Add Wi-Fi next-profile rotation control

This commit is contained in:
2026-08-29 19:43:21 +02:00
parent 371c0ab896
commit 16c0c02389
7 changed files with 90 additions and 8 deletions
+64
View File
@@ -34,6 +34,7 @@ typedef enum {
MESSAGE_COMMAND_STOP,
MESSAGE_COMMAND_APPLY,
MESSAGE_COMMAND_RECONNECT,
MESSAGE_COMMAND_NEXT_PROFILE,
MESSAGE_STA_CONNECTED,
MESSAGE_STA_DISCONNECTED,
MESSAGE_STA_GOT_IP,
@@ -488,6 +489,58 @@ static void start_next_profile(manager_runtime_t *runtime)
schedule_cycle_retry(runtime);
}
static void start_next_profile_after_current(manager_runtime_t *runtime)
{
wifi_app_config_t config;
copy_working_config(&config);
uint8_t order[WIFI_CONFIG_STA_PROFILE_COUNT];
uint8_t count = build_profile_order(order, &config);
int8_t active_profile;
lock_shared();
active_profile = s_shared.snapshot.active_profile;
unlock_shared();
if (count == 0U) {
wifi_config_secure_wipe(&config, sizeof(config));
set_last_error(ESP_ERR_NOT_FOUND);
return;
}
uint8_t active_index = 0U;
bool found_active = false;
for (uint8_t index = 0U; index < count; ++index) {
if (active_profile >= 0 && order[index] == (uint8_t)active_profile) {
active_index = index;
found_active = true;
break;
}
}
for (uint8_t index = 0U; index < count; ++index) {
uint8_t source = found_active ? (uint8_t)((active_index + 1U + index) % count)
: index;
runtime->profile_order[index] = order[source];
}
runtime->profile_count = count;
runtime->next_profile = 0U;
runtime->attempt_deadline = 0;
runtime->disconnect_deadline = 0;
runtime->backoff_deadline = 0;
runtime->stable_deadline = 0;
runtime->advance_after_disconnect = true;
uint32_t intentional_disconnects = runtime->intentional_disconnects;
mark_intentional_disconnect(runtime);
if (runtime->intentional_disconnects == intentional_disconnects) {
runtime->advance_after_disconnect = false;
start_next_profile(runtime);
} else {
/* Recover if the bounded queue drops the matching disconnect event. */
runtime->disconnect_deadline = esp_timer_get_time() +
WIFI_MANAGER_DISCONNECT_SETTLE_US;
}
wifi_config_secure_wipe(&config, sizeof(config));
}
static void start_profile_cycle(manager_runtime_t *runtime)
{
wifi_app_config_t config;
@@ -767,6 +820,12 @@ static void handle_message(manager_runtime_t *runtime,
}
break;
case MESSAGE_COMMAND_NEXT_PROFILE:
if (manager_is_started()) {
start_next_profile_after_current(runtime);
}
break;
case MESSAGE_STA_CONNECTED:
if (!manager_is_started() ||
!connected_event_matches_active_profile(message)) {
@@ -1356,6 +1415,11 @@ esp_err_t wifi_manager_reconnect(void)
return enqueue_lifecycle_command(MESSAGE_COMMAND_RECONNECT, -1);
}
esp_err_t wifi_manager_next_profile(void)
{
return enqueue_lifecycle_command(MESSAGE_COMMAND_NEXT_PROFILE, -1);
}
esp_err_t wifi_manager_get_snapshot(wifi_manager_snapshot_t *snapshot)
{
if (snapshot == NULL) {