Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Doubt about how to handle WiFi reconnections #6672

Unanswered
gonzabrusco asked this question in Q&A
Discussion options

Hello. I have a project where I do A LOT of things simultaneously, most of then reliying on WiFi (Modbus TCP, WebServer, MQTT, etc).

I always had this doubt and I don't know where to look the answer for this. The question would be: what happens to all the WiFi related objects when there is a disconnection and reconnection of WiFi. Should I instantiate them again? Or the same objects keep working?

Examples:

WiFiServer: Used in ModbusTCP and WebSever. Should I start it again after reconnection? Or this is handled internally on the WiFi class and I should not care...

WiFiClient: When I receive a ModbusTCP request, the WebSever object gives me a WiFiClient that handles the connection between the ESP32 and the client. What happens with this object if the WiFi gets disconnected when I was about to send something to it. The object is still valid after reconnection?

Most of the Arduino examples just connect to a WiFi and "do something" with a WiFiClient or a WiFiServer. But none of them tells you how to proceed if a disconnection of the WiFi occurs. They are too simplistic.

TLDR: If WiFi disconnects, what happens to existing WiFiClients, WiFiClientsSecure, WiFiServer... etc...? Do they need to be iniciated again?

You must be logged in to vote

Replies: 2 comments

Comment options

The same question applies to UDP too!

You must be logged in to vote
0 replies
Comment options

Hi @gonzabrusco. That is a complicated question. arduino-esp32 r2.0.3 fixes a WiFi autoreconnect issue, but you aren't asking about that. WebServer actually implements a TCP server. I suspect the TCP server doesn't care about the state of WiFi, but it's a valid concern as buffers could be left unsent.

In our project we are using esphome/ESPAsyncWebServer-esphome@^2.1.0, which is a little different than WebServer. So far my testing shows the server survives WiFi disconnects/reconnects just fine. Don't know about memory leaks yet.

Obviously the WiFiClient won't be able to send when WiFi disconnects. I expect it will timeout, but no idea what happens to data in the TX buffer. Hopefully the TX buffer is reset after the send fails.

UDP doesn't have a handshake, so it doesn't care about the state of WiFi. It just broadcasts the data and hopes someone is listening! I don't expect any issues there.

If you're up for writing some test projects to test for memory leaks or weird behavior of WiFiServer, etc on wifi disconnects/reconnects, I'm sure it would be a valuable contribution to the community.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
Area: BT&Wifi BT & Wifi related issues Type: Question Only question

AltStyle によって変換されたページ (->オリジナル) /