sta config mode
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user