Skip to content

cgiWiFi: Add a watchdog to monitor WiFi - #85

Closed
phatpaul wants to merge 2 commits into
chmorgan:masterfrom
phatpaul:wifi_watchdog
Closed

cgiWiFi: Add a watchdog to monitor WiFi#85
phatpaul wants to merge 2 commits into
chmorgan:masterfrom
phatpaul:wifi_watchdog

Conversation

@phatpaul

@phatpaul phatpaul commented May 7, 2020

Copy link
Copy Markdown
Collaborator

cgiWiFi: Add a watchdog to monitor WiFi STA connection and reconnect if should be connected.

  • This is useful since ESP-IDF has trouble reconnecting STA sometimes (i.e. you reboot your router).
  • Makes sure that the current WiFi state is consistent with "cfg_state.new".

Also added option to start STA connection on boot.

  • use startCgiWifi() to connect STA on Boot-up if WiFi was previously configured,

I'm also adding a PR to esphttpd-freertos example project to demonstrate.

Sorry that the white-space formatting changes makes it hard to see the changes, I'm using VS-Code to auto format. I've been meaning to do a global reformat in a single commit, but not until all the outstanding PRs are closed...

@phatpaul

Copy link
Copy Markdown
Collaborator Author

I found that the new watchdog feature causes interruption in the AP connection periodically if the wanted STA is not available.

So, if my client is connected to ESP32 via it's AP, and there is a STA config set in ESP32, but that STA is not available, then every 30s there is a brief interruption in the connection. This caused websocket to disconnect. (and subsequently reconnect because I'm using ReconnectingWebsocket.js.)

Note that the OS (windows, android) does not disconnect the WiFi connection to ESP32 when these brief interruptions occur.

This isn't a major problem in my application, just an annoyance. The user should remove the STA config if it is no longer valid.

The watchdog interval can be configured via define in esp32_wifi.c. #define WATCHDOG_TIMEOUT (30 * 1000 / portTICK_PERIOD_MS) Should it be more easily customized or disabled?

Or is there a better way to accomplish robust STA reconnect? It seems the ESP32 can't scan for WiFi APs without changing it's only 2.4g radio channel briefly. Maybe there is a less disruptive way for the WiFi driver to scan other channels, like scan one channel at a time and return the the current channel in between to keep servicing it? (BTW I'm on IDF 3.3.3, maybe it's better in 4.x)

@chmorgan

Copy link
Copy Markdown
Owner

This is a limitation of the radio with the esp32. Note that the ap is a soft ap, it’s just along for the ride on whatever channel you are using. It doesn’t look like anything changed in the latest rev of the docs either, https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/wifi.html#wi-fi-channel-management

I’m guessing that the radio goes into search mode for the ap when you attempt an sta connection, as it can’t know in advance what channel the ap is on. Maybe you could save and specify the channel on your reconnection? This might let the radio avoid the channel scan and the drops on the ap side.

For my application I ended up with a state machine that would avoid channel change cases. I can’t recall exactly but it did require limiting the overall system to prevent drops. I can share that code if you are interested in taking a peek. It’s a few years old but it worked well when I stopped using the esp32.

@phatpaul phatpaul mentioned this pull request Jul 23, 2021
@phatpaul

Copy link
Copy Markdown
Collaborator Author

I rebased this, but need to test if it is still needed.
Did esp-idf improve the STA connection robustness since my experience with IDF v3?

@phatpaul

phatpaul commented Aug 8, 2022

Copy link
Copy Markdown
Collaborator Author

this is included in #100

@phatpaul phatpaul closed this Aug 8, 2022
@phatpaul
phatpaul deleted the wifi_watchdog branch August 14, 2024 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants