feat: keep admin portal online
This commit is contained in:
@@ -159,10 +159,14 @@ void app_main(void)
|
|||||||
|
|
||||||
if (!wifi_ok) {
|
if (!wifi_ok) {
|
||||||
ESP_LOGW(TAG, "Entering WiFi onboarding mode...");
|
ESP_LOGW(TAG, "Entering WiFi onboarding mode...");
|
||||||
wifi_onboard_start(); /* blocks, restarts on success */
|
wifi_onboard_start(WIFI_ONBOARD_MODE_CAPTIVE); /* blocks, restarts on success */
|
||||||
return; /* unreachable */
|
return; /* unreachable */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wifi_onboard_start(WIFI_ONBOARD_MODE_ADMIN) != ESP_OK) {
|
||||||
|
ESP_LOGW(TAG, "Local admin portal unavailable; continuing without config hotspot");
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Outbound dispatch task should start first to avoid dropping early replies. */
|
/* Outbound dispatch task should start first to avoid dropping early replies. */
|
||||||
ESP_ERROR_CHECK((xTaskCreatePinnedToCore(
|
ESP_ERROR_CHECK((xTaskCreatePinnedToCore(
|
||||||
|
|||||||
@@ -2,9 +2,14 @@
|
|||||||
|
|
||||||
#include "esp_err.h"
|
#include "esp_err.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
WIFI_ONBOARD_MODE_CAPTIVE = 0,
|
||||||
|
WIFI_ONBOARD_MODE_ADMIN,
|
||||||
|
} wifi_onboard_mode_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start WiFi onboarding captive portal.
|
* Start WiFi onboarding/configuration portal.
|
||||||
* Opens a soft AP, DNS hijacker, and HTTP configuration server.
|
* CAPTIVE mode opens DNS hijack + config page and blocks forever.
|
||||||
* Blocks until the user submits credentials, then saves to NVS and restarts.
|
* ADMIN mode keeps a local config hotspot alive without captive redirects.
|
||||||
*/
|
*/
|
||||||
esp_err_t wifi_onboard_start(void);
|
esp_err_t wifi_onboard_start(wifi_onboard_mode_t mode);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ static EventGroupHandle_t s_wifi_event_group;
|
|||||||
static int s_retry_count = 0;
|
static int s_retry_count = 0;
|
||||||
static char s_ip_str[16] = "0.0.0.0";
|
static char s_ip_str[16] = "0.0.0.0";
|
||||||
static bool s_connected = false;
|
static bool s_connected = false;
|
||||||
|
static bool s_reconnect_enabled = true;
|
||||||
|
|
||||||
static const char *wifi_reason_to_str(wifi_err_reason_t reason)
|
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) {
|
if (disc) {
|
||||||
ESP_LOGW(TAG, "Disconnected (reason=%d:%s)", disc->reason, wifi_reason_to_str(disc->reason));
|
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 */
|
/* Exponential backoff: 1s, 2s, 4s, 8s, ... capped at 30s */
|
||||||
uint32_t delay_ms = MIMI_WIFI_RETRY_BASE_MS << s_retry_count;
|
uint32_t delay_ms = MIMI_WIFI_RETRY_BASE_MS << s_retry_count;
|
||||||
if (delay_ms > MIMI_WIFI_RETRY_MAX_MS) {
|
if (delay_ms > MIMI_WIFI_RETRY_MAX_MS) {
|
||||||
@@ -120,6 +121,7 @@ esp_err_t wifi_manager_start(void)
|
|||||||
return ESP_ERR_NOT_FOUND;
|
return ESP_ERR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s_reconnect_enabled = true;
|
||||||
ESP_LOGI(TAG, "Connecting to SSID: %s", wifi_cfg.sta.ssid);
|
ESP_LOGI(TAG, "Connecting to SSID: %s", wifi_cfg.sta.ssid);
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
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)
|
esp_err_t wifi_manager_stop(void)
|
||||||
{
|
{
|
||||||
|
s_reconnect_enabled = false;
|
||||||
esp_wifi_disconnect();
|
esp_wifi_disconnect();
|
||||||
esp_wifi_stop();
|
esp_wifi_stop();
|
||||||
s_connected = false;
|
s_connected = false;
|
||||||
@@ -260,3 +263,11 @@ esp_err_t wifi_manager_stop(void)
|
|||||||
ESP_LOGI(TAG, "WiFi stopped");
|
ESP_LOGI(TAG, "WiFi stopped");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wifi_manager_set_reconnect_enabled(bool enabled)
|
||||||
|
{
|
||||||
|
s_reconnect_enabled = enabled;
|
||||||
|
if (!enabled) {
|
||||||
|
s_retry_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,3 +59,8 @@ bool wifi_manager_has_credentials(void);
|
|||||||
* Stop WiFi (for mode switching during onboarding).
|
* Stop WiFi (for mode switching during onboarding).
|
||||||
*/
|
*/
|
||||||
esp_err_t wifi_manager_stop(void);
|
esp_err_t wifi_manager_stop(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable or disable STA auto-reconnect on disconnect events.
|
||||||
|
*/
|
||||||
|
void wifi_manager_set_reconnect_enabled(bool enabled);
|
||||||
|
|||||||
Reference in New Issue
Block a user