/ firmware / tests / access_point_connect.rs
access_point_connect.rs
 1  //! `describe("Access Point Connection")`
 2  //!
 3  //! Manual integration test. The device starts its WiFi access point;
 4  //! the test waits for an external client (the user's phone or laptop)
 5  //! to associate. Pass criterion: a station joins within the 5-minute
 6  //! `#[timeout]`. Failure: timeout, or the AP fails to come up.
 7  
 8  #![no_std]
 9  #![no_main]
10  
11  extern crate alloc;
12  
13  #[path = "common/mod.rs"]
14  mod common;
15  
16  use defmt::info;
17  
18  use common::{Device, tasks};
19  
20  esp_bootloader_esp_idf::esp_app_desc!();
21  
22  #[cfg(test)]
23  #[embedded_test::setup]
24  fn setup() {
25      rtt_target::rtt_init_defmt!();
26  }
27  
28  #[cfg(test)]
29  #[embedded_test::tests(default_timeout = 30, executor = esp_rtos::embassy::Executor::new())]
30  mod tests {
31      use super::*;
32  
33      #[init]
34      fn init() -> Device {
35          info!("=== Access Point Connection — describe block ===");
36          common::setup::boot_device()
37      }
38  
39      /// `it("user can connect their phone to the device access point")`
40      #[test]
41      #[timeout(300)]
42      async fn user_connects_their_phone_to_device_access_point(
43          mut device: Device,
44      ) -> Result<(), &'static str> {
45          // SAFETY: every embedded-test runs inside an `esp_rtos::embassy::Executor`,
46          // so the current async context is owned by an Embassy executor.
47          let embassy_spawner =
48              unsafe { embassy_executor::Spawner::for_current_executor() }.await;
49  
50          tasks::wifi::start_access_point(&mut device, embassy_spawner).await?;
51  
52          info!(">>> ACTION REQUIRED <<<");
53          info!(
54              ">>> Connect your phone or laptop to WiFi ssid={=str}",
55              tasks::wifi::DEFAULT_ACCESS_POINT_SSID
56          );
57          info!(
58              ">>> Password: {=str}",
59              tasks::wifi::DEFAULT_ACCESS_POINT_PASSWORD
60          );
61          info!(">>> Test will time out in 5 minutes if no client connects");
62  
63          tasks::wifi::wait_for_first_station(&mut device).await?;
64  
65          Ok(())
66      }
67  }