This commit is contained in:
Dimitris
2026-05-27 13:35:20 +02:00
parent 957e6541f5
commit b2310b0faa
2 changed files with 20 additions and 21 deletions
+17 -18
View File
@@ -24,10 +24,10 @@ use esp_hal::{
use esp_println::println;
// firebeetle
pub const PEER_ADDRESS: [u8; 6] = [0xd4u8, 0x8cu8, 0x49u8, 0xc9u8, 0x13u8, 0x14u8];
// pub const PEER_ADDRESS: [u8; 6] = [0xd4u8, 0x8cu8, 0x49u8, 0xc9u8, 0x13u8, 0x14u8];
// elecrow 5.79
// pub const PEER_ADDRESS: [u8; 6] = [0x48u8, 0xCAu8, 0x43u8, 0x99u8, 0x6Cu8, 0xACu8 ];
pub const PEER_ADDRESS: [u8; 6] = [0x48u8, 0xCAu8, 0x43u8, 0x99u8, 0x6Cu8, 0xACu8];
pub const HOME: &str = "FRITZ!Box 7590 FP DK";
@@ -45,7 +45,6 @@ use esp_radio::{
esp_bootloader_esp_idf::esp_app_desc!();
// When you are okay with using a nightly compiler it's better to use https://docs.rs/static_cell/2.1.0/static_cell/macro.make_static.html
macro_rules! mk_static {
($t:ty,$val:expr) => {{
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
@@ -55,9 +54,8 @@ macro_rules! mk_static {
}};
}
#[esp_hal::main]
#[esp_rtos::main]
async fn main(_spawner: Spawner) -> ! {
esp_println::logger::init_logger_from_env();
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
@@ -84,8 +82,6 @@ async fn main(_spawner: Spawner) -> ! {
esp_radio::wifi::new(peripherals.WIFI, Default::default()).unwrap()
);
// Not used
println!("Scan");
let mut ap_channel = 0;
let scan_config = ScanConfig::default().with_max(10);
let result = controller.scan_async(&scan_config).await.unwrap();
@@ -138,9 +134,7 @@ async fn main(_spawner: Spawner) -> ! {
let reason = reset_reason(Cpu::ProCpu);
let wake_reason = wakeup_cause();
println!("{:?} {:?}", reason, wake_reason);
let timer = TimerWakeupSource::new(core::time::Duration::from_secs(DEEP_SLEEP_TIME));
println!("{:?} {:?}", reason, wake_reason);
let mut ticker = Ticker::every(Duration::from_millis(200));
loop {
@@ -161,6 +155,7 @@ async fn main(_spawner: Spawner) -> ! {
}
Err(error) => {
esp_println::dbg!("An error occurred while trying to read sensor: {:?}", error);
deep_sleep(&mut rtc, &delay, 30);
}
}
@@ -175,17 +170,21 @@ async fn main(_spawner: Spawner) -> ! {
}
};
let string = String::from(temperature.to_string() + ";" + &humidity.to_string());
let fill = (0..(20-string.len())).map(|_| " ").collect::<String>();
println!("Send temperature to peer {:?}", peer.peer_address);
let data = String::from(temperature.to_string() + ";" + &humidity.to_string());
let fill = (0..(20 - data.len())).map(|_| " ").collect::<String>();
println!("Send {:?} to peer {:?}", data, peer.peer_address);
let mut sender = sender.lock().await;
let status = sender
.send_async(&peer.peer_address, (string + fill.as_str()).as_bytes())
.send_async(&peer.peer_address, (data + fill.as_str()).as_bytes())
.await;
println!("Send status: {:?}", status);
println!("Going sleep: {:?} for seconds", DEEP_SLEEP_TIME);
delay.delay_millis(100);
rtc.sleep_deep(&[&timer]);
deep_sleep(&mut rtc, &delay, DEEP_SLEEP_TIME);
}
}
fn deep_sleep(rtc: &mut Rtc, delay: &Delay, time : u64) {
let timer = TimerWakeupSource::new(core::time::Duration::from_secs(time));
println!("Going sleep for {} seconds", time);
delay.delay_millis(100);
rtc.sleep_deep(&[&timer]);
}