Issue while reconnecting during provisining

ChromaMaster
Posts: 2
Joined: Wed Sep 09, 2020 11:53 am

Issue while reconnecting during provisining

Postby ChromaMaster » Wed Sep 09, 2020 12:25 pm

Hi, I'm trying to implement a provisioning method for my esp32 using BLE. I'm using the method provided by esp-idf, the one which uses protocomm.

In order to be more clear about the issue, I'll only paste the provisioning event handler. The rest of the code is exactly the same as the one present in the ble_prov example for branch release/v3.3. Here is the https://github.com/espressif/esp-idf/tr ... g/ble_prov

Code: Select all

case SYSTEM_EVENT_STA_DISCONNECTED:
        ESP_LOGE(TAG, "STA Disconnected");
        ESP_LOGE(TAG, "Disconnect reason : %d", info->disconnected.reason);

        if(retry_count < MAX_CONNECTION_RETRIES){
            retry_count ++;
            esp_wifi_connect();
            return;
        }
        
        /* Station couldn't connect to configured host SSID */
        g_prov->wifi_state = WIFI_PROV_STA_DISCONNECTED;

        /* Set code corresponding to the reason for disconnection */
        switch (info->disconnected.reason) {
        case WIFI_REASON_AUTH_EXPIRE:
        case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT:
        case WIFI_REASON_BEACON_TIMEOUT:
        case WIFI_REASON_AUTH_FAIL:
        case WIFI_REASON_ASSOC_FAIL:
        case WIFI_REASON_HANDSHAKE_TIMEOUT:
            ESP_LOGI(TAG, "STA Auth Error");
            g_prov->wifi_disconnect_reason = WIFI_PROV_STA_AUTH_ERROR;
            break;
        case WIFI_REASON_NO_AP_FOUND:
            ESP_LOGI(TAG, "STA AP Not found");
            g_prov->wifi_disconnect_reason = WIFI_PROV_STA_AP_NOT_FOUND;
            break;
        default:
            break;
        }
        break;
What I'm trying to avoid here are very circumstantial errors like interferences or whatever could happen. For that, if an error occurs I want to reconnect. if the error persists, the error it's most likely a user error (wrong password, AP issues, or whatever).

In order to do that, in the provisioning event handler, whenever I receive an SYSTEM_EVENT_STA_DISCONNECTED event I just ignore it and trying to connect again to the network provided. To test this, I'm sending the wrong password intentionally to the ESP32. When the ESP32 receives this, it reports a app_prov: Disconnect reason : 15 message (which is OK), and then, if needed, I execute again the esp_wifi_connect() function in order to reconnect.

Everytime I do this, after an error code 15 I'm getting a app_prov: Disconnect reason : 205 which according the esp-idf doc is CONNECTION_FAIL. If I retry a third time, I get again the error code 15 which is correct. I observed that if I increase the MAX_CONNECTION_RETRIES, the pattern is always the same (for error codes): 15 -> 205 -> 15 -> 205 -> ...

The serial debug output for the retries (the ones that return error code 205) is the following. I observed that the wifi library starts to scan but then just stops and clears the blacklist, rc list and sends a disconnect event.

Code: Select all

E (39829) app_prov: STA Disconnected
E (39829) app_prov: Disconnect reason : 15 
D (39839) wifi:Start wifi connect      < ----- HERE STARTS THE SECOND TRY
D (39839) wifi:connect status 2 -> 0
D (39849) wifi:connect chan=0
D (39849) wifi:first chan=11
D (39849) wifi:connect status 0 -> 1
D (39849) wifi:filter: set rx policy=3
D (39859) wifi:clear scan ap list
D (39859) wifi:start scan: type=0x50f, priority=2, cb=0x400e7250, arg=0x0, ss_state=0x1, time=36116094, index=0
0x400e7250: cnx_start_handoff_cb at ??:?
D (39869) wifi:perform scan: ss_state=0x9, chan<11,0>, dur<0,120>
D (39879) wifi:rsn valid: gcipher=3 ucipher=3 akm=5
D (39879) wifi:find the 34:db:9c:c1:2a:06 in blacklist.
D (39949) wifi:rsn valid: gcipher=3 ucipher=3 akm=5
D (39949) wifi:find the 34:db:9c:c1:2a:06 in blacklist.
D (40049) wifi:rsn valid: gcipher=3 ucipher=3 akm=5
D (40049) wifi:find the 34:db:9c:c1:2a:06 in blacklist.
D (40119) wifi:scan end: arg=0x0, status=0, ss_state=0x3
D (40119) wifi:perform scan: ss_state=0x9, chan<1,0>, dur<0,120>
D (40359) wifi:scan end: arg=0x0, status=0, ss_state=0x3
...
D (42299) wifi:scan end: arg=0x0, status=0, ss_state=0x3
D (42309) wifi:perform scan: ss_state=0x9, chan<10,0>, dur<0,120>
D (42549) wifi:scan end: arg=0x0, status=0, ss_state=0x3
D (42549) wifi:perform scan: ss_state=0x9, chan<12,0>, dur<360,360>
D (42789) wifi:scan end: arg=0x0, status=0, ss_state=0x3
D (42789) wifi:perform scan: ss_state=0x9, chan<13,0>, dur<360,360>
D (43029) wifi:scan end: arg=0x0, status=0, ss_state=0x3
D (43029) wifi:filter: set rx policy=4
D (43029) wifi:first chan=1
D (43029) wifi:handoff_cb: status=0
D (43029) wifi:clear blacklist
D (43039) wifi:clear rc list
D (43039) wifi:clear blacklist
D (43039) wifi:send disconnect event
D (43049) wifi:connect status 1 -> 3
D (43049) wifi:disable connect timer
D (43049) wifi:clear scan ap list
E (43059) app_prov: STA Disconnected
E (43059) app_prov: Disconnect reason : 205
My question is, is there any way to do this without having an odd number of connection retries? Am I missing something?

Thanks you in advance.

Who is online

Users browsing this forum: No registered users and 81 guests