From 20e158831bcc24b3db5169d148b17750ed39b23e Mon Sep 17 00:00:00 2001 From: mikee47 Date: Sun, 24 Nov 2024 10:46:31 +0000 Subject: [PATCH] Fix race condition enabling access point With Basic_WiFi sample, system crashes in multicore. If station is initialised *before* access point, this doesn't happen. Deferring the call to `esp_wifi_start` fixes the issue. --- .../Network/Arch/Esp32/Platform/AccessPointImpl.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sming/Components/Network/Arch/Esp32/Platform/AccessPointImpl.cpp b/Sming/Components/Network/Arch/Esp32/Platform/AccessPointImpl.cpp index ae783d746f..2b69133aaf 100644 --- a/Sming/Components/Network/Arch/Esp32/Platform/AccessPointImpl.cpp +++ b/Sming/Components/Network/Arch/Esp32/Platform/AccessPointImpl.cpp @@ -57,7 +57,7 @@ void AccessPointImpl::enable(bool enabled, bool save) } } ESP_ERROR_CHECK(esp_wifi_set_storage(save ? WIFI_STORAGE_FLASH : WIFI_STORAGE_RAM)); - ESP_ERROR_CHECK(esp_wifi_set_mode((wifi_mode_t)mode)); + ESP_ERROR_CHECK(esp_wifi_set_mode(mode)); } bool AccessPointImpl::isEnabled() const @@ -88,10 +88,13 @@ bool AccessPointImpl::config(const String& ssid, String password, WifiAuthMode m config.ap.authmode = (wifi_auth_mode_t)mode; config.ap.max_connection = 8; + bool enabled = isEnabled(); enable(true, false); ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_AP, &config)); - ESP_ERROR_CHECK(esp_wifi_start()); + if(enabled) { + System.queueCallback(esp_wifi_start); + } return true; }