Update picoserve and send periodic ping to keep wifi connection active

This commit is contained in:
2025-01-23 00:14:58 +01:00
parent 03b6e01bd8
commit 7dee29b581
3 changed files with 47 additions and 13 deletions

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;
}
}