3.1.4.1 Execution
main.c – Initialize the ATWINC15x0/ATWINC3400 and get the RSSI for the connected AP.
- Code summary:
- Configure the network
parameters in
main.h.
/** Wi-Fi Settings */ #define MAIN_WLAN_SSID "DEMO_AP" /* < Destination SSID */ #define MAIN_WLAN_AUTH M2M_WIFI_SEC_WPA_PSK /* < Security manner */ #define MAIN_WLAN_PSK "12345678" /* < Password for Destination SSID */
- Connect to the AP with
the given information.
/* Connect to defined AP. */ m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (void *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL);
Note: The WINC1500 stores the last successful connection in its memory by default, so if the user disconnects from the AP, the user can callm2m_wifi_default_connect()
; instead of callingm2m_wifi_connect()
with the same credentials again. - The
wifi_cb()
function is called with theM2M_WIFI_RESP_CON_STATE_CHANGED
message, where an appropriate action can be executed as a response. The new Wi-Fi state is passed onto the callback as part of the message.static void wifi_cb(uint8_t u8MsgType, void *pvMsg) { switch (u8MsgType) { case M2M_WIFI_RESP_CON_STATE_CHANGED: { ... tstrM2mWifiStateChanged *pstrWifiState = (tstrM2mWifiStateChanged *)pvMsg; if (pstrWifiState->u8CurrState == M2M_WIFI_CONNECTED){ /* Take action on connection successful */ ...
- The
wifi_cb()
function is called with theM2M_WIFI_REQ_DHCP_CONF
message. If successful, the DHCP assigned IP address is passed to the application.
After the IP is assigned, the next time the DHCP client running on WINC wants the IP, it can start the process with the DHCP request packet straight instead of the DHCP Discovery packet. It has been observed that, some DHCP servers do not respond to the DHCP REQ packet as the first packet but expect the DHCP Discovery to come in from the DHCP client. Ensure that WINC sends a DHCP Discovery packet every time an IP needs to be configured. It is recommended that the user callstatic void wifi_cb(uint8_t u8MsgType, void *pvMsg) { case M2M_WIFI_REQ_DHCP_CONF: { ... uint8_t *pu8IPAddress = (uint8_t *)pvMsg; printf("Wi-Fi connected\r\n"); printf("Wi-Fi IP is %u.%u.%u.%u\r\n", pu8IPAddress[0], pu8IPAddress[1], pu8IPAddress[2], pu8IPAddress[3]); ...
m2m_wifi_disconnect()
just beforem2m_wifi_connect()
, which confirms that the DHCP exchange starts from the Discovery packet.
- Configure the network
parameters in
main.h.
- Build the program and download it into the board.
- Start the application.