feat: keep admin portal online

This commit is contained in:
Asklv
2026-03-08 23:04:14 +08:00
parent 6c283553f9
commit 163f946e50
4 changed files with 31 additions and 6 deletions

View File

@@ -15,6 +15,7 @@ static EventGroupHandle_t s_wifi_event_group;
static int s_retry_count = 0;
static char s_ip_str[16] = "0.0.0.0";
static bool s_connected = false;
static bool s_reconnect_enabled = true;
static const char *wifi_reason_to_str(wifi_err_reason_t reason)
{
@@ -44,7 +45,7 @@ static void event_handler(void *arg, esp_event_base_t event_base,
if (disc) {
ESP_LOGW(TAG, "Disconnected (reason=%d:%s)", disc->reason, wifi_reason_to_str(disc->reason));
}
if (s_retry_count < MIMI_WIFI_MAX_RETRY) {
if (s_reconnect_enabled && s_retry_count < MIMI_WIFI_MAX_RETRY) {
/* Exponential backoff: 1s, 2s, 4s, 8s, ... capped at 30s */
uint32_t delay_ms = MIMI_WIFI_RETRY_BASE_MS << s_retry_count;
if (delay_ms > MIMI_WIFI_RETRY_MAX_MS) {
@@ -120,6 +121,7 @@ esp_err_t wifi_manager_start(void)
return ESP_ERR_NOT_FOUND;
}
s_reconnect_enabled = true;
ESP_LOGI(TAG, "Connecting to SSID: %s", wifi_cfg.sta.ssid);
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
@@ -252,6 +254,7 @@ bool wifi_manager_has_credentials(void)
esp_err_t wifi_manager_stop(void)
{
s_reconnect_enabled = false;
esp_wifi_disconnect();
esp_wifi_stop();
s_connected = false;
@@ -260,3 +263,11 @@ esp_err_t wifi_manager_stop(void)
ESP_LOGI(TAG, "WiFi stopped");
return ESP_OK;
}
void wifi_manager_set_reconnect_enabled(bool enabled)
{
s_reconnect_enabled = enabled;
if (!enabled) {
s_retry_count = 0;
}
}