Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WiFi Easy Connect (DPP) wrappers and associated example #228

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
wifi_dpp: Reworked to not use std and generally simplified code
  • Loading branch information
jasta committed Mar 2, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 96f80ae4b59f0b0d7ac24bd1ce9b22319264ed7c
39 changes: 39 additions & 0 deletions src/private/waitable.rs
Original file line number Diff line number Diff line change
@@ -58,6 +58,22 @@ where
}
}

pub fn wait_while_and_get_mut<Q>(
&self,
condition: impl Fn(&T) -> bool,
getter: impl Fn(&mut T) -> Q,
) -> Q {
let mut state = self.state.lock();

loop {
if !condition(&state) {
return getter(&mut state);
}

state = self.cvar.wait(state);
}
}

pub fn wait_timeout_while_and_get<Q>(
&self,
dur: Duration,
@@ -80,4 +96,27 @@ where
}
}
}

pub fn wait_timeout_while_and_get_mut<Q>(
&self,
dur: Duration,
condition: impl Fn(&T) -> bool,
getter: impl Fn(&mut T) -> Q,
) -> (bool, Q) {
let mut state = self.state.lock();

loop {
if !condition(&state) {
return (false, getter(&mut state));
}

let (new_state, timeout) = self.cvar.wait_timeout(state, dur);

state = new_state;

if timeout {
return (true, getter(&mut state));
}
}
}
}
23 changes: 23 additions & 0 deletions src/wifi.rs
Original file line number Diff line number Diff line change
@@ -31,6 +31,13 @@ use crate::private::cstr::*;
use crate::private::mutex;
use crate::private::waitable::*;

#[cfg(all(
feature = "alloc",
esp_idf_comp_wpa_supplicant_enabled,
any(esp_idf_esp_wifi_dpp_support, esp_idf_wpa_dpp_support)
))]
use crate::wifi_dpp::{EspWifiDpp, QrCode};

pub mod config {
use core::time::Duration;

@@ -1122,6 +1129,22 @@ impl<'d> EspWifi<'d> {

Ok(())
}

/// Generate a QR code that can be used with a Wi-Fi Easy Connect compatible
/// configurator (e.g. a smart phone) to provision the MCU.
#[cfg(all(
feature = "alloc",
esp_idf_comp_wpa_supplicant_enabled,
any(esp_idf_esp_wifi_dpp_support, esp_idf_wpa_dpp_support)
))]
pub fn dpp_generate_qrcode(
&mut self,
channels: &[u8],
key: Option<&[u8; 32]>,
associated_data: Option<&[u8]>
) -> Result<EspWifiDpp<'_, 'd, QrCode>, EspError> {
EspWifiDpp::generate_qrcode(self, channels, key, associated_data)
}
}

#[cfg(esp_idf_comp_esp_netif_enabled)]
Loading