- Wed Feb 25, 2015 8:01 pm
#10740
For everyone's convenience, here's the bit of code that is on the Electrodragon sample:
This bit of code sets the wifi SSID and password via wifi_station_set_config(), which calls wifi_station_connect() if it is called in user_init():
Code: Select all// If the card mode STA, then set the configuration, the name of AP, password, see User_config.h
// Optional read the MAC address of our card mode AP, see. Wifi_get_macaddr (SOFTAP_IF, macaddr)
// In the STA in charge will be a different MAC address as the client, but we have to address yourself to read that she had if she had acted as an access point
if(wifi_get_opmode() == STATION_MODE)
{
wifi_station_get_config(&stationConfig);
os_memset(stationConfig.ssid, 0, sizeof(stationConfig.ssid));
os_memset(stationConfig.password, 0, sizeof(stationConfig.password));
os_sprintf(stationConfig.ssid, "%s", WIFI_CLIENTSSID);
os_sprintf(stationConfig.password, "%s", WIFI_CLIENTPASSWORD);
wifi_station_set_config(&stationConfig);
// wifi_get_macaddr(SOFTAP_IF, macaddr);
}
// For adjusting the output data in uart mode setup STA
#ifdef PLATFORM_DEBUG
if(wifi_get_opmode() == STATION_MODE)
{
wifi_station_get_config(&stationConfig);
os_sprintf(info,"OPMODE: %u, SSID: %s, PASSWORD: %s\r\n",
wifi_get_opmode(),
stationConfig.ssid,
stationConfig.password);
uart0_sendStr(info);
}
#endif
And this bit calls wifi_station_get_connect_status() every second to check if the ESP8266 is successfully connected to the wifi network. The wifi_station_get_connect_status() is somehow returning an incorrect password error for an indeterminate number of minutes betore returning a STATION_GOT_IP code.
Code: Select all // Start the timer test the connection to Wi-Fi, check the connection every 1 sec., If the connection is established, then run TCP-client and send a test string.
os_timer_disarm(&WiFiLinker);
os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
os_timer_arm(&WiFiLinker, 1000, 0);
Is there no one else using this bit of code? Or is everyone else having no problems with this code? (A yes/no answer to this question will be helpful too...)