Skip to content

Commit

Permalink
Add methods to EspWifi to replace STA or AP netif discretely (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssnover authored Dec 8, 2023
1 parent d2d1dc4 commit d562655
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,30 @@ impl<'d> EspWifi<'d> {
Ok((old_sta, old_ap))
}

/// Replaces the STA network interface with the provided one and returns the
/// existing network interface.
pub fn swap_netif_sta(&mut self, sta_netif: EspNetif) -> Result<EspNetif, EspError> {
self.detach_netif()?;

let old = core::mem::replace(&mut self.sta_netif, sta_netif);

self.attach_netif()?;

Ok(old)
}

/// Replaces the AP network interface with the provided one and returns the
/// existing network interface.
pub fn swap_netif_ap(&mut self, ap_netif: EspNetif) -> Result<EspNetif, EspError> {
self.detach_netif()?;

let old = core::mem::replace(&mut self.ap_netif, ap_netif);

self.attach_netif()?;

Ok(old)
}

/// Returns the underlying [`WifiDriver`]
pub fn driver(&self) -> &WifiDriver<'d> {
&self.driver
Expand Down

0 comments on commit d562655

Please sign in to comment.