Skip to content

Commit

Permalink
refactor wifi.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
indexds committed Dec 24, 2024
1 parent d48c566 commit d61bc98
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/network/bridge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

25 changes: 11 additions & 14 deletions src/network/wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ use std::sync::{Arc, Mutex};

use esp_idf_svc::eventloop::EspSystemEventLoop;
use esp_idf_svc::hal::modem::Modem;
// use esp_idf_svc::ipv4::{
// ClientConfiguration as IpClientConfiguration,
// ClientSettings as IpClientSettings,
// Configuration as IpConfiguration,
// Ipv4Addr,
// Mask,
// Subnet,
// };
use esp_idf_svc::netif::{EspNetif, NetifConfiguration, NetifStack};
use esp_idf_svc::nvs::{EspDefaultNvsPartition, EspNvs, NvsDefault};
use esp_idf_svc::wifi::{AuthMethod, ClientConfiguration, Configuration, EspWifi, WifiDriver};
Expand All @@ -22,7 +14,8 @@ pub fn init_netif(
sysloop: EspSystemEventLoop,
nvs: EspDefaultNvsPartition,
) -> anyhow::Result<Arc<Mutex<EspWifi<'static>>>> {
log::warn!("Installing wifi netif...");
log::info!("Installing wifi netif...");

let wifi_driver = WifiDriver::new(modem, sysloop.clone(), Some(nvs.clone()))?;

let wifi_netif = EspWifi::wrap_all(
Expand All @@ -33,15 +26,16 @@ pub fn init_netif(
})?,
)?;

log::warn!("Wifi netif install success!");
log::info!("Installed wifi netif!");

Ok(Arc::new(Mutex::new(wifi_netif)))
}

pub fn set_configuration(
nvs_config: Arc<Mutex<EspNvs<NvsDefault>>>,
wifi_netif: Arc<Mutex<EspWifi<'static>>>,
) -> anyhow::Result<()> {
log::warn!("Setting wifi configuration...");
log::info!("Setting wifi configuration...");

let mut wifi_netif = wifi_netif.lock().unwrap();
let nvs = nvs_config.lock().unwrap();
Expand All @@ -60,13 +54,15 @@ pub fn set_configuration(
});

wifi_netif.set_configuration(&wifi_config)?;
log::warn!("Wifi configuration set!");

log::info!("Wifi configuration set!");

Ok(())
}

pub fn connect(wifi_netif: Arc<Mutex<EspWifi<'static>>>) -> anyhow::Result<()> {
log::warn!("Connecting to AP!");
log::info!("Connecting to access point..");

let mut wifi = wifi_netif.lock().unwrap();

if !wifi.is_started()? {
Expand All @@ -83,7 +79,8 @@ pub fn connect(wifi_netif: Arc<Mutex<EspWifi<'static>>>) -> anyhow::Result<()> {
}

pub fn disconnect(wifi_netif: Arc<Mutex<EspWifi<'static>>>) -> anyhow::Result<()> {
log::warn!("Disconnecting from AP!");
log::warn!("Disconnecting from access point..");

let mut wifi = wifi_netif.lock().unwrap();

if !wifi.is_started()? {
Expand Down
2 changes: 1 addition & 1 deletion src/ota/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
//!todo
//! todo

0 comments on commit d61bc98

Please sign in to comment.