Skip to content

Commit

Permalink
Bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed May 1, 2024
1 parent 6fb14ee commit 931e248
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions examples/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down
11 changes: 6 additions & 5 deletions src/wifi/mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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,
Expand All @@ -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(())
}
}

0 comments on commit 931e248

Please sign in to comment.