56 lines
1.6 KiB
Rust
56 lines
1.6 KiB
Rust
#![no_std]
|
|
#![no_main]
|
|
|
|
use embassy_executor::Spawner;
|
|
use embassy_time::Timer;
|
|
|
|
use esp_alloc as _;
|
|
use esp_backtrace as _;
|
|
use esp_hal::{
|
|
clock::CpuClock, interrupt::software::SoftwareInterruptControl, timer::timg::TimerGroup,
|
|
};
|
|
use esp_println::println;
|
|
use esp_radio::wifi::sta::StationConfig;
|
|
use esp_radio::wifi::{Config, ControllerConfig, scan::ScanConfig};
|
|
|
|
#[panic_handler]
|
|
fn panic(_: &core::panic::PanicInfo) -> ! {
|
|
loop {}
|
|
}
|
|
esp_bootloader_esp_idf::esp_app_desc!();
|
|
|
|
#[esp_rtos::main]
|
|
async fn main(_spawner: Spawner) -> ! {
|
|
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 timg0 = TimerGroup::new(peripherals.TIMG0);
|
|
let sw_int = SoftwareInterruptControl::new(peripherals.SW_INTERRUPT);
|
|
esp_rtos::start(timg0.timer0, sw_int.software_interrupt0);
|
|
|
|
let station_config = Config::Station(
|
|
StationConfig::default()
|
|
.with_ssid("ssid")
|
|
.with_password("password".into()),
|
|
);
|
|
|
|
println!("Starting wifi");
|
|
let (mut controller, _interfaces) = esp_radio::wifi::new(
|
|
peripherals.WIFI,
|
|
ControllerConfig::default().with_initial_config(station_config),
|
|
)
|
|
.unwrap();
|
|
println!("Wifi configured and started!");
|
|
|
|
loop {
|
|
println!("Scan");
|
|
let scan_config = ScanConfig::default().with_max(20);
|
|
let result = controller.scan_async(&scan_config).await.unwrap();
|
|
for ap in result {
|
|
println!("{:?}", ap);
|
|
}
|
|
Timer::after_millis(1000).await;
|
|
}
|
|
}
|