1#![allow(missing_docs)]
2#![cfg(feature = "wifi")]
5#![no_std]
6#![no_main]
7#![allow(clippy::future_not_send, reason = "single-threaded")]
8
9extern crate defmt_rtt as _;
10extern crate panic_probe as _;
11
12use core::convert::Infallible;
13use device_envoy::{
14 Result,
15 button::PressedTo,
16 flash_array::FlashArray,
17 wifi_auto::{WifiAuto, WifiAutoEvent},
18};
19use embassy_net::dns::DnsQueryType;
20use embassy_time::{Duration, Timer};
21
22#[embassy_executor::main]
23async fn main(spawner: embassy_executor::Spawner) -> ! {
24 let err = inner_main(spawner).await.unwrap_err();
25 core::panic!("{err}");
26}
27
28async fn inner_main(spawner: embassy_executor::Spawner) -> Result<Infallible> {
29 let p = embassy_rp::init(Default::default());
30
31 let [wifi_flash] = FlashArray::<1>::new(p.FLASH)?;
32
33 let wifi_auto = WifiAuto::new(
34 p.PIN_23, p.PIN_24, p.PIN_25, p.PIN_29, p.PIO0, p.DMA_CH0, wifi_flash,
41 p.PIN_13, PressedTo::Ground,
43 "PicoAccess", [], spawner,
46 )?;
47
48 let (stack, _button) = wifi_auto
49 .connect(|event| async move {
50 match event {
51 WifiAutoEvent::CaptivePortalReady => {
52 defmt::info!("Captive portal ready");
53 }
54 WifiAutoEvent::Connecting { .. } => {
55 defmt::info!("Connecting to WiFi");
56 }
57 WifiAutoEvent::ConnectionFailed => {
58 defmt::info!("WiFi connection failed");
59 }
60 }
61 Ok(())
62 })
63 .await?;
64
65 defmt::info!("WiFi connected");
67
68 loop {
69 if let Ok(addresses) = stack.dns_query("google.com", DnsQueryType::A).await {
70 defmt::info!("google.com: {:?}", addresses);
71 } else {
72 defmt::info!("google.com: lookup failed");
73 }
74 Timer::after(Duration::from_secs(15)).await;
75 }
76}