Add WiFi reconnection retry logic to recover from unreliable WiFi
- Implement periodic WiFi reconnection attempts when stuck in AP mode - Add WIFI_RECONNECT_INTERVAL_MS config (default 60s) for configurable retry frequency - Prevent data loss by automatically attempting to switch back to STA mode - Maintain AP mode for manual configuration if reconnection fails - Track WiFi config and last reconnection attempt time in shared state - Add wifi_try_reconnect_sta() and wifi_restore_ap_mode() helper functions - Log reconnection attempts and results for debugging
This commit is contained in:
12
src/main.cpp
12
src/main.cpp
@@ -112,6 +112,11 @@ void setup() {
|
||||
display_set_sender_statuses(g_receiver_shared.sender_statuses, NUM_SENDERS);
|
||||
|
||||
bool has_cfg = wifi_load_config(g_cfg);
|
||||
|
||||
// Store WiFi config in shared state for later reconnection attempts
|
||||
g_receiver_shared.wifi_config = g_cfg;
|
||||
g_receiver_shared.last_wifi_reconnect_attempt_ms = 0;
|
||||
|
||||
if (has_cfg && wifi_connect_sta(g_cfg)) {
|
||||
g_receiver_shared.ap_mode = false;
|
||||
time_receiver_init(g_cfg.ntp_server_1.c_str(), g_cfg.ntp_server_2.c_str());
|
||||
@@ -124,6 +129,13 @@ void setup() {
|
||||
char ap_ssid[32];
|
||||
snprintf(ap_ssid, sizeof(ap_ssid), "%s%04X", AP_SSID_PREFIX, g_short_id);
|
||||
wifi_start_ap(ap_ssid, AP_PASSWORD);
|
||||
|
||||
// Store AP credentials in shared state for potential reconnection fallback
|
||||
strncpy(g_receiver_shared.ap_ssid, ap_ssid, sizeof(g_receiver_shared.ap_ssid) - 1);
|
||||
g_receiver_shared.ap_ssid[sizeof(g_receiver_shared.ap_ssid) - 1] = '\0';
|
||||
strncpy(g_receiver_shared.ap_password, AP_PASSWORD, sizeof(g_receiver_shared.ap_password) - 1);
|
||||
g_receiver_shared.ap_password[sizeof(g_receiver_shared.ap_password) - 1] = '\0';
|
||||
|
||||
if (g_cfg.ntp_server_1.isEmpty()) {
|
||||
g_cfg.ntp_server_1 = "pool.ntp.org";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user