reset after configuring wifi, and if if doesn't work
This commit is contained in:
@@ -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();
|
||||
}
|
||||
},
|
||||
_ => {}
|
||||
|
||||
+36
-13
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user