10.6 OTA Code Example

/*!<OTA update callback typedef> */
static void OtaUpdateCb(uint8 u8OtaUpdateStatusType ,uint8 u8OtaUpdateStatus)
{
	if(u8OtaUpdateStatusType == DL_STATUS)
	{
		if(u8OtaUpdateStatus == OTA_STATUS_SUCSESS)
		{
			//switch to the upgraded firmware
			m2m_ota_switch_firmware();
		}
	}
	else if(u8OtaUpdateStatusType == SW_STATUS)
	{
		if(u8OtaUpdateStatus == OTA_STATUS_SUCSESS)
		{
			M2M_INFO("Now OTA suceesfully done");
			//start the host SW upgrade then system reset is required (Reintilize the driver)
		}
	}
}

void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
{
	case M2M_WIFI_REQ_DHCP_CONF:
	{
		//after suceesfull connection, start the over air upgrade
		m2m_ota_start_update(OTA_URL);
	}
	break;
	default:
	break;
}

int main (void)
{
	tstrWifiInitParam param;
	tstr1xAuthCredentials gstrCred1x    = AUTH_CREDENTIALS;
	nm_bsp_init();
	m2m_memset((uint8*)&param, 0, sizeof(param));
	param.pfAppWifiCb = wifi_event_cb;
	
	//intilize the WINC Driver
	ret = m2m_wifi_init(&param);
	if (M2M_SUCCESS != ret)
	{
		M2M_ERR("Driver Init Failed <%d>\n",ret);
		while(1);
	}
	//intilize the ota module
	m2m_ota_init(OtaUpdateCb,NULL);
	//connect to AP that provide connection to the OTA server
	m2m_wifi_default_connect();
	while(1)
	{
		while(m2m_wifi_handle_events(NULL) != M2M_SUCCESS) {}
	}
}
Note: For more details on example codes, refer to the Wi-Fi Network Controller Software Programming Guide.