espressif / esp-idf-provisioning-ios

Apache License 2.0
130 stars 62 forks source link

How to know when the user has entered an incorrect network password? #18

Closed maro01507i closed 3 years ago

maro01507i commented 3 years ago

Hello,

I need to know when the user has introduced an incorrect password, to warn them about it. So far I tested it and it seems that when I call the provision method, the status returns something along the lines of: "wifiStatusAuthenticationError".

device?.provision(ssid: ssid, passPhrase: pass) { status in        
switch status {
            case .success:
                print("Success conecting to netowkr: \(ssid)")
            case .configApplied:
                print("Configuration applied, waiting for the device to connect")
            default:
                let error = "\(status)"
                if error.contains("wifiStatusAuthenticationError") {
                   print("Error, wifi password incorrect")
                } else {
                    print("Another error.")
                }
     }

The problem is that sometimes, when the password is incorrect, I received something like this:

Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline."

Is there a consistent way to do this? Or there is something I am not understanding/ doing wrong?

vikas-chandra-mnnit commented 3 years ago

Hi @maro01507i , Please refer provision() API use in our sample application ESPProvisionSample. Line 77 in this file show that error code is passed as argument inside the failure enum. Add case .wifiStatusAuthenticationError inside the switch statement to handle incorrect password case. Let me know if it resolves your query.

Screenshot 2020-12-14 at 8 12 35 PM
maro01507i commented 3 years ago

Hello @vikas-chandra-mnnit. Thanks for the answer; it helped me to at least having all the errors better organized.

Although I have to say that I still having the same issue, sometimes when I introduced a wrong password, instead of returning the desired error (the one that you pointed out), it returns the error that I have commented in the original post; but since I need to connect to the given network later, I can manage the error later, and thus, it's not a big problem.

If you wanna keep discussing about the issue that I mentioned, tell me, otherwise just close this issue.

shahpiyushv commented 3 years ago

@maro01507i , do you see this specifically for SoftAP based provisioning? If yes, it is possible that your phone is indeed getting disconnected from the device. When the device switches from an AP to AP + Station mode, it changes the Wi-Fi channel as per the channel of the target network. During this channel switch, sometimes, the phone gets disconnected from the device.

maro01507i commented 3 years ago

@shahpiyushv Yes, it is SoftAp based provisioning, so maybe that's what is happening. Since my problem was solved with what I commented previously, I will close this issue. Thanks for attending me.