get most stuff working again, by upgrading to newer esp-hal version
this involved adding a lot of code from the develop branch step by step there are still some bugs, but at least i can get into the web interface and configure stuff again \o/ … measuring and pumping is working as well
This commit is contained in:
@@ -6,7 +6,7 @@ use alloc::format;
|
||||
use alloc::string::{String, ToString};
|
||||
use chrono::DateTime;
|
||||
use edge_http::io::server::Connection;
|
||||
use embedded_io_async::{Read, Write};
|
||||
use edge_nal::io::{Read, Write};
|
||||
use log::info;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use alloc::format;
|
||||
use alloc::string::String;
|
||||
use edge_http::io::server::Connection;
|
||||
use edge_http::Method;
|
||||
use embedded_io_async::{Read, Write};
|
||||
use edge_nal::io::{Read, Write};
|
||||
use log::info;
|
||||
|
||||
pub(crate) async fn list_files<T, const N: usize>(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::fat_error::{FatError, FatResult};
|
||||
use crate::hal::{esp_time, PLANT_COUNT};
|
||||
use crate::hal::PLANT_COUNT;
|
||||
use crate::log::LogMessage;
|
||||
use crate::plant_state::{MoistureSensorState, PlantState};
|
||||
use crate::tank::determine_tank_state;
|
||||
@@ -10,7 +10,8 @@ use alloc::vec::Vec;
|
||||
use chrono_tz::Tz;
|
||||
use core::str::FromStr;
|
||||
use edge_http::io::server::Connection;
|
||||
use embedded_io_async::{Read, Write};
|
||||
use edge_nal::io::{Read, Write};
|
||||
use log::info;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
@@ -139,13 +140,29 @@ pub(crate) async fn get_time<T, const N: usize>(
|
||||
) -> FatResult<Option<String>> {
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
let conf = board.board_hal.get_config();
|
||||
let tz = Tz::from_str(conf.timezone.as_ref().unwrap_or(&"Europe/Berlin".to_string()).as_str()).unwrap();
|
||||
let native = esp_time().await.with_timezone(&tz).to_rfc3339();
|
||||
|
||||
let tz: Tz = match conf.timezone.as_ref() {
|
||||
None => Tz::UTC,
|
||||
Some(tz_string) => match Tz::from_str(tz_string) {
|
||||
Ok(tz) => tz,
|
||||
Err(err) => {
|
||||
info!("failed parsing timezone {err}");
|
||||
Tz::UTC
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
let native = board
|
||||
.board_hal
|
||||
.get_time()
|
||||
.await
|
||||
.with_timezone(&tz)
|
||||
.to_rfc3339();
|
||||
|
||||
let rtc = match board.board_hal.get_rtc_module().get_rtc_time().await {
|
||||
Ok(time) => time.with_timezone(&tz).to_rfc3339(),
|
||||
Err(err) => {
|
||||
format!("Error getting time: {}", err)
|
||||
format!("Error getting time: {err}")
|
||||
}
|
||||
};
|
||||
|
||||
@@ -162,6 +179,6 @@ pub(crate) async fn get_log_localization_config<T, const N: usize>(
|
||||
_request: &mut Connection<'_, T, N>,
|
||||
) -> FatResult<Option<String>> {
|
||||
Ok(Some(serde_json::to_string(
|
||||
&LogMessage::to_log_localisation_config(),
|
||||
&LogMessage::log_localisation_config(),
|
||||
)?))
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::fat_error::FatResult;
|
||||
use crate::log::LOG_ACCESS;
|
||||
use edge_http::io::server::Connection;
|
||||
use embedded_io_async::{Read, Write};
|
||||
use edge_nal::io::{Read, Write};
|
||||
|
||||
pub(crate) async fn get_log<T, const N: usize>(
|
||||
conn: &mut Connection<'_, T, N>,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::fat_error::FatError;
|
||||
use edge_http::io::server::Connection;
|
||||
use embedded_io_async::{Read, Write};
|
||||
use edge_nal::io::{Read, Write};
|
||||
|
||||
pub(crate) async fn serve_favicon<T, const N: usize>(
|
||||
conn: &mut Connection<'_, T, { N }>,
|
||||
|
||||
@@ -31,10 +31,10 @@ use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use edge_http::io::server::{Connection, Handler, Server};
|
||||
use edge_http::Method;
|
||||
use edge_nal::TcpBind;
|
||||
use edge_nal::io::{Read, Write};
|
||||
use edge_nal_embassy::{Tcp, TcpBuffers};
|
||||
use embassy_net::Stack;
|
||||
use embassy_time::Instant;
|
||||
use embedded_io_async::{Read, Write};
|
||||
use log::info;
|
||||
|
||||
// fn ota(
|
||||
@@ -228,34 +228,6 @@ pub async fn http_server(reboot_now: Arc<AtomicBool>, stack: Stack<'static>) {
|
||||
info!("Webserver started and waiting for connections");
|
||||
|
||||
//TODO https if mbed_esp lands
|
||||
|
||||
// server
|
||||
// .fn_handler("/ota", Method::Post, |request| {
|
||||
// handle_error_to500(request, ota)
|
||||
// })
|
||||
// .unwrap();
|
||||
// server
|
||||
// .fn_handler("/ota", Method::Options, |request| {
|
||||
// cors_response(request, 200, "")
|
||||
// })
|
||||
// .unwrap();
|
||||
// let reboot_now_for_reboot = reboot_now.clone();
|
||||
// server
|
||||
// .fn_handler("/reboot", Method::Post, move |_| {
|
||||
// BOARD_ACCESS
|
||||
// .lock()
|
||||
// .unwrap()
|
||||
// .board_hal
|
||||
// .get_esp()
|
||||
// .set_restart_to_conf(true);
|
||||
// reboot_now_for_reboot.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||
// anyhow::Ok(())
|
||||
// })
|
||||
// .unwrap();
|
||||
//
|
||||
// unsafe { vTaskDelay(1) };
|
||||
//
|
||||
// server
|
||||
}
|
||||
|
||||
async fn handle_json<'a, T, const N: usize>(
|
||||
@@ -264,7 +236,7 @@ async fn handle_json<'a, T, const N: usize>(
|
||||
) -> FatResult<u32>
|
||||
where
|
||||
T: Read + Write,
|
||||
<T as embedded_io_async::ErrorType>::Error: Debug,
|
||||
<T as edge_nal::io::ErrorType>::Error: Debug,
|
||||
{
|
||||
match chain {
|
||||
Ok(answer) => match answer {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
use crate::config::PlantControllerConfig;
|
||||
use crate::fat_error::FatResult;
|
||||
use crate::hal::esp_set_time;
|
||||
use crate::webserver::read_up_to_bytes_from_request;
|
||||
use crate::{do_secure_pump, BOARD_ACCESS};
|
||||
use alloc::borrow::ToOwned;
|
||||
use alloc::string::{String, ToString};
|
||||
use alloc::vec::Vec;
|
||||
use chrono::DateTime;
|
||||
use edge_http::io::server::Connection;
|
||||
use embedded_io_async::{Read, Write};
|
||||
use edge_nal::io::{Read, Write};
|
||||
use esp_radio::wifi::ap::AccessPointInfo;
|
||||
use log::info;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -35,10 +36,10 @@ pub(crate) async fn wifi_scan<T, const N: usize>(
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
info!("start wifi scan");
|
||||
let mut ssids: Vec<String> = Vec::new();
|
||||
let scan_result = board.board_hal.get_esp().wifi_scan().await?;
|
||||
let scan_result: Vec<AccessPointInfo> = board.board_hal.get_esp().wifi_scan().await?;
|
||||
scan_result
|
||||
.iter()
|
||||
.for_each(|s| ssids.push(s.ssid.to_string()));
|
||||
.for_each(|s| ssids.push(s.ssid.as_str().to_owned()));
|
||||
let ssid_json = serde_json::to_string(&SSIDList { ssids })?;
|
||||
info!("Sending ssid list {}", &ssid_json);
|
||||
Ok(Some(ssid_json))
|
||||
@@ -89,8 +90,9 @@ where
|
||||
{
|
||||
let actual_data = read_up_to_bytes_from_request(request, None).await?;
|
||||
let time: SetTime = serde_json::from_slice(&actual_data)?;
|
||||
let parsed = DateTime::parse_from_rfc3339(time.time).unwrap();
|
||||
esp_set_time(parsed).await?;
|
||||
let parsed = DateTime::parse_from_rfc3339(time.time)?;
|
||||
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||
board.board_hal.set_time(&parsed).await?;
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user