40
lib/wifi/examples/wifi.rs
Normal file
40
lib/wifi/examples/wifi.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
use anyhow::{bail, Result};
|
||||
use esp_idf_svc::{eventloop::EspSystemEventLoop, hal::prelude::Peripherals};
|
||||
use wifi::wifi;
|
||||
|
||||
/// This configuration is picked up at compile time by `build.rs` from the
|
||||
/// file `cfg.toml`.
|
||||
#[toml_cfg::toml_config]
|
||||
pub struct Config {
|
||||
#[default("")]
|
||||
wifi_ssid: &'static str,
|
||||
#[default("")]
|
||||
wifi_psk: &'static str,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
esp_idf_svc::sys::link_patches();
|
||||
esp_idf_svc::log::EspLogger::initialize_default();
|
||||
|
||||
let peripherals = Peripherals::take().unwrap();
|
||||
let sysloop = EspSystemEventLoop::take()?;
|
||||
|
||||
let app_config = CONFIG;
|
||||
// Connect to the Wi-Fi network
|
||||
let _wifi = match wifi(
|
||||
app_config.wifi_ssid,
|
||||
app_config.wifi_psk,
|
||||
peripherals.modem,
|
||||
sysloop,
|
||||
) {
|
||||
Ok(inner) => {
|
||||
println!("Connected to Wi-Fi network!");
|
||||
inner
|
||||
}
|
||||
Err(err) => {
|
||||
// Red!
|
||||
bail!("Could not connect to Wi-Fi network: {:?}", err)
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
Reference in New Issue
Block a user