LocalParseStatus initWifiModule(void) { sint8 ret = 0; tstrWifiInitParam param; /* Initialize the BSP. */ nm_bsp_init(); /* Initialize WIFI parameters structure. */ memset((uint8_t *)¶m, 0, sizeof(tstrWifiInitParam)); param.pfAppWifiCb = fluffy_wifi_noti_cb; /* Initialize WINC1500 WIFI driver with data and status callbacks. */ ret = m2m_wifi_init(¶m); if (M2M_SUCCESS != ret) { printf("initWifiModule / m2m_wifi_init call error!(%d)\r\n", ret); return LOCAL_PARSE_ERROR_UNKNOWN; } /* Initialize Socket module */ fluffy_trans_init_socket(); #ifdef ENABLE_MDNS /* Initialize the Timer. */ configure_timer(); #endif return LOCAL_PARSE_SUCCESS; }
/** * \brief Main application function. * * Application entry point. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* Initialize Wi-Fi parameters structure. */ memset((uint8_t *)¶m, 0, sizeof(tstrWifiInitParam)); /* Initialize Wi-Fi driver with data and status callbacks. */ ret = m2m_wifi_init(¶m); if (M2M_SUCCESS != ret) { printf("main: m2m_wifi_init call error!(%d)\r\n", ret); while (1) { } } /** * Station mode. * Device started as station mode basically. */ if (1) { } /** * AP mode. * On and off AP mode. */ ret = enable_disable_ap_mode(); if (M2M_SUCCESS != ret) { printf("main: enable_disable_ap_mode call error!\r\n"); while (1) { } } nm_bsp_sleep(DELAY_FOR_MODE_CHANGE); /** * P2P mode. * On and off P2P mode. */ ret = enable_disable_p2p_mode(); if (M2M_SUCCESS != ret) { printf("main: enable_disable_p2p_mode call error!\r\n"); while (1) { } } return 0; }
/** * \brief Main application function. * * Application entry point. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ sysclk_init(); board_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* 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) { } } /* Set device name to be shown in peer device. */ ret = m2m_wifi_set_device_name((uint8_t *)MAIN_WLAN_DEVICE_NAME, strlen(MAIN_WLAN_DEVICE_NAME)); if (M2M_SUCCESS != ret) { printf("main: m2m_wifi_set_device_name call error!\r\n"); while (1) { } } /* Bring up P2P mode with channel number. */ ret = m2m_wifi_p2p(M2M_WIFI_CH_6); if (M2M_SUCCESS != ret) { printf("main: m2m_wifi_p2p call error!\r\n"); while (1) { } } printf("P2P mode started. You can connect to %s.\r\n", (char *)MAIN_WLAN_DEVICE_NAME); while (1) { /* Handle pending events from network controller. */ while (m2m_wifi_handle_events(NULL) != M2M_SUCCESS) { } } return 0; }
/** * \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; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* 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(); registerSocketCallback(socket_cb, resolve_cb); /* Connect to router. */ m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); while (1) { m2m_wifi_handle_events(NULL); if (gbConnectedWifi && gbHostIpByName) { if (gu8SocketStatus == SocketInit) { if (tcp_client_socket < 0) { gu8SocketStatus = SocketWaiting; if (sslConnect() != SOCK_ERR_NO_ERROR) { gu8SocketStatus = SocketInit; } } } } } return 0; }
int WiFiClass::init() { tstrWifiInitParam param; int8_t ret; // Initialize the WiFi BSP: nm_bsp_init(); // Initialize WiFi module and register status callback: param.pfAppWifiCb = wifi_cb; ret = m2m_wifi_init(¶m); if (M2M_SUCCESS != ret) { // Error led ON (rev A then rev B). m2m_periph_gpio_set_val(M2M_PERIPH_GPIO18, 0); m2m_periph_gpio_set_dir(M2M_PERIPH_GPIO6, 1); return ret; } // Initialize socket API and register socket callback: socketInit(); socketBufferInit(); registerSocketCallback(socketBufferCb, resolve_cb); _init = 1; _status = WL_IDLE_STATUS; _localip = 0; _submask = 0; _gateway = 0; _dhcp = 1; memset(_client, 0, sizeof(WiFiClient *) * TCP_SOCK_MAX); // Initialize IO expander LED control (rev A then rev B).. m2m_periph_gpio_set_val(M2M_PERIPH_GPIO15, 1); m2m_periph_gpio_set_val(M2M_PERIPH_GPIO16, 1); m2m_periph_gpio_set_val(M2M_PERIPH_GPIO18, 1); m2m_periph_gpio_set_dir(M2M_PERIPH_GPIO15, 1); m2m_periph_gpio_set_dir(M2M_PERIPH_GPIO16, 1); m2m_periph_gpio_set_dir(M2M_PERIPH_GPIO18, 1); m2m_periph_gpio_set_val(M2M_PERIPH_GPIO4, 1); m2m_periph_gpio_set_val(M2M_PERIPH_GPIO5, 1); m2m_periph_gpio_set_val(M2M_PERIPH_GPIO6, 1); m2m_periph_gpio_set_dir(M2M_PERIPH_GPIO4, 1); m2m_periph_gpio_set_dir(M2M_PERIPH_GPIO5, 1); m2m_periph_gpio_set_dir(M2M_PERIPH_GPIO6, 1); return ret; }
/** * \brief Main application function. * * Application entry point. * Initialize system, UART and board specific settings. * Connect AP using Security mode WEP, WPA * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ sysclk_init(); board_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* 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) { } } /* Case 1. Connect to AP with security type WEP. */ /* m2m_wifi_connect((char *)MAIN_WLAN_DEVICE_NAME, strlen((char *)MAIN_WLAN_DEVICE_NAME), M2M_WIFI_SEC_WEP, &wep64_parameters, M2M_WIFI_CH_ALL); */ /* Case 2. Connect to AP with security type WPA. */ m2m_wifi_connect((char *)MAIN_WLAN_DEVICE_NAME, strlen((char *)MAIN_WLAN_DEVICE_NAME), M2M_WIFI_SEC_WPA_PSK, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); printf("Connecting to %s.\r\n", (char *)MAIN_WLAN_DEVICE_NAME); /* Infinite loop to handle a event from the WINC1500. */ while (1) { while (m2m_wifi_handle_events(NULL) != M2M_SUCCESS) { } } return 0; }
/** * \brief Main application function. * * Application entry point. * Initialize board and WINC1500 Wi-Fi module. * * \return program return value. */ int main(void) { tstrWifiInitParam param = {0}; int8_t ret; /* Initialize variables. */ monitoring_enabled = false; /* Initialize monitoring configuration parameters. */ memset(&wifi_monitor_conf, 0, sizeof(tstrM2MWifiMonitorModeCtrl)); /* Initialize Wi-Fi parameters structure. */ param.pfAppMonCb = monitoring_cb; /* Register monitoring callback function. */ /* Initialize the board. */ sysclk_init(); board_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* Initialize Wi-Fi driver with data and status callbacks. */ ret = m2m_wifi_init(¶m); if (M2M_SUCCESS != ret) { printf("main: m2m_wifi_init call error!(%d)\r\n", ret); while (1) { } } /* Start the packet monitoring. */ start_packet_monitoring(); while (1) { /* Handle pending events from network controller. */ m2m_wifi_handle_events(NULL); } return 0; }
/** * \brief Main application function. * * Application entry point. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* 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) { } } /* 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); /* Init ota function. */ m2m_ota_init(OtaUpdateCb, OtaNotifCb); while (1) { /* Handle pending events from network controller. */ while (m2m_wifi_handle_events(NULL) != M2M_SUCCESS) { } } return 0; }
/** * \brief Main application function. * * Application entry point. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ sysclk_init(); board_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* 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) { } } /* Request scan. */ m2m_wifi_request_scan(M2M_WIFI_CH_ALL); while (1) { /* Handle pending events from network controller. */ while (m2m_wifi_handle_events(NULL) != M2M_SUCCESS) { } } return 0; }
/** * \brief Main application function. * * Application entry point. * Initialize system, UART and board specific settings. * Connect AP using Security mode WPA/WPA2 enterprise * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* 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) { } } /* Connect to the enterprise network. */ m2m_wifi_connect((char *)MAIN_WLAN_DEVICE_NAME, sizeof(MAIN_WLAN_DEVICE_NAME), M2M_WIFI_SEC_802_1X, (char *)&gstrCred1x, M2M_WIFI_CH_ALL); /* Infinite loop to handle a event from the WINC1500. */ while (1) { while (m2m_wifi_handle_events(NULL) != M2M_SUCCESS) { } } return 0; }
/** * \brief Main application function. * * Application entry point. * Initialize board and WINC1500 Wi-Fi module. * Display WINC1500 chip id and rf revision id. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* Initialize Wi-Fi parameters structure. */ memset((uint8_t *)¶m, 0, sizeof(tstrWifiInitParam)); /* Initialize Wi-Fi driver with data and status callbacks. */ ret = m2m_wifi_init(¶m); if (M2M_SUCCESS != ret) { printf("main: m2m_wifi_init call error!(%d)\r\n", ret); while (1) { } } /* Display WINC1500 chip information. */ printf("Chip ID : \r\t\t\t%x\r\n", (unsigned int)nmi_get_chipid()); printf("RF Revision ID : \r\t\t\t%x\r\n", (unsigned int)nmi_get_rfrevid()); printf("Done.\r\n\r\n"); while (1) { } return 0; }
/** * \brief Main application function. * * Initialize system, UART console, network then start function of UDP socket. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; struct sockaddr_in addr; /* Initialize the board. */ sysclk_init(); board_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* Initialize socket address structure. */ addr.sin_family = AF_INET; addr.sin_port = _htons(MAIN_WIFI_M2M_SERVER_PORT); addr.sin_addr.s_addr = _htonl(MAIN_WIFI_M2M_SERVER_IP); /* 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(); registerSocketCallback(socket_cb, NULL); /* Connect to router. */ m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); packetCnt = 0; while (1) { if (packetCnt >= MAIN_WIFI_M2M_PACKET_COUNT) { printf("UDP Server test Complete!\r\n"); close(rx_socket); rx_socket = -1; break; } m2m_wifi_handle_events(NULL); if (wifi_connected == M2M_WIFI_CONNECTED) { /* Create socket for Rx UDP */ if (rx_socket < 0) { if ((rx_socket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { printf("main : failed to create RX UDP Client socket error!\r\n"); continue; } /* Socket bind */ bind(rx_socket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)); } } } return 0; }
/** * \brief Main application function. * * Initialize system, UART console, network then start time client. * * \return Program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; struct sockaddr_in addr_in; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* 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) { } } /* Turn LED0 off initially. */ port_pin_set_output_level(LED_0_PIN, true); /* Initialize Socket module */ socketInit(); /* Register socket handler, resolve handler */ registerSocketCallback(socket_cb, resolve_cb); /* Connect to router. */ m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); while (1) { /* Handle pending events from network controller. */ m2m_wifi_handle_events(NULL); if (gbConnectedWifi) { /* * Create the socket for the first time. */ if (udp_socket < 0) { udp_socket = socket(AF_INET, SOCK_DGRAM, 0); if (udp_socket < 0) { printf("main: UDP Client Socket Creation Failed.\r\n"); continue; } /* Initialize default socket address structure. */ addr_in.sin_family = AF_INET; addr_in.sin_addr.s_addr = _htonl(MAIN_DEFAULT_ADDRESS); addr_in.sin_port = _htons(MAIN_DEFAULT_PORT); bind(udp_socket, (struct sockaddr *)&addr_in, sizeof(struct sockaddr_in)); } } } return 0; }
/** * \brief Main application function. * * Initialize system, UART console, network then start function of SMTP email client. * * \return Program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* 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(); registerSocketCallback(socket_cb, resolve_cb); /* Connect to router. */ m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); while (1) { m2m_wifi_handle_events(NULL); if (gbConnectedWifi && gbHostIpByName) { if (gu8SocketStatus == SocketInit) { if (tcp_client_socket < 0) { gu8SocketStatus = SocketWaiting; if (smtpConnect() != SOCK_ERR_NO_ERROR) { gu8SocketStatus = SocketInit; } } } else if (gu8SocketStatus == SocketConnect) { gu8SocketStatus = SocketWaiting; if (smtpStateHandler() != MAIN_EMAIL_ERROR_NONE) { if (gs8EmailError == MAIN_EMAIL_ERROR_INIT) { gu8SocketStatus = SocketError; } else { close_socket(); break; } } } else if (gu8SocketStatus == SocketComplete) { printf("main: Email was successfully sent.\r\n"); port_pin_set_output_level(LED_0_PIN, false); close_socket(); break; } else if (gu8SocketStatus == SocketError) { if (gu8RetryCount < MAIN_RETRY_COUNT) { gu8RetryCount++; printf("main: Waiting to connect server.(30 seconds)\r\n\r\n"); retry_smtp_server(); } else { printf("main: Failed retry to server. Press reset your board.\r\n"); gu8RetryCount = 0; close_socket(); break; } } } } return 0; }
/** * \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; }
/** * \brief Main application function. * * Application entry point. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; char topic[strlen(MAIN_CHAT_TOPIC) + MAIN_CHAT_USER_NAME_SIZE + 1]; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); /* Output example information */ printf(STRING_HEADER); /* Initialize the Timer. */ configure_timer(); /* Initialize the MQTT service. */ configure_mqtt(); /* Initialize the BSP. */ nm_bsp_init(); /* Setup user name first */ printf("Enter the user name (Max %d characters)\r\n", MAIN_CHAT_USER_NAME_SIZE); scanf("%64s", mqtt_user); printf("User : %s\r\n", mqtt_user); sprintf(topic, "%s%s", MAIN_CHAT_TOPIC, mqtt_user); /* Initialize Wi-Fi parameters structure. */ memset((uint8_t *)¶m, 0, sizeof(tstrWifiInitParam)); /* Initialize Wi-Fi driver with data and 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 interface. */ socketInit(); registerSocketCallback(socket_event_handler, socket_resolve_handler); /* Connect to router. */ m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); while (1) { /* Handle pending events from network controller. */ m2m_wifi_handle_events(NULL); /* Try to read user input from USART. */ usart_read_job(&cdc_uart_module, &uart_ch_buffer); /* Checks the timer timeout. */ sw_timer_task(&swt_module_inst); /* Checks the USART buffer. */ check_usart_buffer(topic); } }
error_t wilc1000Init(NetInterface *interface) { int8_t status; tstrWifiInitParam param; //STA or AP mode? if(interface->nicDriver == &wilc1000StaDriver) { //Debug message TRACE_INFO("Initializing WILC1000 (STA mode)...\r\n"); } else { //Debug message TRACE_INFO("Initializing WILC1000 (AP mode)...\r\n"); } //Start of exception handling block do { //Initialization sequence is performed once at startup if(wilc1000StaInterface == NULL && wilc1000ApInterface == NULL) { //Low-level initialization status = nm_bsp_init(); //Check status code if(status != M2M_SUCCESS) break; //Set default parameters memset(¶m, 0, sizeof(param)); //Register callback functions param.pfAppWifiCb = wilc1000AppWifiEvent; param.pfAppMonCb = NULL; param.strEthInitParam.pfAppWifiCb = NULL; param.strEthInitParam.pfAppEthCb = wilc1000AppEthEvent; //Set receive buffer param.strEthInitParam.au8ethRcvBuf = rxBuffer; param.strEthInitParam.u16ethRcvBufSize = WILC1000_RX_BUFFER_SIZE - ETH_CRC_SIZE; //Initialize WILC1000 controller status = m2m_wifi_init(¶m); //Check status code if(status != M2M_SUCCESS) break; //Optionally set the station MAC address if(macCompAddr(&interface->macAddr, &MAC_UNSPECIFIED_ADDR)) { //Use the factory preprogrammed station address status = m2m_wifi_get_mac_address(interface->macAddr.b); //Check status code if(status != M2M_SUCCESS) break; //Generate the 64-bit interface identifier macAddrToEui64(&interface->macAddr, &interface->eui64); } else { //Override the factory preprogrammed address status = m2m_wifi_set_mac_address(interface->macAddr.b); //Check status code if(status != M2M_SUCCESS) break; } } else { //Initialization was already done status = M2M_SUCCESS; } //STA or AP mode? if(interface->nicDriver == &wilc1000StaDriver) { //Save underlying network interface (STA mode) wilc1000StaInterface = interface; if(wilc1000ApInterface != NULL) { wilc1000StaInterface->macAddr = wilc1000ApInterface->macAddr; wilc1000StaInterface->eui64 = wilc1000ApInterface->eui64; } } else { //Save underlying network interface (AP mode) wilc1000ApInterface = interface; if(wilc1000StaInterface != NULL) { wilc1000ApInterface->macAddr = wilc1000StaInterface->macAddr; wilc1000ApInterface->eui64 = wilc1000StaInterface->eui64; } } //End of exception handling block } while(0); //WILC1000 is now ready to send osSetEvent(&interface->nicTxEvent); //Return status code if(status == M2M_SUCCESS) return NO_ERROR; else return ERROR_FAILURE; }
/** * \brief Main application function. * * Application entry point. * Initialize board and WINC1500 Wi-Fi module. * Read input data from serial interface and sent it to the remote device. * * \return program return value. */ int main(void) { tstrWifiInitParam param; int8_t ret; /* Initialize the board. */ system_init(); /* Initialize the UART console. */ configure_console(); printf(STRING_HEADER); /* Initialize the BSP. */ nm_bsp_init(); /* 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 interface. */ socketInit(); registerSocketCallback(socket_cb, NULL); /* Connect to router. */ m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID), MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL); while (1) { if (wifi_connected == M2M_WIFI_CONNECTED && tcp_server_socket < 0) { struct sockaddr_in addr; /* Create TCP server socket. */ if ((tcp_server_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) { printf("Failed to create TCP server socket!\r\n"); continue; } /* Initialize socket address structure and bind service. */ addr.sin_family = AF_INET; addr.sin_port = _htons(MAIN_WIFI_M2M_SERVER_PORT); addr.sin_addr.s_addr = 0; bind(tcp_server_socket, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)); } /* Handle pending events from network controller. */ m2m_wifi_handle_events(NULL); /* Try to read user input from EDBG. */ usart_read_job(&cdc_uart_module, &uart_ch_buffer); /* Handle user message from EDBG. */ handle_input_message(); } return 0; }