ESP8266 (Arduino) WiFi intermittent connection when between mesh access points

  Kiến thức lập trình

Background

I have an Arduino sketch running on an ESP8266 clone, using the vanilla ESP8266WiFi.h library.

This works as expected on the bench, when it is in clear sight of just one access point (Netgear Orbi). In another room, the Wifi performance is very intermittent. The signal strength is good, but there is circumstantial evidence that being within sight of two access points yields poor perfomance with this device. ‘Real’ devices such as my laptop have rock solid WiFi in the same location.

The way the Orbi system works is that several access points all broadcast the same SSID, all on the same channel. My suspicion is that this confuses the ESP8266 stack somehow.

Testing

I have enbled WiFi debugging in the code, though the messages appear to come from within pre-canned Expressif libraries, so there is only so much I can learn from them.

Because this is WiFi, I’ve not tried tools like Wireshark so far, and the WiFi analysis tools on my phone are no good. I’m fundamentally confident in the code, but clearly I’m missing something to deal with this case.

Below are two examples: one successful, showing rapid connection to WiFi, DHCP, and subsequent network traffic; the other shows poor connection and ultimately unsuccessful network traffic. (Please note that a bug in the MQTT implementation causes the first attempt to fail; it’s the subsequent failure that highlights the issue.)

Good

15:13:56.873 -> 1db512b-dirty (Tue  2 Jan 15:08:50 GMT 2024)
15:13:56.873 -> External System
15:13:56.906 -> WIFI: INFO: MAC: 40:91:51:52:bd:7e
15:13:56.906 -> WIFI: INFO: inital connection...
15:13:56.906 -> fpm close 1 
15:13:56.906 -> mode : sta(40:91:51:52:bd:7e)
15:13:56.906 -> add if0
15:13:59.863 -> scandone
15:14:00.726 -> state: 0 -> 2 (b0)
15:14:00.760 -> state: 2 -> 3 (0)
15:14:00.760 -> state: 3 -> 5 (10)
15:14:00.760 -> add 0
15:14:00.760 -> aid 3
15:14:00.760 -> cnt 
15:14:00.793 -> 
15:14:00.793 -> connected with XXXX, channel 9
15:14:00.793 -> dhcp client start...
15:14:00.793 -> WIFI: INFO: connected

15:14:02.354 -> ip:10.23.3.142,mask:255.255.252.0,gw:10.23.1.1
15:14:02.388 -> WIFI: INFO: got IP: 10.23.3.142

15:14:02.421 -> MQTT: INFO: starting
15:14:02.421 -> MQTT: INFO: trying to connect
15:14:02.454 -> MQTT: INFO: connect failed; will try again

15:14:07.470 -> MQTT: INFO: trying to connect
15:14:07.503 -> MQTT: INFO: connected

15:14:10.759 -> pm open,type:2 0

Bad

15:13:07.041 -> 1db512b-dirty (Tue  2 Jan 15:08:50 GMT 2024)
15:13:07.075 -> External System
15:13:07.075 -> WIFI: INFO: MAC: 40:91:51:52:bd:7e
15:13:07.075 -> WIFI: INFO: inital connection...
15:13:07.075 -> fpm close 1 
15:13:07.075 -> mode : sta(40:91:51:52:bd:7e)
15:13:07.075 -> add if0
15:13:10.032 -> scandone
15:13:10.928 -> state: 0 -> 2 (b0)
15:13:11.925 -> state: 2 -> 0 (2)
15:13:11.925 -> reconnect
15:13:11.925 -> WIFI: INFO: disconnected

15:13:14.781 -> scandone
15:13:14.781 -> state: 0 -> 2 (b0)
15:13:14.781 -> state: 2 -> 3 (0)
15:13:14.781 -> state: 3 -> 5 (10)
15:13:14.781 -> add 0
15:13:14.781 -> aid 3
15:13:14.781 -> cnt 
15:13:14.814 -> 
15:13:14.814 -> connected with XXXX, channel 9
15:13:14.848 -> dhcp client start...
15:13:14.848 -> WIFI: INFO: connected

15:13:22.820 -> ip:10.23.3.142,mask:255.255.252.0,gw:10.23.1.1
15:13:22.820 -> WIFI: INFO: got IP: 10.23.3.142

15:13:24.780 -> pm open,type:2 0

15:13:25.345 -> MQTT: INFO: starting
15:13:25.345 -> MQTT: INFO: trying to connect
15:13:30.328 -> MQTT: INFO: connect failed; will try again

15:13:35.346 -> MQTT: INFO: trying to connect
15:13:40.330 -> MQTT: INFO: connect failed; will try again

Code

I’ve deliberately not presented any code in this post because I do not believe it would be instructive, though I can post a GitHub link if anyone insists.

Next steps

I guess what I’m after is one of more of:

  • Corroboration that this scenario is a known problem,
  • An explanation of the debug output,
  • Suggestions as to further debugging that might be instructing

Well…

I uploaded the WifiScan example sketch, which just lists all the available networks continuously.

What I saw was really surprising: at the problematic location – where I thought I could see more than one access point – the ESP8266 could not see any of them. That explains a lot!

But why? The access points would intermittently show up on the list, and no other networks were on the same channel. But I changed the channel anyway (9 to 12), and now the device can see all the access points with a really good signal.

Conclusions:

  • WiFi is hard and magical
  • Always use the example sketches before writing huge questions on SO
  • The ESP8266 WiFi stack does not have an issue with mesh networks

Anti-Conclusions:

  • Changing the WiFi channel in the absence of contention should not make a difference.

2

LEAVE A COMMENT