eculocate

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 671c2a382cc4b2a53803c1fe7509c3e96e84e50a
parent d79b32c8bfcdf9f580658a097525a7831f842a6a
Author: Daniel Barlow <dan@telent.net>
Date:   Wed,  4 Feb 2026 18:42:49 +0000

reset after configuring wifi, and if if doesn't work

Diffstat:
Mecu-esp32/src/wibble.rs | 5++++-
Mecu-esp32/src/wifi.rs | 49++++++++++++++++++++++++++++++++++++-------------
2 files changed, 40 insertions(+), 14 deletions(-)

diff --git a/ecu-esp32/src/wibble.rs b/ecu-esp32/src/wibble.rs @@ -1,4 +1,4 @@ -use embassy_time::Timer; +use embassy_time::{Duration,Timer}; use trouble_host::prelude::*; use esp_radio::ble::controller::BleConnector; use esp_radio::Controller as RadioController; @@ -146,6 +146,9 @@ async fn gatt_events_task<P: PacketPool>(server: &Server<'_>, if let Some(i) = n_s.find("\0") { i } else { n_s.len() }; flasher.set_var("ssid", Some(&n_s[..n0])); flasher.set_var("secret", Some(core::str::from_utf8(event.data()).unwrap())); + info!("[gatt] deep breath then reboot"); + Timer::after(Duration::from_millis(2000)).await; + esp_hal::system::software_reset(); } }, _ => {} diff --git a/ecu-esp32/src/wifi.rs b/ecu-esp32/src/wifi.rs @@ -35,6 +35,7 @@ use esp_radio::{ WifiDevice, WifiEvent, WifiStaState, + WifiError, AccessPointInfo }, }; @@ -136,9 +137,9 @@ pub async fn scan_networks(controller: &mut WifiController<'_>) -> Vec<AccessPoi } pub async fn start_wifi(spawner: &Spawner, - controller: WifiController<'static>, + mut controller: WifiController<'static>, wifi_interface: WifiDevice<'static>, - flasher: crate::ota::Flasher<'_>, + mut flasher: crate::ota::Flasher<'static>, ecu: &mut crate::ecu::Ecu<'_>) { let config = embassy_net::Config::dhcpv4(Default::default()); @@ -154,7 +155,15 @@ pub async fn start_wifi(spawner: &Spawner, seed, ); - spawner.spawn(connection(controller)).ok(); + if !connect(&mut controller).await.is_ok() { + flasher.set_var("ssid", None); + flasher.set_var("secret", None); + info!("[gatt] deep breath then reboot"); + Timer::after(Duration::from_millis(2000)).await; + esp_hal::system::software_reset(); + } + + spawner.spawn(maintain_connection(controller)).ok(); spawner.spawn(net_task(runner)).ok(); let my_address; @@ -198,9 +207,31 @@ pub async fn start_wifi(spawner: &Spawner, ).await; } +async fn connect(mut controller: &mut WifiController<'static>) -> Result<(), WifiError> { + let mut attempts = 0; + let mut retval = Ok(()); + println!("start connecting"); + while attempts < 5 { + println!("About to connect..."); + + match controller.connect_async().await { + Ok(_) => { + println!("Wifi connected!"); + return retval; + }, + Err(e) => { + println!("Failed to connect to wifi, attempt {attempts}: {e:?}"); + attempts += 1; + Timer::after(Duration::from_millis(1000)).await; + retval = Err(e); + } + } + } + retval +} #[embassy_executor::task] -async fn connection(mut controller: WifiController<'static>) { +async fn maintain_connection(mut controller: WifiController<'static>) { println!("start connection task"); println!("Device capabilities: {:?}", controller.capabilities()); loop { @@ -214,15 +245,7 @@ async fn connection(mut controller: WifiController<'static>) { } _ => {} } - println!("About to connect..."); - - match controller.connect_async().await { - Ok(_) => println!("Wifi connected!"), - Err(e) => { - println!("Failed to connect to wifi: {e:?}"); - Timer::after(Duration::from_millis(5000)).await - } - } + let _ = connect(&mut controller); } }