Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
DanNixon committed Nov 25, 2023
1 parent 2384ec9 commit ae75035
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion satori/firmware/firmware/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn main() -> anyhow::Result<()> {
.expect("temperature sensor task should be spawned")
.spawn_local_collect(demo_koishi_telemetry(koishi_telemetry_uart), &mut tasks)
.expect("koishi telemetry task should be spawned")
.spawn_local_collect(wifi::task(wifi), &mut tasks)
.spawn_local_collect(wifi::task(wifi, led), &mut tasks)
.expect("wifi task should be spawned");
executor.run_tasks(move || !QUIT.triggered(), tasks);

Expand Down
30 changes: 22 additions & 8 deletions satori/firmware/firmware/src/wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use esp_idf_svc::{
nvs::EspDefaultNvsPartition,
wifi::{BlockingWifi, EspWifi},
};
use log::info;
use log::{warn, info};

pub(crate) fn setup(
ssid: &str,
Expand All @@ -20,7 +20,7 @@ pub(crate) fn setup(
EspWifi::new(modem, sysloop.clone(), Some(nvs)).expect("should have wifi"),
sysloop,
)
.expect("should have wifi");
.expect("should have wifi");

wifi.set_configuration(&Configuration::Client(ClientConfiguration::default()))
.expect("empty wifi config should be set");
Expand All @@ -39,19 +39,33 @@ pub(crate) fn setup(
Box::new(wifi)
}

pub(crate) async fn task(mut wifi: Box<BlockingWifi<EspWifi<'static>>>) {
pub(crate) async fn task(mut wifi: Box<BlockingWifi<EspWifi<'static>>>, led: crate::led::Led) {
let mut ticker = Ticker::every(Duration::from_secs(1));

loop {
info!("WiFi");

if !wifi.is_connected().unwrap() {
led.set(crate::led::RED);

info!("WiFi disconnected, connecting");
wifi.connect().unwrap();
if let Err(e) = wifi.connect() {
warn!("WiFi connect failed: {:?}", e);
continue;
}

info!("Waiting for network setup");
if let Err(e) = wifi.wait_netif_up() {
warn!("Network setup failed: {:?}", e);
continue;
}

info!("Waiting for DHCP lease");
wifi.wait_netif_up().unwrap();
led.set(crate::led::GREEN);

let ip_info = wifi.wifi().sta_netif().get_ip_info().unwrap();
info!("DHCP info: {:?}", ip_info);
match wifi.wifi().sta_netif().get_ip_info() {
Ok(info) => info!("DHCP info: {:?}", info),
Err(e) => warn!("Failed to get DHCP info: {:?}", e),
}
}

ticker.next().await;
Expand Down

0 comments on commit ae75035

Please sign in to comment.