A RPi Pico powered Lightning Detector
1use embassy_net::tcp::TcpSocket;
2use sachy_fmt::{error, info};
3
4use crate::{
5 constants::HOST_PORT,
6 updates::{NetDataReceiver, UpdateConnection},
7};
8
9pub async fn rpc_loop<'device>(tcp: &mut TcpSocket<'device>, net_data: &NetDataReceiver) {
10 loop {
11 UpdateConnection::disconnect();
12
13 if tcp.accept(HOST_PORT).await.is_err() {
14 continue;
15 }
16
17 match super::noise::NoiseSession::initialize(tcp).await {
18 Ok(session) => {
19 info!("Connected!");
20 UpdateConnection::connect();
21
22 session.run(tcp).await;
23
24 net_data.clear();
25
26 info!("DISCONNECT");
27 }
28 Err(e) => error!("Session init failure: {}", e),
29 }
30
31 tcp.abort();
32 tcp.flush().await.ok();
33 }
34}