From 931e24815baa0f16efc475d60a09ceb09f5562e1 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Wed, 1 May 2024 19:06:36 +0000 Subject: [PATCH] Bugfixing --- README.md | 5 ++++- examples/light.rs | 3 +++ src/stack.rs | 8 +++++++- src/wifi/mgmt.rs | 11 ++++++----- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2e69b74..36dbdca 100644 --- a/README.md +++ b/README.md @@ -58,13 +58,16 @@ mod dev_att; fn main() -> Result<(), Error> { EspLogger::initialize_default(); + // We'll use `async-io` for networking, so ESP IDF VFS needs to be initialized + esp_idf_svc::io::vfs::initialize_eventfd(3)?; + info!("Starting..."); // Run in a higher-prio thread to avoid issues with `async-io` getting // confused by the low priority of the ESP IDF main task // Also allocate a large stack as `rs-matter` futures do occupy quite some space let thread = std::thread::Builder::new() - .stack_size(40 * 1024) + .stack_size(60 * 1024) .spawn(run) .unwrap(); diff --git a/examples/light.rs b/examples/light.rs index 06db701..f778389 100644 --- a/examples/light.rs +++ b/examples/light.rs @@ -37,6 +37,9 @@ mod dev_att; fn main() -> Result<(), Error> { EspLogger::initialize_default(); + // We'll use `async-io` for networking, so ESP IDF VFS needs to be initialized + esp_idf_svc::io::vfs::initialize_eventfd(3)?; + info!("Starting..."); // Run in a higher-prio thread to avoid issues with `async-io` getting diff --git a/src/stack.rs b/src/stack.rs index 957e89d..9e58f2c 100644 --- a/src/stack.rs +++ b/src/stack.rs @@ -302,6 +302,8 @@ mod wifible { use core::cell::RefCell; use core::pin::pin; + use alloc::boxed::Box; + use embassy_futures::select::select; use embassy_sync::blocking_mutex::raw::NoopRawMutex; use embassy_sync::mutex::Mutex; @@ -494,7 +496,11 @@ mod wifible { // Reset the matter transport to free up sessions and exchanges self.matter().reset(); - let mut wifi = EspWifi::new(&mut modem, sysloop.clone(), Some(nvs.clone()))?; + let mut wifi = Box::new(EspWifi::new( + &mut modem, + sysloop.clone(), + Some(nvs.clone()), + )?); info!("Wifi driver initialized"); diff --git a/src/wifi/mgmt.rs b/src/wifi/mgmt.rs index 565a8f8..97c03eb 100644 --- a/src/wifi/mgmt.rs +++ b/src/wifi/mgmt.rs @@ -15,8 +15,9 @@ use embassy_time::{Duration, Timer}; use esp_idf_svc::eventloop::EspSystemEventLoop; use esp_idf_svc::hal::task::embassy_sync::EspRawMutex; +use esp_idf_svc::handle::RawHandle; use esp_idf_svc::netif::EspNetif; -use esp_idf_svc::sys::{EspError, ESP_ERR_INVALID_STATE}; +use esp_idf_svc::sys::{esp, esp_netif_create_ip6_linklocal, EspError, ESP_ERR_INVALID_STATE}; use esp_idf_svc::wifi::{self as wifi, AsyncWifi, AuthMethod, EspWifi, WifiEvent}; use log::{error, info, warn}; @@ -124,9 +125,11 @@ where if result.is_ok() { info!("Connected to SSID {}", creds.ssid); + self.wait_disconnect().await?; } else { error!("Failed to connect to SSID {}: {:?}", creds.ssid, result); + break result; } } @@ -199,12 +202,9 @@ where let _ = wifi.stop().await; wifi.set_configuration(conf)?; - info!("Configuration set"); wifi.start().await?; - info!("Wifi driver started"); - let connect = matches!(conf, wifi::Configuration::Client(_)) && !matches!( conf, @@ -215,12 +215,13 @@ where ); if connect { - info!("Connecting..."); wifi.connect().await?; } info!("Successfully connected with {:?}", conf); + esp!(unsafe { esp_netif_create_ip6_linklocal(wifi.wifi().sta_netif().handle() as _) })?; + Ok(()) } }