Doubt about how to handle WiFi reconnections #6672
Replies: 2 comments
-
The same question applies to UDP too! |
Beta Was this translation helpful? Give feedback.
-
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 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. |
Beta Was this translation helpful? Give feedback.
-
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?
Beta Was this translation helpful? Give feedback.
All reactions