Skip to content

Commit

Permalink
Read config
Browse files Browse the repository at this point in the history
  • Loading branch information
fangpenlin committed Jan 7, 2025
1 parent b599789 commit 5bded28
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,11 @@ async fn run_async(spawner: LocalSpawner) -> Result<(), anyhow::Error> {
msc_device.install()?;

let peripherals = Peripherals::take()?;
let mut button = PinDriver::input(peripherals.pins.gpio14)?;
button.set_pull(Pull::Up)?;

let mut wifi: Option<WifiSession> = None;
let mut _wifi: Option<WifiSession> = None;
let mut _sntp: Option<EspSntp> = None;
if let Some(config) = &config {
let mut wifi = WifiSession::new(
&WifiConfig {
Expand All @@ -83,15 +86,13 @@ async fn run_async(spawner: LocalSpawner) -> Result<(), anyhow::Error> {
)?;
wifi.connect().await?;
log::info!("Connected wifi: {:#?}", wifi.get_ip_info());
_wifi = Some(wifi);

// Keep it around or else the SNTP service will stop
let _sntp = EspSntp::new_default()?;
_sntp = Some(EspSntp::new_default()?);
log::info!("SNTP initialized");

let mut button = PinDriver::input(peripherals.pins.gpio14)?;
button.set_pull(Pull::Up)?;

let mut client = WebSocketSession::new(API_ENDPOINT, Duration::from_secs(30));
let mut client = WebSocketSession::new(&config.api.endpoint, Duration::from_secs(30));

let captured_mount_path = mount_path.clone();
let mount_path_c_str = CString::new(mount_path.as_bytes())?;
Expand Down Expand Up @@ -119,7 +120,11 @@ async fn run_async(spawner: LocalSpawner) -> Result<(), anyhow::Error> {
button.wait_for_low().await?;
log::info!("Button pressed!");

spawner.spawn_local(process_events(client, device_info_producer, mount_path))?;
spawner.spawn_local(process_events(
client,
device_info_producer,
mount_path.to_string(),
))?;
}

loop {
Expand Down

0 comments on commit 5bded28

Please sign in to comment.