[solved] Network found by wifi_station_scan() but "no Network found, reconnect after 1s"

Pato
Posts: 32
Joined: Sat Mar 24, 2018 12:52 am

[solved] Network found by wifi_station_scan() but "no Network found, reconnect after 1s"

Postby Pato » Fri Jun 08, 2018 10:36 pm

Hi dear folks,

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);   
}
Last edited by Pato on Mon Jun 11, 2018 8:42 pm, edited 1 time in total.

Bernard
Posts: 7
Joined: Tue Apr 17, 2018 10:49 pm
Location: France

Re: Network found by wifi_station_scan() but "no Network found, reconnect after 1s"

Postby Bernard » Sat Jun 09, 2018 12:01 am

Not sure it helps you, but I also faced some instability or strange behavior with wifi (but in RTOS mode and in softAP mode) and it was suddently solved when I started to flash all binaries :the ones generated by compilation plus esp_init_data_default.bin and blank.bin.
Previously I was flashing only the binaries generated by compilation...
Regards, Bernard

Website: https://www.ochrin.com

blubb
Posts: 116
Joined: Mon Jun 22, 2015 5:35 am

Re: Network found by wifi_station_scan() but "no Network found, reconnect after 1s"

Postby blubb » Sun Jun 10, 2018 11:53 pm

Local non-static variables are not initialized, which typically means they contain garbage.
struct station_config has more fields than ssid and password.

Try
stationConfig.bssid_set = 0;

Edit:
But it is better to zero out the whole thing first- for future compatibility. They added even more fields in the latest SDK versions!

Pato
Posts: 32
Joined: Sat Mar 24, 2018 12:52 am

Re: Network found by wifi_station_scan() but "no Network found, reconnect after 1s"

Postby Pato » Mon Jun 11, 2018 6:50 pm

Ho dude,

Indeed it was about uninitialized fields in the struct station_config !
However set the bssid_set field = 0 alone (to not connect only if the BSSID matches, cf. doc) was not sufficient, two other fields must be set:

Code: Select all

struct station_config stationConfig;
       
os_strcpy(stationConfig.ssid, ssid);
os_strcpy(stationConfig.password, password);
   
// Must also be set or garbages values will make the scan/connection fail
stationConfig.bssid_set = 0;                        // Don't match the BSSID
stationConfig.threshold.rssi = 0;               // To "ignore" the RSSI level when scanning the network ?
stationConfig.threshold.authmode = AUTH_OPEN;   // The router must no ask for a challenge when scanning ?


It worked by zeroing everything with a memset(&stationConfig, 0, sizeof(struct station_config)), what "accidently" set the above fields to the right values (wich happened to be 0). This is what most of people seems to do and why it works, I think.

Thanks !

Who is online

Users browsing this forum: No registered users and 297 guests