72 lines
2.4 KiB
Rust
72 lines
2.4 KiB
Rust
#![no_std]
|
|
#![no_main]
|
|
#![deny(
|
|
clippy::mem_forget,
|
|
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
|
|
holding buffers for the duration of a data transfer."
|
|
)]
|
|
|
|
use embassy_executor::Spawner;
|
|
use embassy_time::{Duration, Timer};
|
|
use esp_backtrace as _;
|
|
use esp_hal::clock::CpuClock;
|
|
use esp_hal::timer::timg::TimerGroup;
|
|
use log::info;
|
|
use esp_wifi::wifi::{ClientConfiguration, Configuration, WifiController};
|
|
|
|
extern crate alloc;
|
|
|
|
// This creates a default app-descriptor required by the esp-idf bootloader.
|
|
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
|
|
esp_bootloader_esp_idf::esp_app_desc!();
|
|
|
|
// Pull SSID/PASSWORD from .cargo/config.toml at compile time
|
|
const SSID: &str = env!("SSID");
|
|
const PASSWORD: &str = env!("PASSWORD");
|
|
|
|
#[esp_hal_embassy::main]
|
|
async fn main(spawner: Spawner) {
|
|
// generator version: 0.5.0
|
|
|
|
esp_println::logger::init_logger_from_env();
|
|
|
|
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
|
let peripherals = esp_hal::init(config);
|
|
|
|
esp_alloc::heap_allocator!(size: 64 * 1024);
|
|
|
|
let timer0 = TimerGroup::new(peripherals.TIMG1);
|
|
esp_hal_embassy::init(timer0.timer0);
|
|
|
|
info!("Embassy initialized!");
|
|
|
|
let rng = esp_hal::rng::Rng::new(peripherals.RNG);
|
|
let timer1 = TimerGroup::new(peripherals.TIMG0);
|
|
let wifi_init =
|
|
esp_wifi::init(timer1.timer0, rng).expect("Failed to initialize WIFI/BLE wifi_controller");
|
|
let (mut wifi_controller, interfaces) = esp_wifi::wifi::new(&wifi_init, peripherals.WIFI)
|
|
.expect("Failed to initialize WIFI wifi_controller");
|
|
|
|
let client_conf = Configuration::Client(ClientConfiguration {
|
|
ssid: SSID.try_into().unwrap(),
|
|
password: PASSWORD.try_into().unwrap(),
|
|
..Default::default()
|
|
});
|
|
wifi_controller.set_configuration(&client_conf).unwrap();
|
|
|
|
info!("Starting WiFi...");
|
|
wifi_controller.start_async().await.unwrap();
|
|
info!("WiFi started, connecting...");
|
|
|
|
match wifi_controller.connect_async().await {
|
|
Ok(_) => info!("Connected to WiFi!"),
|
|
Err(e) => info!("Failed to connect: {:?}", e),
|
|
}
|
|
|
|
loop {
|
|
Timer::after(Duration::from_millis(50)).await;
|
|
}
|
|
|
|
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0-rc.0/examples/src/bin
|
|
}
|