dl9rdz / rdz_ttgo_sonde

264 stars 92 forks source link

WiFi in mode 3 fails to connect to AP, but works in mode 1 #96

Closed sgtwilko closed 3 years ago

sgtwilko commented 3 years ago

Describe the bug When left at the default Wifi setting of 3, it attempts to connect to my AP but gives up very quickly and starts the built in AP. If I change it to mode 1 it will connect fine. It also connected fine in mode 3 on the 0.8.0 firmware.

To Reproduce Steps to reproduce the behaviour: Use my AP and try to connect in mode 3

Expected behaviour It connects to the configured AP.

Screenshots If applicable, add screenshots to help explain your problem.

Version and specific configuration:

Additional context worked fine on 0.8.0 doesn't work on latest dev build.

The following is an edited log from the board (I removed the other access points, change the Network name, MAC address & password):

AIN: Running loop in state 2 [currentDisp:1, lastDisp:1]. free heap: 208320, unused stack: 6148
[WiFi-event] event: 0
WiFi interface ready
[WiFi-event] event: 2
WiFi client started
[WiFi-event] event: 1
Completed scan for access points
Network MyWifi RSSI -54, MAC DE:AD:BE:EF:DE:AD, enc: WPA2_PSK
Match for MyWifi at 1
Match found at scan entry 0, config network 1
Connecting to: MyWifi with password SuperSecretPassword
......[WiFi-event] event: 3
WiFi clients stopped
[WiFi-event] event: 0
WiFi interface ready
[WiFi-event] event: 2
WiFi client started
Reconnecting to: MyWifi with password SuperSecretPassword
.........[WiFi-event] event: 4
Connected to access point
.....[WiFi-event] event: 3
WiFi clients stopped
[WiFi-event] event: 3
WiFi clients stopped
Activating access point mode
[WiFi-event] event: 0
WiFi interface ready
Wait 100 ms for AP_START...
[WiFi-event] event: 14
WiFi access point started
Ready
updateDisplayIP: 5 7
AP IP address: 192.168.4.1
Jan-NiklasB commented 3 years ago

Can also confirm this issue with "devel20210630-B11-full.bin" flashed on a T-Beam Lora32 T22 V1.1.

Seems like the ESP can't hold enough SSID's and if the wanted AP isn't one of the first found the ESP seems to stop scanning and opens it's own AP.

Switching to AP Mode 1 solves the problem temporarily, but if the AP isn't present, there's no way to reconfigure the TTGO.

LukePrior commented 3 years ago

I am encountering this same issue on devel20210726, here is my log:

Network MYWIFI: RSSI -88, MAC MACMACMAC, enc: WPA2_PSK
Match for MYWIFI at 2
Match found at scan entry 1, config network 2
Network MYWIFI: RSSI -91, MAC MACMACMAC, enc: WPA2_PSK
Match for MYWIFI at 2
Connecting to: MYWIFI with password PASSWORD
......[WiFi-event] event: 3
WiFi clients stopped
[WiFi-event] event: 0
WiFi interface ready
[WiFi-event] event: 2
WiFi client started
Reconnecting to: MYWIFI with password PASSWORD
..........[WiFi-event] event: 4
Connected to access point
....[WiFi-event] event: 3
WiFi clients stopped
[WiFi-event] event: 3
WiFi clients stopped
Activating access point mode
[WiFi-event] event: 0
WiFi interface ready
Wait 100 ms for AP_START...
[WiFi-event] event: 14
WiFi access point started
Ready
updateDisplayIP: 5 7
AP IP address: 192.168.4.1
dl9rdz commented 3 years ago

Is this also a problem on the most recent version?

Looks like a timing issue. It takes 5s to connect (echo "." is 500ms), and then after 2s more (7s in total) Mode 3 gives up (as it has not yet received an IP via DHCP after those 7 sec.. In the most recent version, this timeout should now be 10s in total instead of 7s (I removed the "Reconnecting" part which was needed in the past due to some bug in the wifi libraray, which seems no longer to be present).

If that still causes issues, one could also use separate time outs for connect and DHCP.

LukePrior commented 3 years ago

Is this also a problem on the most recent version?

I have updated to 20210728 and the issue now seems to appear about half the time.

Here is the updated log:

Network MYWIFI: RSSI -85, MAC MACMACMAC, enc: WPA2_PSK
Match for MYWIFI at 2
Match found at scan entry 1, config network 2
Connecting to: MYWIFI with password PASSWORD
..........[WiFi-event] event: 5
Disconnected from WiFi access point
.........[WiFi-event] event: 5
Disconnected from WiFi access point
.[WiFi-event] event: 3
WiFi clients stopped
Activating access point mode
[WiFi-event] event: 0
WiFi interface ready
Wait 100 ms for AP_START...
[WiFi-event] event: 14
WiFi access point started
Ready
updateDisplayIP: 5 7
AP IP address: 192.168.4.1
Jan-NiklasB commented 3 years ago

Well, I tried a bit around with the settings and found out that the behaviour is more or less inconsistent.

After initial problems I set the mode to 1, but later again to 3 when going on chase. But after initial setting it to 1 it seems to work quite fine...

So maybe a problem with the initial config shipped with the bin file?

dl9rdz commented 3 years ago

The connect + DHCP timeout in mode 3 is now twice as long (20s instead of 10s). Should be sufficient for even slow APs / DHCP servers. If not, use mode 1.