I ask for explaination for the following behavior of the ESP8266 in station mode, with the NONOS_SDK_2.2.0.
When connecting to the the wifi network called MyNetwork, and listing the visible APs, I got the following output from the SDK (I print the list of AP scanned and the reason of the disconnection):
Code: Select all
Setting up the Esp as a Wifi station...
bcn 0
del if1
usl
mode : sta(ec:fa:bc:05:9b:59)
add if0
Connecting to WiFi...
scandone
scandone
AP: iPhone of Juliet
AP: SFR-12Y0
AP: MyNetwork <= MyNetwork is visible
AP: Livebox-F553
AP: Livebox-F89E
AP: Livebox-EC52
AP: AndroidAP
AP: eduroam
reconnect
scandone
no MyNetwork found, reconnect after 1s <= MyNetwork is said not found...
Disconnect from ssid MyNetwork, reason 201 <= code 201 = REASON_NO_AP_FOUND
reconnect
scandone
no MyNetwork found, reconnect after 1s
Disconnect from ssid MyNetwork, reason 201
reconnect
scandone
no MyNetwork found, reconnect after 1s
Disconnect from ssid MyNetwork, reason 201
reconnect
...
This looks contradictory.
Why the wifi_connect() fails saying "no MyNetwork found" ?
Also, It seems like if I comment lines of codes that are unused (yeah, because they are work in progress and in functions that are not called yet), it sometimes fixe the problem and my Esp connect at start to MyNetwork (I can repeat the coment/uncomment and obtain this behavior repeatedly). How can this be related ?
Thanks for your help and your explainations <3 !
---------
The code in question:
Code: Select all
/**
* @brief Callback function called when the wifi connection is fully operational.
*
*/
void ICACHE_FLASH_ATTR WifiConnectedCb(System_Event_t *event)
{
if(event->event == EVENT_STAMODE_DISCONNECTED)
{
os_printf("Disconnect from ssid %s, reason %d\n", event->event_info.disconnected.ssid, event->event_info.disconnected.reason);
}
/* Run OTA process only when we are fully connected to WiFi */
if(event->event == EVENT_STAMODE_GOT_IP)
{
os_printf("Connected to Wifi (EVENT_STAMODE_GOT_IP) \n");
}
}
/**
* @brief Print all visible APs.
*
*/
static void ICACHE_FLASH_ATTR scan_done_CB(void *arg, STATUS status)
{
if (status == OK)
{
struct bss_info *bss_link = (struct bss_info *)arg;
while(bss_link != NULL)
{
os_printf("AP: %s \n", bss_link->ssid);
bss_link = STAILQ_NEXT(bss_link, next);
}
}
}
/**
* @brief Called when system is fully initialized. Here we do our custom initialization
* like connecting to wifi and setting timers.
*/
void PostInitCb()
{
/* Connect to WiFi */
os_printf("I'm version 2 ! \n");
os_printf("Setting up the Esp as a Wifi station... \n");
struct station_config stationConfig;
os_strcpy(stationConfig.ssid, ssid);
os_strcpy(stationConfig.password, password);
wifi_set_opmode_current(STATION_MODE);
wifi_station_disconnect();
wifi_station_set_config(&stationConfig);
wifi_set_event_handler_cb(WifiConnectedCb);
wifi_station_connect();
os_printf("Connecting to WiFi... \n");
//DEBUG
wifi_station_scan(NULL, scan_done_CB);
}
/**
* @brief Was present in IoT_Demo/user/user_main.c on which this code is based...
* Set the 5th sector from the end of the flash to store the RF_CAL parameter.
*/
uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
priv_param_start_sec = 0x3C;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_16M_MAP_512_512:
rf_cal_sec = 512 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_32M_MAP_512_512:
rf_cal_sec = 1024 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_64M_MAP_1024_1024:
rf_cal_sec = 2048 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_128M_MAP_1024_1024:
rf_cal_sec = 4096 - 5;
priv_param_start_sec = 0xFC;
break;
default:
rf_cal_sec = 0;
priv_param_start_sec = 0;
break;
}
return rf_cal_sec;
}
/**
* @brief Was present in IoT_Demo/user/user_main.c on wich this code is based...
*/
void ICACHE_FLASH_ATTR user_rf_pre_init(void)
{
}
/**
* @brief Main entry point of our programm
*/
void user_init()
{
system_init_done_cb(PostInitCb);
}