enable ota_update webserver path again
take latest ota code from `develop` branch and apply to legacy branch
This commit is contained in:
@@ -30,59 +30,80 @@ use core::result::Result::Ok;
|
|||||||
use core::sync::atomic::{AtomicBool, Ordering};
|
use core::sync::atomic::{AtomicBool, Ordering};
|
||||||
use edge_http::io::server::{Connection, Handler, Server};
|
use edge_http::io::server::{Connection, Handler, Server};
|
||||||
use edge_http::Method;
|
use edge_http::Method;
|
||||||
use edge_nal::TcpBind;
|
|
||||||
use edge_nal::io::{Read, Write};
|
use edge_nal::io::{Read, Write};
|
||||||
|
use edge_nal::TcpBind;
|
||||||
use edge_nal_embassy::{Tcp, TcpBuffers};
|
use edge_nal_embassy::{Tcp, TcpBuffers};
|
||||||
use embassy_net::Stack;
|
use embassy_net::Stack;
|
||||||
use embassy_time::Instant;
|
use embassy_time::Instant;
|
||||||
use log::info;
|
use log::{error, info};
|
||||||
|
|
||||||
// fn ota(
|
pub(crate) async fn ota_operations<T, const N: usize>(
|
||||||
// request: &mut Request<&mut EspHttpConnection>,
|
conn: &mut Connection<'_, T, { N }>,
|
||||||
// ) -> Result<Option<std::string::String>, anyhow::Error> {
|
method: Method,
|
||||||
// let mut board = BOARD_ACCESS.lock().unwrap();
|
) -> Result<Option<u32>, FatError>
|
||||||
// let mut ota = OtaUpdate::begin()?;
|
where
|
||||||
// log::info!("start ota");
|
T: Read + Write,
|
||||||
//
|
{
|
||||||
// //having a larger buffer is not really faster, requires more stack and prevents the progress bar from working ;)
|
Ok(match method {
|
||||||
// const BUFFER_SIZE: usize = 512;
|
Method::Options => {
|
||||||
// let mut buffer: [u8; BUFFER_SIZE] = [0; BUFFER_SIZE];
|
conn.initiate_response(
|
||||||
// let mut total_read: usize = 0;
|
200,
|
||||||
// let mut lastiter = 0;
|
Some("OK"),
|
||||||
// loop {
|
&[
|
||||||
// let read = request.read(&mut buffer)?;
|
("Access-Control-Allow-Origin", "*"),
|
||||||
// total_read += read;
|
("Access-Control-Allow-Headers", "*"),
|
||||||
// let to_write = &buffer[0..read];
|
("Access-Control-Allow-Methods", "*"),
|
||||||
// //delay for watchdog and wifi stuff
|
],
|
||||||
// board.board_hal.get_esp().delay.delay_ms(1);
|
)
|
||||||
//
|
.await?;
|
||||||
// let iter = (total_read / 1024) % 8;
|
Some(200)
|
||||||
// if iter != lastiter {
|
}
|
||||||
// board.board_hal.general_fault(iter % 5 == 0);
|
Method::Post => {
|
||||||
// for i in 0..PLANT_COUNT {
|
let mut offset = 0_usize;
|
||||||
// let _ = board.board_hal.fault(i, iter == i);
|
let mut chunk = 0;
|
||||||
// }
|
loop {
|
||||||
// lastiter = iter;
|
let buf = read_up_to_bytes_from_request(conn, Some(4096)).await?;
|
||||||
// }
|
if buf.is_empty() {
|
||||||
//
|
info!("file request for ota finished");
|
||||||
// ota.write(to_write)?;
|
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||||
// if read == 0 {
|
board.board_hal.get_esp().finalize_ota().await?;
|
||||||
// break;
|
break;
|
||||||
// }
|
} else {
|
||||||
// }
|
let mut board = BOARD_ACCESS.get().await.lock().await;
|
||||||
// log::info!("wrote bytes ota {total_read}");
|
board.board_hal.progress(chunk as u32).await;
|
||||||
// log::info!("finish ota");
|
// Erase next block if we are at a 4K boundary (including the first block at offset 0)
|
||||||
// let partition = ota.raw_partition();
|
board
|
||||||
// log::info!("finalizing and changing boot partition to {partition:?}");
|
.board_hal
|
||||||
//
|
.get_esp()
|
||||||
// let mut finalizer = ota.finalize()?;
|
.write_ota(offset as u32, &buf)
|
||||||
// log::info!("changing boot partition");
|
.await?;
|
||||||
// board.board_hal.get_esp().set_restart_to_conf(true);
|
}
|
||||||
// drop(board);
|
offset += buf.len();
|
||||||
// finalizer.set_as_boot_partition()?;
|
chunk += 1;
|
||||||
// anyhow::Ok(None)
|
}
|
||||||
// }
|
BOARD_ACCESS
|
||||||
//
|
.get()
|
||||||
|
.await
|
||||||
|
.lock()
|
||||||
|
.await
|
||||||
|
.board_hal
|
||||||
|
.clear_progress()
|
||||||
|
.await;
|
||||||
|
conn.initiate_response(
|
||||||
|
200,
|
||||||
|
Some("OK"),
|
||||||
|
&[
|
||||||
|
("Access-Control-Allow-Origin", "*"),
|
||||||
|
("Access-Control-Allow-Headers", "*"),
|
||||||
|
("Access-Control-Allow-Methods", "*"),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
Some(200)
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
struct HTTPRequestRouter {
|
struct HTTPRequestRouter {
|
||||||
reboot_now: Arc<AtomicBool>,
|
reboot_now: Arc<AtomicBool>,
|
||||||
@@ -105,7 +126,12 @@ impl Handler for HTTPRequestRouter {
|
|||||||
let path = headers.path;
|
let path = headers.path;
|
||||||
|
|
||||||
let prefix = "/file?filename=";
|
let prefix = "/file?filename=";
|
||||||
let status = if path.starts_with(prefix) {
|
let status = if path == "/ota" {
|
||||||
|
ota_operations(conn, method).await.map_err(|e| {
|
||||||
|
error!("Error handling ota: {e}");
|
||||||
|
e
|
||||||
|
})?
|
||||||
|
} else if path.starts_with(prefix) {
|
||||||
file_operations(conn, method, &path, &prefix).await?
|
file_operations(conn, method, &path, &prefix).await?
|
||||||
} else {
|
} else {
|
||||||
match method {
|
match method {
|
||||||
|
|||||||
Reference in New Issue
Block a user