esp sa teraz pripaja na wifi
This commit is contained in:
@@ -12,6 +12,7 @@ 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;
|
||||
|
||||
@@ -19,6 +20,10 @@ extern crate alloc;
|
||||
// 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
|
||||
@@ -39,15 +44,28 @@ async fn main(spawner: Spawner) {
|
||||
let timer1 = TimerGroup::new(peripherals.TIMG0);
|
||||
let wifi_init =
|
||||
esp_wifi::init(timer1.timer0, rng).expect("Failed to initialize WIFI/BLE controller");
|
||||
let (mut _wifi_controller, _interfaces) = esp_wifi::wifi::new(&wifi_init, peripherals.WIFI)
|
||||
let (mut controller, _interfaces) = esp_wifi::wifi::new(&wifi_init, peripherals.WIFI)
|
||||
.expect("Failed to initialize WIFI controller");
|
||||
|
||||
// TODO: Spawn some tasks
|
||||
let _ = spawner;
|
||||
let client_conf = Configuration::Client(ClientConfiguration {
|
||||
ssid: SSID.try_into().unwrap(),
|
||||
password: PASSWORD.try_into().unwrap(),
|
||||
..Default::default()
|
||||
});
|
||||
controller.set_configuration(&client_conf).unwrap();
|
||||
|
||||
info!("Starting WiFi...");
|
||||
controller.start_async().await.unwrap();
|
||||
info!("WiFi started, connecting...");
|
||||
|
||||
match controller.connect_async().await {
|
||||
Ok(_) => info!("Connected to WiFi!"),
|
||||
Err(e) => info!("Failed to connect: {:?}", e),
|
||||
}
|
||||
|
||||
// keep task alive
|
||||
loop {
|
||||
info!("Hello world!");
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
Timer::after(Duration::from_secs(5)).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
|
||||
|
||||
Reference in New Issue
Block a user