From 8aeecf1bc90fceddb274832af5b06b5bff121a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1niel=20Buga?= Date: Mon, 16 Oct 2023 20:51:44 +0200 Subject: [PATCH] Update esp-wifi, tls and reqwless --- Cargo.toml | 15 ++++++++++++--- bad-server/Cargo.toml | 3 ++- bad-server/src/connector.rs | 2 +- bad-server/src/error_handler.rs | 2 +- bad-server/src/lib.rs | 14 ++++++-------- bad-server/src/request_body.rs | 8 ++++---- bad-server/src/response.rs | 4 ++-- src/board/wifi/ap.rs | 5 +---- src/board/wifi/mod.rs | 13 +------------ src/states/firmware_update.rs | 2 +- src/states/throughput.rs | 2 +- src/states/upload_or_store_measurement.rs | 2 +- 12 files changed, 33 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a214d3e8..bc59376e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,16 +11,17 @@ embedded-graphics = "0.8.0" embedded-hal = "1.0.0-rc.1" embedded-hal-async = "1.0.0-rc.1" embedded-hal-bus = { version = "0.1.0-rc.1", features = ["async"] } -embedded-nal-async = "0.4.0" +embedded-nal-async = "0.6.0" embedded-io = { version = "0.4", features = ["async"] } +embedded-io-new = { package = "embedded-io", version = "0.6" } +embedded-io-async = { version = "0.6" } embedded-menu = "0.5.2" embedded-svc = { version = "0.25", default-features = false } -embassy-net = { version = "0.1.0", features = [ +embassy-net = { version = "0.2.0", features = [ "nightly", "tcp", "dhcpv4", "dns", - "unstable-traits", "medium-ethernet", ] } embassy-sync = { version = "0.2.0" } @@ -56,6 +57,7 @@ embassy-executor = { workspace = true } embassy-time = { version = "0.1.3", features = ["nightly", "unstable-traits"] } embedded-hal-old = { package = "embedded-hal", version = "0.2.7" } +embedded-io-async = { workspace = true } # esp32s2-hal = { version = "0.10.0", optional = true, features = ["rt", "async", "embassy", "embassy-time-systick", "eh1"] } esp32s3-hal = { version = "0.12.0", optional = true, features = [ @@ -146,8 +148,15 @@ esp32s3-hal = { git = "https://github.com/esp-rs/esp-hal.git", rev = "44e968f7a8 # embedded-text = { git = "https://github.com/embedded-graphics/embedded-text.git" } # esp32s3-hal = { path = "../../esp-hal/esp32s3-hal" } # esp-hal-common = { path = "../../esp-hal/esp-hal-common" } +embedded-tls = { git = "https://github.com/drogue-iot/embedded-tls.git", branch = "old" } +reqwless = { git = "https://github.com/bugadani/reqwless.git", branch = "old" } +buffered-io = { git = "https://github.com/bugadani/buffered-io.git", branch = "old" } +embassy-time = { git = "https://github.com/bugadani/embassy.git", branch = "old" } +embassy-net = { git = "https://github.com/bugadani/embassy.git", branch = "old" } +embassy-net-driver = { git = "https://github.com/bugadani/embassy.git", branch = "old" } [patch.'https://github.com/esp-rs/esp-wifi.git'] +# esp-wifi = { git = "https://github.com/bugadani/esp-wifi.git", branch = "embassy" } esp-wifi = { path = "../esp-wifi/esp-wifi" } [features] diff --git a/bad-server/Cargo.toml b/bad-server/Cargo.toml index ef3bef3c..2949cdbb 100644 --- a/bad-server/Cargo.toml +++ b/bad-server/Cargo.toml @@ -9,7 +9,8 @@ edition = "2021" async-io = { version = "1", optional = true } defmt = { workspace = true, optional = true } embassy-net = { workspace = true, optional = true } -embedded-io = { workspace = true } +embedded-io-new = { workspace = true } +embedded-io-async = { workspace = true } embedded-svc = { workspace = true } heapless = { workspace = true, features = ["ufmt-impl"] } httparse = { version = "1.8", default-features = false } diff --git a/bad-server/src/connector.rs b/bad-server/src/connector.rs index 95460084..d1dab051 100644 --- a/bad-server/src/connector.rs +++ b/bad-server/src/connector.rs @@ -1,6 +1,6 @@ use core::fmt::Debug; -use embedded_io::asynch::{Read, Write}; +use embedded_io_async::{Read, Write}; pub trait Connection: Read + Write { #[cfg(feature = "defmt")] diff --git a/bad-server/src/error_handler.rs b/bad-server/src/error_handler.rs index 636b495d..89014ddb 100644 --- a/bad-server/src/error_handler.rs +++ b/bad-server/src/error_handler.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use embedded_io::asynch::Write; +use embedded_io_async::Write; use ufmt::uwrite; use crate::{ diff --git a/bad-server/src/lib.rs b/bad-server/src/lib.rs index a6b921c7..c11e127d 100644 --- a/bad-server/src/lib.rs +++ b/bad-server/src/lib.rs @@ -8,10 +8,8 @@ extern crate logger; use core::{fmt::Debug, marker::PhantomData}; -use embedded_io::{ - asynch::{Read, Write as _}, - Io, -}; +use embedded_io_async::{Read, Write as _}; +use embedded_io_new::ErrorType; use httparse::Status; use object_chain::{Chain, ChainElement, Link}; @@ -123,7 +121,7 @@ where } } -pub enum HandleError { +pub enum HandleError { Read(ReadError), Write(C::Error), TooManyHeaders, @@ -131,7 +129,7 @@ pub enum HandleError { RequestParse(httparse::Error), } -impl From> for HandleError { +impl From> for HandleError { fn from(value: ReadError) -> Self { HandleError::Read(value) } @@ -139,7 +137,7 @@ impl From> for HandleError { impl Debug for HandleError where - C: Io, + C: ErrorType, { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { match self { @@ -155,7 +153,7 @@ where #[cfg(feature = "defmt")] impl defmt::Format for HandleError where - C: Io, + C: ErrorType, C::Error: defmt::Format, { fn format(&self, f: defmt::Formatter) { diff --git a/bad-server/src/request_body.rs b/bad-server/src/request_body.rs index a86ce72a..b6c28571 100644 --- a/bad-server/src/request_body.rs +++ b/bad-server/src/request_body.rs @@ -1,4 +1,4 @@ -use embedded_io::{blocking::ReadExactError, Io}; +use embedded_io_new::{ErrorType, ReadExactError}; use httparse::Header; use crate::{connector::Connection, response::ResponseStatus}; @@ -185,7 +185,7 @@ impl<'buf, 's, C: Connection> ContentLengthReader<'buf, 's, C> { pub enum ReadError where - C: Io, + C: ErrorType, { Io(C::Error), Encoding, @@ -194,7 +194,7 @@ where impl core::fmt::Debug for ReadError where - C: Io, + C: ErrorType, { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { match self { @@ -208,7 +208,7 @@ where #[cfg(feature = "defmt")] impl defmt::Format for ReadError where - C: Io, + C: ErrorType, C::Error: defmt::Format, { fn format(&self, f: defmt::Formatter) { diff --git a/bad-server/src/response.rs b/bad-server/src/response.rs index 9e02d7cc..dd759bd5 100644 --- a/bad-server/src/response.rs +++ b/bad-server/src/response.rs @@ -1,6 +1,6 @@ use core::marker::PhantomData; -use embedded_io::Io; +use embedded_io_new::ErrorType; use httparse::Header; use ufmt::uwrite; @@ -131,7 +131,7 @@ impl<'s, C: Connection> Response<'s, C, Headers> { async fn send( socket: &mut C, header: Header<'_>, - ) -> Result<(), ::Error> { + ) -> Result<(), ::Error> { socket.write_all(header.name.as_bytes()).await?; socket.write_all(b": ").await?; socket.write_all(header.value).await?; diff --git a/src/board/wifi/ap.rs b/src/board/wifi/ap.rs index 6c50c4e3..b6c7a0ab 100644 --- a/src/board/wifi/ap.rs +++ b/src/board/wifi/ap.rs @@ -174,10 +174,7 @@ async fn ap_task( info!("Wifi started!"); loop { - if let WifiStackState::ApStart - | WifiStackState::ApStaConnected - | WifiStackState::ApStaDisconnected = esp_wifi::wifi::get_wifi_state() - { + if let WifiStackState::ApStart = esp_wifi::wifi::get_wifi_state() { let events = controller .wait_for_events( WifiEvent::ApStop diff --git a/src/board/wifi/mod.rs b/src/board/wifi/mod.rs index f494421c..3f5060d5 100644 --- a/src/board/wifi/mod.rs +++ b/src/board/wifi/mod.rs @@ -258,16 +258,5 @@ impl WifiDriver { #[cardio::task] async fn net_task(stack: Rc, mut task_control: TaskControlToken) { - task_control - .run_cancellable(|_| async { - select(stack.run(), async { - // HACK: force polling the interface in case some write operation doesn't wake it up - loop { - DelayTimer::after(Duration::from_secs(1)).await; - } - }) - .await; - unreachable!() - }) - .await; + task_control.run_cancellable(|_| stack.run()).await; } diff --git a/src/states/firmware_update.rs b/src/states/firmware_update.rs index acfdc7d3..f22da0b3 100644 --- a/src/states/firmware_update.rs +++ b/src/states/firmware_update.rs @@ -1,5 +1,5 @@ use embassy_time::{Duration, Instant}; -use embedded_io::asynch::Read; +use embedded_io_async::Read; use reqwless::{request::Method, response::Status}; use ufmt::uwrite; diff --git a/src/states/throughput.rs b/src/states/throughput.rs index 4ac11265..e7a7ec5c 100644 --- a/src/states/throughput.rs +++ b/src/states/throughput.rs @@ -1,6 +1,6 @@ use embassy_futures::select::{select, Either}; use embassy_time::{Duration, Instant}; -use embedded_io::asynch::Read; +use embedded_io_async::Read; use reqwless::{request::Method, response::Status}; use ufmt::{uwrite, uwriteln}; diff --git a/src/states/upload_or_store_measurement.rs b/src/states/upload_or_store_measurement.rs index bd20e18d..0b1b5436 100644 --- a/src/states/upload_or_store_measurement.rs +++ b/src/states/upload_or_store_measurement.rs @@ -335,7 +335,7 @@ impl RequestBody for MeasurementRef<'_> { Some(self.buffer.len() + 4) } - async fn write(&self, writer: &mut W) -> Result<(), W::Error> { + async fn write(&self, writer: &mut W) -> Result<(), W::Error> { writer.write_all(&self.version.to_le_bytes()).await?; writer.write_all(self.buffer).await?;