Update picoserve and send periodic ping to keep wifi connection active

This commit is contained in:
Dreaded_X 2025-01-23 00:14:58 +01:00
parent 03b6e01bd8
commit 7dee29b581
Signed by: Dreaded_X
GPG Key ID: 5A0CBFE3C3377FAA
3 changed files with 47 additions and 13 deletions

24
Cargo.lock generated
View File

@ -13,7 +13,7 @@ dependencies = [
[[package]]
name = "air_filter"
version = "0.4.4"
version = "0.4.5"
dependencies = [
"air_filter_types",
"bme280",
@ -1294,8 +1294,9 @@ dependencies = [
[[package]]
name = "picoserve"
version = "0.13.3"
source = "git+https://github.com/hodasemi/picoserve#c4fe40eccfcd1188f117d4b7c689f6dc48c94d44"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d2c9a99cfe7a070728554f1d42f62067937ce30f9b057a6b507e0cc14fe96e9"
dependencies = [
"const-sha1",
"data-encoding",
@ -1306,9 +1307,22 @@ dependencies = [
"futures-util",
"heapless",
"lhash",
"picoserve_derive",
"ryu",
"serde",
"serde-json-core",
"thiserror 2.0.11",
]
[[package]]
name = "picoserve_derive"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62ba0d83906d0357fedd23de7c5e3a5235342c248cc1d954d43d5e7b455c375c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.96",
]
[[package]]
@ -1899,8 +1913,8 @@ checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "updater"
version = "0.2.0"
source = "git+https://git.huizinga.dev/Dreaded_X/iot_tools?tag=v0.2.0#ce96dd0a4ef3cffe1c6be6786b0a47cdb412f861"
version = "0.3.0"
source = "git+https://git.huizinga.dev/Dreaded_X/iot_tools?tag=v0.3.0#b8e543b97261ba358b14c8088e55e6425a13c8a8"
dependencies = [
"cortex-m",
"defmt",

View File

@ -1,6 +1,6 @@
[package]
name = "air_filter"
version = "0.4.4"
version = "0.4.5"
edition = "2021"
[workspace.dependencies]
@ -73,16 +73,15 @@ nourl = { version = "0.1", features = ["defmt"] }
smoltcp = { version = "0.12", default-features = false, features = [
"dns-max-server-count-4",
] }
updater = { git = "https://git.huizinga.dev/Dreaded_X/iot_tools", tag = "v0.2.0" }
updater = { git = "https://git.huizinga.dev/Dreaded_X/iot_tools", tag = "v0.3.0" }
portable-atomic = { version = "1.6", features = ["critical-section"] }
bme280 = { workspace = true }
picoserve = { version = "0.13.3", features = ["defmt", "embassy"] }
picoserve = { version = "0.14", features = ["defmt", "embassy"] }
embedded-storage = "0.3"
[patch.crates-io]
# Make mqtt:// and mqtts:// actually work
nourl = { git = "https://git.huizinga.dev/Dreaded_X/nourl" }
picoserve = { git = "https://github.com/hodasemi/picoserve" }
[features]
include_firmwares = []

View File

@ -3,7 +3,7 @@
#![feature(impl_trait_in_assoc_type)]
#![feature(type_alias_impl_trait)]
use core::{cell::RefCell, str::FromStr};
use core::{cell::RefCell, net::Ipv4Addr, str::FromStr};
use approuter::{AppRouter, AppState};
use bme280::i2c::AsyncBME280;
@ -13,7 +13,7 @@ use defmt::{debug, info, warn};
use embassy_boot::{AlignedBuffer, BlockingFirmwareUpdater, FirmwareUpdaterConfig};
use embassy_embedded_hal::flash::partition::BlockingPartition;
use embassy_executor::Spawner;
use embassy_net::{Config, DhcpConfig, Stack, StackResources};
use embassy_net::{tcp::TcpSocket, Config, DhcpConfig, Stack, StackResources};
use embassy_rp::{
bind_interrupts,
clocks::RoscRng,
@ -371,6 +371,14 @@ async fn web_task(
.await;
}
#[embassy_executor::task]
async fn controller_task(state: AppState) {
loop {
state.shared_controller.0.lock().await.check_for_manual();
Timer::after(Duration::from_millis(500)).await;
}
}
#[embassy_executor::main]
async fn main(spawner: Spawner) {
info!("Starting...");
@ -489,8 +497,21 @@ async fn main(spawner: Spawner) {
spawner.must_spawn(web_task(id, stack, app, config, state.clone()));
}
spawner.must_spawn(controller_task(state));
let mut rx_buffer = [0; 4096];
let mut tx_buffer = [0; 4096];
loop {
state.shared_controller.0.lock().await.check_for_manual();
Timer::after(Duration::from_millis(500)).await;
// TODO: In the future, use reqless to push the current state to automation_rs
control.gpio_set(0, true).await;
let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);
socket.set_timeout(Some(Duration::from_secs(1)));
socket
.connect(("10.0.0.2".parse::<Ipv4Addr>().unwrap(), 80))
.await
.ok();
control.gpio_set(0, false).await;
Timer::after(Duration::from_secs(60)).await;
}
}