small adjustments

This commit is contained in:
2025-09-16 22:41:45 +02:00
parent 1c84cd00da
commit 8b938e7687
3 changed files with 38 additions and 20 deletions

View File

@@ -17,6 +17,7 @@ use embassy_net::tcp::TcpSocket;
use embassy_net::{IpListenEndpoint, Ipv4Cidr, Runner, Stack, StackResources, StaticConfigV4};
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
use embassy_sync::mutex::Mutex;
use embassy_sync::rwlock::TryLockError;
use embassy_time::{Duration, Instant, Timer};
use embedded_storage::nor_flash::ReadNorFlash;
use embedded_storage::Storage;
@@ -29,7 +30,7 @@ use esp_println::{print, println};
use esp_storage::FlashStorage;
use esp_wifi::wifi::{
AccessPointConfiguration, AccessPointInfo, Configuration, Interfaces, ScanConfig,
WifiController, WifiDevice, WifiEvent, WifiState,
ScanTypeConfig, WifiController, WifiDevice, WifiEvent, WifiState,
};
use log::{info, warn};
@@ -99,13 +100,7 @@ macro_rules! mk_static {
}};
}
static WIFI_CONTROLLER: static_cell::StaticCell<WifiController> = static_cell::StaticCell::new();
impl Esp<'_> {
const SPIFFS_PARTITION_NAME: &'static str = "storage";
const CONFIG_FILE: &'static str = "/spiffs/config.cfg";
const BASE_PATH: &'static str = "/spiffs";
pub(crate) fn get_ota_slot(&mut self) -> String {
match self.ota.current_slot() {
Ok(slot) => {
@@ -164,14 +159,26 @@ impl Esp<'_> {
DateTime::from_timestamp_millis(wall_clock as i64).unwrap()
}
pub(crate) async fn wifi_scan(&mut self) -> Vec<AccessPointInfo> {
pub(crate) async fn wifi_scan(&mut self) -> anyhow::Result<Vec<AccessPointInfo>> {
info!("start wifi scan");
let mut lock = self.controller.try_lock().unwrap();
let mut lock = self
.controller
.try_lock()
.map_err(|_| anyhow!("Could not lock wifi controller, currently in use"))?;
info!("start wifi scan lock");
let scan_config = ScanConfig::default();
let rv = lock.scan_with_config_sync(scan_config).unwrap();
let scan_config = ScanConfig {
ssid: None,
bssid: None,
channel: None,
show_hidden: false,
scan_type: ScanTypeConfig::Passive(core::time::Duration::from_secs(2)),
};
let rv = lock
.scan_with_config_async(scan_config)
.await
.map_err(|err| anyhow!("Could not scan wifi: {:?}", err))?;
info!("end wifi scan lock");
return rv;
Ok(rv)
}
pub(crate) fn last_pump_time(&self, plant: usize) -> Option<DateTime<Utc>> {
@@ -223,7 +230,7 @@ impl Esp<'_> {
let spawner = Spawner::for_current_executor().await;
let device = self.interfaces.take().unwrap().ap;
let gw_ip_addr_str = GW_IP_ADDR_ENV.unwrap_or("192.168.2.1");
let gw_ip_addr_str = "192.168.71.1";
let gw_ip_addr = Ipv4Addr::from_str(gw_ip_addr_str).expect("failed to parse gateway ip");
let config = embassy_net::Config::ipv4_static(StaticConfigV4 {