espressif / esp-homekit-sdk

550 stars 99 forks source link

Hardcoded Wi-Fi credentials -- does it work? #10

Closed Cosmo closed 3 years ago

Cosmo commented 3 years ago

Currently, my only option is to use the provisioning app and scan the QR code to get my device connected to my Wi-Fi.

For some reason, when I try to flash my ESP32 with hardcoded Wi-Fi data (via menuconfig), the ESP32 tries to connect, then restarts, and tries again and again. Same Wi-Fi for both scenarios.

In menuconfig I disabled WPA3 support, to see if it makes any difference (no luck). I also created an additional 2.4 GHz Wi-Fi access point in my home to see if the problem still exists. For SSID and password, I used simple characters (a-z, 0-9) to rule out any encoding issues or stuff like that.

This is what my monitor looks like on my main Wi-Fi (2.4 GHz / 5 GHz with WPA2/WPA3):

I (55950) wifi:Send SA Query req with transaction id 410f
I (56160) wifi:Send SA Query req with transaction id c3b7
I (56360) wifi:Send SA Query req with transaction id 452b
I (56570) wifi:Send SA Query req with transaction id 13c0
I (56770) wifi:Send SA Query req with transaction id 1d76
I (56970) wifi:No response to 5 SA Queries, reset connection
I (56970) wifi:state: run -> init (200)
I (56980) wifi:pm stop, total sleep time: 15846362 us / 19093577 us

W (56980) wifi:<ba-del>idx
I (56980) wifi:new:<13,0>, old:<13,0>, ap:<255,255>, sta:<13,0>, prof:1
I (56990) app_wifi: Disconnected. Connecting to the AP again...
I (57360) wifi:new:<13,0>, old:<13,0>, ap:<255,255>, sta:<13,0>, prof:1
I (57360) wifi:state: init -> auth (b0)
I (59840) wifi:state: auth -> assoc (0)
I (59850) wifi:state: assoc -> run (10)
I (59880) wifi:connected with NoNetworkFound, aid = 18, channel 13, BW20, bssid = 44:4e:6d:a5:44:70
I (59890) wifi:security: WPA3-SAE, phy: bgn, rssi: -68
I (59890) wifi:pm start, type: 1

I (59900) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (60460) app_wifi: Connected with IP Address:10.0.0.146
I (60460) esp_netif_handlers: sta ip: 10.0.0.146, mask: 255.255.0.0, gw: 10.0.0.1

I (62750) wifi:Send SA Query req with transaction id d4a9
I (62950) wifi:Send SA Query req with transaction id 35a1
I (63160) wifi:Send SA Query req with transaction id 23e8
I (63370) wifi:Send SA Query req with transaction id 1f9
I (63570) wifi:Send SA Query req with transaction id 25f4
I (63770) wifi:No response to 5 SA Queries, reset connection
I (63770) wifi:state: run -> init (200)
I (63770) wifi:pm stop, total sleep time: 2155892 us / 3882892 us

W (63780) wifi:<ba-del>idx
I (63780) wifi:new:<13,0>, old:<13,0>, ap:<255,255>, sta:<13,0>, prof:1
I (63790) app_wifi: Disconnected. Connecting to the AP again...
I (64150) wifi:new:<13,0>, old:<13,0>, ap:<255,255>, sta:<13,0>, prof:1
I (64150) wifi:state: init -> auth (b0)
I (66430) wifi:state: auth -> assoc (0)
I (66440) wifi:state: assoc -> run (10)
I (66470) wifi:connected with NoNetworkFound, aid = 18, channel 13, BW20, bssid = 44:4e:6d:a5:44:70
I (66470) wifi:security: WPA3-SAE, phy: bgn, rssi: -67
I (66480) wifi:pm start, type: 1

I (66560) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (67420) app_wifi: Connected with IP Address:10.0.0.146
I (67420) esp_netif_handlers: sta ip: 10.0.0.146, mask: 255.255.0.0, gw: 10.0.0.1
I (68020) wifi:state: run -> init (22c0)
I (68020) wifi:pm stop, total sleep time: 680035 us / 1537762 us

W (68020) wifi:<ba-del>idx
I (68020) wifi:new:<13,0>, old:<13,0>, ap:<255,255>, sta:<13,0>, prof:1
I (68020) app_wifi: Disconnected. Connecting to the AP again...
I (68390) wifi:new:<13,0>, old:<13,0>, ap:<255,255>, sta:<13,0>, prof:1
I (68390) wifi:state: init -> auth (b0)
I (68400) wifi:state: auth -> assoc (0)
I (68410) wifi:state: assoc -> run (10)
I (68440) wifi:connected with NoNetworkFound, aid = 18, channel 13, BW20, bssid = 44:4e:6d:a5:44:70
I (68440) wifi:security: WPA3-SAE, phy: bgn, rssi: -68
I (68450) wifi:pm start, type: 1

I (68500) wifi:AP's beacon interval = 102400 us, DTIM period = 1
I (69420) app_wifi: Connected with IP Address:10.0.0.146
I (69420) esp_netif_handlers: sta ip: 10.0.0.146, mask: 255.255.0.0, gw: 10.0.0.1

As I mentioned, it works via the provisioning app without any problems -- on the same Wi-Fi.

Can someone please verify whether the hardcoded method works or point me in the right direction to debug my issue?

Thanks!

EDIT: Don't get confused when you read my log. My Wi-Fi SSID is "NoNetworkFound" :)

shahpiyushv commented 3 years ago

@Cosmo , the primary difference in the Wi-Fi configuration when you use hard coded credentials is this. Please try setting this value to false and let me know if it works.

Even if this indeed works, it would be nice if you can test the simple Wi-Fi station example from esp-idf with your AP and if you see similar behaviour, file an issue on esp-idf. If you can get some sniffer captures, that would help too.

Cosmo commented 3 years ago

@shahpiyushv Thank you very much! I wish I would have asked you earlier :) I set .capable to false and now my ESP connects and stays connected — perfect!

So when I understand the flag correctly, PMF stands for protected management frames and either my access point doesn't support it or it's disabled.

After a quick check, my router shows that PMF is grayed-out because WPA2+WPA3 is enabled. WPA3 mandates the use of PMF, whereas in WPA2, it's optional. I guess I need to invest a bit more time into this.

Later, I tested the WiFi station example. I set my SSID and password via menuconfig, build and flashed on my device. It worked without any further changes.

So thanks again for saving me a lot of time and a headache. I really appreciate it. 👍