fix wokwi wifi
This commit is contained in:
+12
-16
@@ -31,31 +31,27 @@ pub async fn setup_wifi(
|
|||||||
#[cfg(feature = "wokwi")]
|
#[cfg(feature = "wokwi")]
|
||||||
pub async fn setup_wifi(
|
pub async fn setup_wifi(
|
||||||
wifi: esp_hal::peripherals::WIFI<'static>,
|
wifi: esp_hal::peripherals::WIFI<'static>,
|
||||||
flash: esp_hal::peripherals::FLASH<'static>,
|
nvs: Arc<Mutex<Nvs>>,
|
||||||
spawner: &Spawner,
|
spawner: &Spawner,
|
||||||
) {
|
) {
|
||||||
log::info!("Wokwi mode active: pre-seeding WiFi Manager with Wokwi credentials");
|
log::info!("Wokwi mode active: pre-seeding WiFi Manager with Wokwi credentials");
|
||||||
|
|
||||||
// Preload connection data so init_wm can connect immediately without AP setup.
|
use esp_nvs::Key;
|
||||||
let nvs = match esp_hal_wifimanager::Nvs::new(0x9000, 0x6000, flash) {
|
const WIFIMANAGER_NAMESPACE: Key = Key::from_str("wifimanager");
|
||||||
Ok(nvs) => nvs,
|
const WIFIMANAGER_NVS_KEY: Key = Key::from_str("WIFI_SETUP");
|
||||||
Err(e) => {
|
|
||||||
log::error!("Failed to initialize NVS for Wokwi: {e:?}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
if let Err(e) = nvs
|
if let Err(e) = nvs.lock().await.set(
|
||||||
.set(
|
&WIFIMANAGER_NAMESPACE,
|
||||||
esp_hal_wifimanager::WIFI_NVS_KEY,
|
&WIFIMANAGER_NVS_KEY,
|
||||||
"{\"ssid\":\"Wokwi-GUEST\",\"psk\":\"\",\"data\":{}}",
|
"{\"ssid\":\"Wokwi-GUEST\",\"psk\":\"\",\"data\":{}}",
|
||||||
)
|
) {
|
||||||
.await
|
|
||||||
{
|
|
||||||
log::error!("Failed to store Wokwi WiFi config in NVS: {e:?}");
|
log::error!("Failed to store Wokwi WiFi config in NVS: {e:?}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Preload connection data so init_wm can connect immediately without AP setup.
|
||||||
|
let nvs = esp_hal_wifimanager::Nvs::new_from_nvs(nvs, 0, 0);
|
||||||
|
|
||||||
let mut wm_settings = esp_hal_wifimanager::WmSettings::default();
|
let mut wm_settings = esp_hal_wifimanager::WmSettings::default();
|
||||||
|
|
||||||
// Wokwi simulation uses a default open network called "Wokwi-GUEST"
|
// Wokwi simulation uses a default open network called "Wokwi-GUEST"
|
||||||
|
|||||||
Reference in New Issue
Block a user