4.3.2 IP Address
The ATWINC15x0 firmware uses the embedded DHCP
client to automatically obtain an IP configuration after a successful Wi-Fi connection.
DHCP is the preferred method and therefore it is used as a default method. After the IP
configuration is obtained, the host MCU application is notified by the asynchronous
event M2M_WIFI_REQ_DHCP_CONF
.
Alternatively, the host MCU application can set a static IP configuration by
calling the m2m_wifi_set_static_ip
API. Before setting a static IP
address, it is recommended to disable DHCP using the API
m2m_wifi_enable_dhcp(0)
and then set the static IP as shown
below.
In Main(), disable dhcp after m2m_wifi_init
as shown below
/* Initialize Wi-Fi driver with data and status callbacks. */
param.pfAppWifiCb = wifi_cb;
ret = m2m_wifi_init(¶m);
if (M2M_SUCCESS != ret)
{
printf("main: m2m_wifi_init call error!(%d)\r\n", ret);
while (1)
{}
}
m2m_wifi_enable_dhcp(0);
Set Static IP when WINC is connected to AP as shown below.
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){
printf("Wi-Fi connected\r\n");
tstrM2MIPConfig ip_client;
ip_client.u32StaticIP = _htonl(0xc0a80167); // Provide the required Static IP
ip_client.u32DNS = _htonl(0xc0a80101); // Provide DNS server details
ip_client.u32SubnetMask = _htonl(0xFFFFFF00); // Provide the SubnetMask for the currently connected AP
ip_client.u32Gateway = _htonl(0xc0a80101); // Provide the GAteway IP for the AP
printf("Wi-Fi setting static ip\r\n");
m2m_wifi_set_static_ip(&ip_client);
}
}
}