8.5 AP Mode Code Example

The following example shows how to configure the ATWINC15x0 AP mode with WINC_SSID as broadcasted SSID on channel one with open security and an IP address equals 192.168.1.1.

#include "m2m_wifi.h"
#include "m2m_types.h"
void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
{
	switch(u8WiFiEvent)
	{
		case M2M_WIFI_REQ_DHCP_CONF:
		{
			uint8 *pu8IPAddress = (uint8*)pvMsg;
			printf("Associated STA has IP Address \"%u.%u.%u.%u\"\n", pu8IPAddress[0],
						pu8IPAddress[1], pu8IPAddress[2], pu8IPAddress[3]);
		}
		break;
		default:
		break;
	}
}

int main()
{
	tstrWifiInitParam param;

	/* Platform specific initializations. */

	param.pfAppWifiCb = wifi_event_cb;
	if (!m2m_wifi_init(&param))
	{
		tstrM2MAPConfig apConfig;
		strcpy(apConfig.au8SSID, "WINC_SSID");	// Set SSID
		apConfig.u8SsidHide = SSID_MODE_VISIBLE;	// Set SSID to be broadcasted
		apConfig.u8ListenChannel = 1;	// Set Channel

		apConfig.u8SecType = M2M_WIFI_SEC_WEP;	// Set Security to WEP
		apConfig.u8KeyIndx = 0;	// Set WEP Key Index
		apConfig.u8KeySz = WEP_40_KEY_STRING_SIZE;	// Set WEP Key Size
		strcpy(apConfig.au8WepKey, "1234567890");	// Set WEP Key

		// IP Address
		apConfig.au8DHCPServerIP[0] = 192;
		apConfig.au8DHCPServerIP[1] = 168;
		apConfig.au8DHCPServerIP[2] = 1;
		apConfig.au8DHCPServerIP[3] = 1;

		// Start AP mode
		m2m_wifi_enable_ap(&apConfig);
		while(1)
		{
			m2m_wifi_handle_events(NULL);
		}
	}
}
Note: Power Save mode is not supported in the ATWINC15x0 AP mode.