mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Add WiFi reconnection logic to companion radio WiFi interface
The WiFi companion firmware previously had no reconnection handling after the initial WiFi.begin() call. On ESP32 Arduino core 2.x, the built-in auto-reconnect is unreliable, so if WiFi drops it never comes back. This adds a periodic health check (every 60s) in checkRecvFrame() that detects WiFi disconnection and calls WiFi.reconnect(). The check only activates after WiFi has successfully connected at least once, so it won't interfere with the initial connection attempt on startup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
748f9cfdda
commit
ec2dd475eb
2 changed files with 13 additions and 0 deletions
|
|
@ -53,6 +53,15 @@ void SerialWifiInterface::resetReceivedFrameHeader() {
|
|||
}
|
||||
|
||||
size_t SerialWifiInterface::checkRecvFrame(uint8_t dest[]) {
|
||||
// periodic WiFi health check (every 60s, only after first successful connection)
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
_wifi_was_connected = true;
|
||||
} else if (_wifi_was_connected && millis() >= _wifi_check_time) {
|
||||
WIFI_DEBUG_PRINTLN("WiFi disconnected, attempting reconnect...");
|
||||
WiFi.reconnect();
|
||||
_wifi_check_time = millis() + 60000;
|
||||
}
|
||||
|
||||
// check if new client connected
|
||||
auto newClient = server.available();
|
||||
if (newClient) {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ class SerialWifiInterface : public BaseSerialInterface {
|
|||
bool _isEnabled;
|
||||
unsigned long _last_write;
|
||||
unsigned long adv_restart_time;
|
||||
bool _wifi_was_connected;
|
||||
unsigned long _wifi_check_time;
|
||||
|
||||
WiFiServer server;
|
||||
WiFiClient client;
|
||||
|
|
@ -39,6 +41,8 @@ public:
|
|||
deviceConnected = false;
|
||||
_isEnabled = false;
|
||||
_last_write = 0;
|
||||
_wifi_was_connected = false;
|
||||
_wifi_check_time = 0;
|
||||
send_queue_len = recv_queue_len = 0;
|
||||
received_frame_header.type = 0;
|
||||
received_frame_header.length = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue