/** * \brief Main application function. * * Initializing the board and connect to wireless router. * And event handling the Wi-Fi and SW timer. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); /* Initialize the Timer. */ configure_timer(); /* Initialize the HTTP client service. */ configure_http_client(); /* Initialize the BSP. */ nm_bsp_init(); /* Output example information */ printf(STRING_HEADER); /* Initialize Wi-Fi driver with data and Wi-Fi status callbacks. */ param.pfAppWifiCb = wifi_callback; /* Set Wi-Fi event callback. */ ret = m2m_wifi_init(¶m); if (M2M_SUCCESS != ret) { printf("main: m2m_wifi_init call error!(%d)\r\n", ret); while (1) { /* Loop forever. */ } } /* Initialize Socket module */ socketInit(); registerSocketCallback(socket_event_handler, socket_resolve_handler); /* Connect to router. */ ret = m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); if (M2M_SUCCESS != ret) { printf("main: failed to connect access point!\r\n"); while (1) { } } while (1) { /* Handle pending events from network controller. */ m2m_wifi_handle_events(NULL); /* Checks the timer timeout. */ sw_timer_task(&swt_module_inst); } }
/** * \brief Main application function. * * Application entry point. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; init_state(); /* Initialize the board. */ sysclk_init(); board_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); printf("This example may not work as it requires internet connectivity.\r\n"); /* Initialize the Timer. */ configure_timer(); /* Initialize the HTTP client service. */ configure_http_client(); /* Initialize the BSP. */ nm_bsp_init(); /* Initialize SD/MMC storage. */ init_storage(); /* Initialize Wi-Fi parameters structure. */ memset((uint8_t *)¶m, 0, sizeof(tstrWifiInitParam)); /* 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) { } } /* Initialize socket module. */ socketInit(); /* Register socket callback function. */ registerSocketCallback(socket_cb, resolve_cb); /* Connect to router. */ printf("main: Waiting for Wi-Fi connection. AP:%s\r\n", (char *)MAIN_WLAN_SSID); m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); while (!(is_state_set(COMPLETED) || is_state_set(CANCELED))) { /* Handle pending events from network controller. */ m2m_wifi_handle_events(NULL); /* Checks the timer timeout. */ sw_timer_task(&swt_module_inst); } printf("main: Exit program. Please unplug the card.\r\n"); while (1) { } /* Loop forever. */ return 0; }