esp-idf-provisioning-android icon indicating copy to clipboard operation
esp-idf-provisioning-android copied to clipboard

AUTH_FAILED in provision

Open developerGM opened this issue 4 years ago • 7 comments

If I write an error wifi password, the callback go to AUTH_FAILED correctly

@Override
            public void provisioningFailedFromDevice(final ESPConstants.ProvisionFailureReason failureReason) {
                requireActivity().runOnUiThread(() -> {
                    switch (failureReason) {
                        case AUTH_FAILED: //HERE
                            setError(R.string.error_authentication_failed);
                            break;
                        case NETWORK_NOT_FOUND:
                            setError(R.string.error_network_not_found);
                            break;
                        case DEVICE_DISCONNECTED:
                        case UNKNOWN:
                            setError(R.string.error_prov_step_3);
                            break;
                    }
                });
            }

Than I try to call again mProvisionManager.getEspDevice().provision(ssid, password, new ProvisionListener() {}

but recive createSessionFailed, than is all stopped. I cannot call again provision method. I need to reconnect device and scan again wifi???

developerGM avatar Jan 12 '21 17:01 developerGM

@developerGM as of now, if you provide incorrect Wi-Fi password, you have to reset the device to factory settings and repeat the provisioning. The reason for this is that the firmware side provisioning state machine cannot easily handle re-provisioning in the same boot cycle.

We understand that this could be very inconvenient. We will check how to fix this so that the process becomes easier. I hope this answers your query. Let me know if I have misunderstood the query here.

shahpiyushv avatar Jan 12 '21 18:01 shahpiyushv

Thanks, is clear. So I need to re-connect the device and start provisioning again

developerGM avatar Jan 12 '21 18:01 developerGM

@developerGM , not just reconnect, but erase the programmed wifi credentials and reboot the board. You can erase the credentials by one of the following ways

  • Calling esp_wifi_restore() on some trigger (timer/wifi prov failure event/push button press)
  • Erasing the nvs partition using esptool.py -p <PORT> erase_region <nvs_partition_start_addr> <nvs_partition_length> or calling nvs_flash_deinit(); nvs_flash_erase(); from your code.
  • Erasing entire flash using idf.py erase_flash and re-flashing the firmware.

shahpiyushv avatar Jan 12 '21 20:01 shahpiyushv

if you provide incorrect Wi-Fi password, you have to reset the device to factory settings and repeat the provisioning. The reason for this is that the firmware side provisioning state machine cannot easily handle re-provisioning in the same boot cycle.

Hi @shahpiyushv, thanks for explaining.

If I understand correctly this means that if a customer enters their WiFi password incorrectly then

  1. the phone must show an error message asking the customer to reboot the device
  2. the customer must reboot the device
  3. and then run through the whole process again on their phone: BLE scan, BLE connect, WiFi scan, enter password, WiFi provisioning

Is there an issue in espressif/esp-idf that tracks this bug in the provisioning state machine?

willmoffat avatar Jan 14 '21 06:01 willmoffat

Hi I think that there is a problem inside ESPDevice.java

When I call provision method and use a wrong wifi password the board try to connect 4 times and never send a callback different form connecting status.

So, I can't go inside last else

if (wifiStationState == WifiConstants.WifiStationState.Connected) {

} else if (wifiStationState == WifiConstants.WifiStationState.Disconnected) {

} else if (wifiStationState == WifiConstants.WifiStationState.Connecting) {

// callback enter always here becase status is alwasy "Connecting"

                    try {
                        sleep(5000);
                        pollForWifiConnectionStatus();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                        session = null;
                        disableOnlyWifiNetwork();
                        provisionListener.onProvisioningFailed(new RuntimeException("Provisioning Failed"));
                    }
} else {

// I need to enter here when I have a wrong password

}

This is the log and go for 4 times

I (40762) app: Received Wi-Fi credentials
        SSID     : ABCD
        Password : xxxx
I (43216) wifi:new:<6,0>, old:<1,0>, ap:<255,255>, sta:<6,0>, prof:1
I (44046) wifi:state: init -> auth (b0)
I (44056) wifi:state: auth -> assoc (0)
I (44073) wifi:state: assoc -> run (10)
I (48099) wifi:state: run -> init (2c0)
I (48101) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (48101) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (48105) app: Disconnected. Connecting to the AP again...
E (48114) wifi_prov_mgr: STA Disconnected
E (48115) wifi_prov_mgr: Disconnect reason : 15
E (48121) wifi_prov_mgr: STA Auth Error
E (48126) app: Provisioning failed!
        Reason : Wi-Fi station authentication failed
        Please reset to factory and retry provisioning
I (51253) app: Disconnected. Connecting to the AP again...
E (51257) wifi_prov_mgr: STA Disconnected
E (51257) wifi_prov_mgr: Disconnect reason : 205
I (52712) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (52714) wifi:state: init -> auth (b0)
I (52729) wifi:state: auth -> assoc (0)
I (52735) wifi:state: assoc -> run (10)
I (56769) wifi:state: run -> init (2c0)
I (56771) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (56771) wifi:new:<6,0>, old:<6,0>, ap:<255,255>, sta:<6,0>, prof:1
I (56775) app: Disconnected. Connecting to the AP again...

developerGM avatar Jan 28 '21 12:01 developerGM