Compare commits

...

4 Commits

Author SHA1 Message Date
copilot-swe-agent[bot] c10757defe chore: clarify deferred reconnect fallback log
Co-authored-by: 78 <4488133+78@users.noreply.github.com>
2026-03-10 13:06:13 +00:00
copilot-swe-agent[bot] 65ffda6341 fix: use timer for deferred wifi reconnect
Co-authored-by: 78 <4488133+78@users.noreply.github.com>
2026-03-10 13:05:49 +00:00
copilot-swe-agent[bot] 94659ec8b7 fix: defer wifi reconnect after config mode exit
Co-authored-by: 78 <4488133+78@users.noreply.github.com>
2026-03-10 13:04:32 +00:00
copilot-swe-agent[bot] f735b660ed Initial plan 2026-03-10 12:55:09 +00:00
2 changed files with 32 additions and 2 deletions
+26 -2
View File
@@ -25,6 +25,8 @@ static const char *TAG = "WifiBoard";
// Connection timeout in seconds
static constexpr int CONNECT_TIMEOUT_SEC = 60;
// Give SoftAP/web teardown a brief window to finish before restarting STA mode.
static constexpr uint64_t CONFIG_EXIT_RECONNECT_DELAY_US = 500000;
WifiBoard::WifiBoard() {
// Create connection timeout timer
@@ -36,6 +38,15 @@ WifiBoard::WifiBoard() {
.skip_unhandled_events = true
};
esp_timer_create(&timer_args, &connect_timer_);
esp_timer_create_args_t config_exit_timer_args = {
.callback = OnWifiConfigExitReconnect,
.arg = this,
.dispatch_method = ESP_TIMER_TASK,
.name = "wifi_cfg_exit_timer",
.skip_unhandled_events = true
};
esp_timer_create(&config_exit_timer_args, &config_exit_timer_);
}
WifiBoard::~WifiBoard() {
@@ -43,6 +54,10 @@ WifiBoard::~WifiBoard() {
esp_timer_stop(connect_timer_);
esp_timer_delete(connect_timer_);
}
if (config_exit_timer_) {
esp_timer_stop(config_exit_timer_);
esp_timer_delete(config_exit_timer_);
}
}
std::string WifiBoard::GetBoardType() {
@@ -131,8 +146,12 @@ void WifiBoard::OnNetworkEvent(NetworkEvent event, const std::string& data) {
case NetworkEvent::WifiConfigModeExit:
ESP_LOGI(TAG, "WiFi config mode exited");
in_config_mode_ = false;
// Try to connect with the new credentials
TryWifiConnect();
// Defer reconnect until config AP teardown has fully completed.
esp_timer_stop(config_exit_timer_);
if (esp_timer_start_once(config_exit_timer_, CONFIG_EXIT_RECONNECT_DELAY_US) != ESP_OK) {
ESP_LOGW(TAG, "Failed to schedule deferred WiFi reconnect, attempting immediate connection");
TryWifiConnect();
}
break;
default:
break;
@@ -156,6 +175,11 @@ void WifiBoard::OnWifiConnectTimeout(void* arg) {
board->StartWifiConfigMode();
}
void WifiBoard::OnWifiConfigExitReconnect(void* arg) {
auto* board = static_cast<WifiBoard*>(arg);
board->TryWifiConnect();
}
void WifiBoard::StartWifiConfigMode() {
in_config_mode_ = true;
// Transition to wifi configuring state
+6
View File
@@ -9,6 +9,7 @@
class WifiBoard : public Board {
protected:
esp_timer_handle_t connect_timer_ = nullptr;
esp_timer_handle_t config_exit_timer_ = nullptr;
bool in_config_mode_ = false;
NetworkEventCallback network_event_callback_ = nullptr;
@@ -36,6 +37,11 @@ protected:
*/
static void OnWifiConnectTimeout(void* arg);
/**
* Delayed reconnect after WiFi config AP teardown
*/
static void OnWifiConfigExitReconnect(void* arg);
public:
WifiBoard();
virtual ~WifiBoard();