sta config mode

This commit is contained in:
2025-09-26 01:13:08 +02:00
parent 6d5bb5b966
commit 7fc8d0c882
3 changed files with 16 additions and 12 deletions

View File

@@ -146,6 +146,7 @@ deranged = "0.5.3"
embassy-embedded-hal = "0.5.0"
bincode = { version = "2.0.1", default-features = false, features = ["derive"] }
sntpc = { version = "0.6.0", default-features = false, features = ["log", "embassy-socket", "embassy-socket-ipv6"] }
option-lock = { version = "0.3.1", default-features = false }
[patch.crates-io]
#bq34z100 = { path = "../../bq34z100_rust" }

View File

@@ -307,7 +307,10 @@ impl Esp<'_> {
bssid: None,
channel: None,
show_hidden: false,
scan_type: ScanTypeConfig::Passive(core::time::Duration::from_secs(2)),
scan_type: ScanTypeConfig::Active {
min: Default::default(),
max: Default::default(),
},
};
let rv = lock.scan_with_config_async(scan_config).await?;
info!("end wifi scan lock");
@@ -499,6 +502,7 @@ impl Esp<'_> {
}
Timer::after(Duration::from_millis(500)).await;
}
let timeout = TIME_ACCESS.get().await.current_time_us() + max_wait as u64 * 1000;
loop {
let state = esp_wifi::wifi::sta_state();
println!("waiting wifi sta connected {:?}", state);
@@ -518,6 +522,7 @@ impl Esp<'_> {
}
Timer::after(Duration::from_millis(500)).await;
}
let timeout = TIME_ACCESS.get().await.current_time_us() + max_wait as u64 * 1000;
while !stack.is_link_up() {
if TIME_ACCESS.get().await.current_time_us() > timeout {
bail!("Timeout waiting for wifi link up")
@@ -525,6 +530,7 @@ impl Esp<'_> {
println!("waiting for wifi link up");
Timer::after(Duration::from_millis(500)).await;
}
let timeout = TIME_ACCESS.get().await.current_time_us() + max_wait as u64 * 1000;
while !stack.is_config_up() {
if TIME_ACCESS.get().await.current_time_us() > timeout {
bail!("Timeout waiting for wifi config up")

View File

@@ -22,7 +22,7 @@ use crate::{
config::BoardVersion::INITIAL,
hal::{PlantHal, HAL, PLANT_COUNT},
};
use ::log::{info, warn};
use ::log::{error, info, warn};
use alloc::borrow::ToOwned;
use alloc::string::{String, ToString};
use alloc::sync::Arc;
@@ -41,6 +41,7 @@ use esp_hal::system::software_reset;
use esp_println::{logger, println};
use hal::battery::BatteryState;
use log::LogMessage;
use option_lock::OptionLock;
use plant_state::PlantState;
use serde::{Deserialize, Serialize};
use smoltcp::socket::udp::PacketMetadata;
@@ -242,9 +243,9 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
wait_infinity(board, WaitType::MissingConfig, reboot_now.clone()).await;
}
let mut stack = Option::None;
let mut stack: OptionLock<Stack> = OptionLock::empty();
let network_mode = if board.board_hal.get_config().network.ssid.is_some() {
try_connect_wifi_sntp_mqtt(&mut board, *&mut stack).await
try_connect_wifi_sntp_mqtt(&mut board, &mut stack).await
} else {
info!("No wifi configured");
//the current sensors require this amount to stabilize, in case of wifi this is already handles for sure;
@@ -261,7 +262,7 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
};
match res {
Ok(ap_stack) => {
stack = Some(ap_stack);
stack.replace(ap_stack);
info!("Started ap, continuing")
}
Err(err) => info!("Could not start config override ap mode due to {}", err),
@@ -317,7 +318,7 @@ async fn safe_main(spawner: Spawner) -> FatResult<()> {
info!("executing config mode override");
//config upload will trigger reboot!
let reboot_now = Arc::new(AtomicBool::new(false));
spawner.spawn(httpd(reboot_now.clone(), stack.unwrap()))?;
spawner.spawn(httpd(reboot_now.clone(), stack.take().unwrap()))?;
wait_infinity(board, WaitType::ConfigButton, reboot_now.clone()).await;
} else {
LOG_ACCESS
@@ -884,12 +885,12 @@ async fn publish_firmware_info(
async fn try_connect_wifi_sntp_mqtt(
board: &mut MutexGuard<'static, CriticalSectionRawMutex, HAL<'static>>,
mut stack_store: Option<Stack<'_>>,
mut stack_store: &mut OptionLock<Stack<'static>>,
) -> NetworkMode {
let nw_conf = &board.board_hal.get_config().network.clone();
match board.board_hal.get_esp().wifi(nw_conf).await {
Ok(stack) => {
stack_store = Some(stack.clone());
stack_store.replace(stack);
let sntp_mode: SntpMode = match board
.board_hal
@@ -909,10 +910,6 @@ async fn try_connect_wifi_sntp_mqtt(
}
};
loop {
println!("wifi stuff");
Timer::after_millis(1000).await;
}
let mqtt_connected = if board.board_hal.get_config().network.mqtt_url.is_some() {
let nw_config = &board.board_hal.get_config().network.clone();
match board.board_hal.get_esp().mqtt(nw_config).await {