ESPSomfy-RTS icon indicating copy to clipboard operation
ESPSomfy-RTS copied to clipboard

Wifi connection timeout

Open alka79 opened this issue 1 month ago • 6 comments

Describe you new feature you'd like

My wifi access point has sometimes it's own life. It randomly resets the 2.4G band every day or two ! There must be to many IOT devices on my wifi ! When this happens, 2.4G wifi is lost for about 40secs. All devices on my network recover almost immediately when wifi comes back, but ESPSomfy took several more minutes. That made me investigate. It has highlighted an ESPSomfy wifi reconnection behaviour which is not optimal IMHO. Leading to some suggestions below.

The way it works as I could understand:

  • At reset, if no SSID is present in the settings, the board starts in AP mode, launching the SoftAP (hotspot). If SSID is present in the settings, as it normally is after initial setup, the board will enter in STA mode and try to connect to the set SSID to the strongest AP.
  • At any point in time, if wifi connection is lost, the board will try to reconnect.
  • Wifi connection (or reconnection) has a 20sec timeout. After that, if reconnect failed, the softAP is started (why it is actually started in AP_STA mode is unclear to me)
  • SoftAP has also a timeout. If no client connects in 3 minutes, the SoftAP is closed and the wifi connection process starts over.

So in the end, the board recovers from a temporary wifi failure but takes some extra time.

IMHO this could be improved.

  • 20 sec reconnection timeout is really short. An AP reboot takes longer.
  • Catch the 3 minutes window while the board is in SoftAP mode could be challenging !

I have done some minimal changes to the code to accommodate:

  • set the wifi connection timeout to 2 minutes instead of 20 sec. That should cover most cases.
  • use the blue builtin_led to give some visual indication of the status of the board : Led steady on during setup and when wifi is disconnected. Led blinking slowly when board is in softAP mode. This could be improved with deeper changes to the code, like a different timeout for first connection (short) and reconnection (long).

I understand the need to re-enter SoftAP mode in case the wifi settings must be changed. This fortunately occurs rarely and is predictable, So I don't mind to wait some extra minutes when it happens.

BTW; as I understand, an easy way to force restart in SoftAP mode is to wipe the SSID in the settings and reset. The question was once asked but not sure about the answer at that time.

alka79 avatar May 19 '24 20:05 alka79