small adjustments
This commit is contained in:
parent
1c84cd00da
commit
8b938e7687
@ -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 {
|
||||
|
@ -44,6 +44,7 @@ use esp_hal::rng::Rng;
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use esp_storage::FlashStorage;
|
||||
use esp_wifi::{init, EspWifiController};
|
||||
use littlefs2::fs::Filesystem;
|
||||
|
||||
//Only support for 8 right now!
|
||||
pub const PLANT_COUNT: usize = 8;
|
||||
@ -274,12 +275,21 @@ impl PlantHal {
|
||||
};
|
||||
|
||||
let ota_next = mk_static!(PartitionEntry, ota_partition);
|
||||
let storage_ota_next = mk_static!(FlashStorage, FlashStorage::new());
|
||||
let ota_next = mk_static!(
|
||||
FlashRegion<FlashStorage>,
|
||||
ota_next.as_embedded_storage(storage_ota_next)
|
||||
ota_next.as_embedded_storage(storage_ota)
|
||||
);
|
||||
|
||||
let data_partition = pt
|
||||
.find_partition(esp_bootloader_esp_idf::partitions::PartitionType::Data(
|
||||
DataPartitionSubType::LittleFs,
|
||||
))?
|
||||
.unwrap();
|
||||
|
||||
let mut data = data_partition.as_embedded_storage(storage_ota);
|
||||
let mut alloc = Filesystem::allocate();
|
||||
let mut fs = Filesystem::mount(&mut alloc, &mut data).unwrap();
|
||||
|
||||
let mut esp = Esp {
|
||||
rng,
|
||||
controller: Arc::new(Mutex::new(controller)),
|
||||
|
@ -434,11 +434,12 @@ async fn wifi_scan<T, const N: usize>(
|
||||
) -> Result<Option<String>, anyhow::Error> {
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
info!("start wifi scan");
|
||||
let scan_result = board.board_hal.get_esp().wifi_scan().await;
|
||||
//let scan_result = board.board_hal.get_esp().wifi_scan().await?
|
||||
//FIXME currently panics
|
||||
let mut ssids: Vec<String> = Vec::new();
|
||||
scan_result
|
||||
.iter()
|
||||
.for_each(|s| ssids.push(s.ssid.to_string()));
|
||||
//scan_result
|
||||
//.iter()
|
||||
//.for_each(|s| ssids.push(s.ssid.to_string()));
|
||||
let ssid_json = serde_json::to_string(&SSIDList { ssids })?;
|
||||
info!("Sending ssid list {}", &ssid_json);
|
||||
anyhow::Ok(Some(ssid_json))
|
||||
@ -532,7 +533,7 @@ pub async fn httpd(reboot_now: Arc<AtomicBool>, stack: Stack<'static>) {
|
||||
let buffer: TcpBuffers<2, 1024, 1024> = TcpBuffers::new();
|
||||
let tcp = Tcp::new(stack, &buffer);
|
||||
let acceptor = tcp
|
||||
.bind(SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 8080))
|
||||
.bind(SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 80))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user