Rust
This commit is contained in:
+3
-3
@@ -36,11 +36,11 @@ esp32 = [
|
|||||||
"esp-radio/esp32",
|
"esp-radio/esp32",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
debug = true
|
debug = false
|
||||||
debug-assertions = true
|
debug-assertions = false
|
||||||
lto = "fat"
|
lto = "fat"
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|
||||||
|
|
||||||
# cargo xtask run example esp_now_slave --chip=esp32
|
# cargo xtask run example esp_now_slave --chip=esp32
|
||||||
+17
-18
@@ -24,10 +24,10 @@ use esp_hal::{
|
|||||||
use esp_println::println;
|
use esp_println::println;
|
||||||
|
|
||||||
// firebeetle
|
// 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
|
// 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";
|
pub const HOME: &str = "FRITZ!Box 7590 FP DK";
|
||||||
|
|
||||||
@@ -45,7 +45,6 @@ use esp_radio::{
|
|||||||
|
|
||||||
esp_bootloader_esp_idf::esp_app_desc!();
|
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 {
|
macro_rules! mk_static {
|
||||||
($t:ty,$val:expr) => {{
|
($t:ty,$val:expr) => {{
|
||||||
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
|
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) -> ! {
|
async fn main(_spawner: Spawner) -> ! {
|
||||||
esp_println::logger::init_logger_from_env();
|
|
||||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||||
let peripherals = esp_hal::init(config);
|
let peripherals = esp_hal::init(config);
|
||||||
|
|
||||||
@@ -84,8 +82,6 @@ async fn main(_spawner: Spawner) -> ! {
|
|||||||
esp_radio::wifi::new(peripherals.WIFI, Default::default()).unwrap()
|
esp_radio::wifi::new(peripherals.WIFI, Default::default()).unwrap()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Not used
|
|
||||||
println!("Scan");
|
|
||||||
let mut ap_channel = 0;
|
let mut ap_channel = 0;
|
||||||
let scan_config = ScanConfig::default().with_max(10);
|
let scan_config = ScanConfig::default().with_max(10);
|
||||||
let result = controller.scan_async(&scan_config).await.unwrap();
|
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 reason = reset_reason(Cpu::ProCpu);
|
||||||
let wake_reason = wakeup_cause();
|
let wake_reason = wakeup_cause();
|
||||||
|
|
||||||
println!("{:?} {:?}", reason, wake_reason);
|
println!("{:?} {:?}", reason, wake_reason);
|
||||||
|
|
||||||
let timer = TimerWakeupSource::new(core::time::Duration::from_secs(DEEP_SLEEP_TIME));
|
|
||||||
|
|
||||||
let mut ticker = Ticker::every(Duration::from_millis(200));
|
let mut ticker = Ticker::every(Duration::from_millis(200));
|
||||||
loop {
|
loop {
|
||||||
@@ -161,6 +155,7 @@ async fn main(_spawner: Spawner) -> ! {
|
|||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
esp_println::dbg!("An error occurred while trying to read sensor: {:?}", 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 data = String::from(temperature.to_string() + ";" + &humidity.to_string());
|
||||||
let string = String::from(temperature.to_string() + ";" + &humidity.to_string());
|
let fill = (0..(20 - data.len())).map(|_| " ").collect::<String>();
|
||||||
let fill = (0..(20-string.len())).map(|_| " ").collect::<String>();
|
println!("Send {:?} to peer {:?}", data, peer.peer_address);
|
||||||
println!("Send temperature to peer {:?}", peer.peer_address);
|
|
||||||
let mut sender = sender.lock().await;
|
let mut sender = sender.lock().await;
|
||||||
let status = sender
|
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;
|
.await;
|
||||||
println!("Send status: {:?}", status);
|
println!("Send status: {:?}", status);
|
||||||
println!("Going sleep: {:?} for seconds", DEEP_SLEEP_TIME);
|
deep_sleep(&mut rtc, &delay, DEEP_SLEEP_TIME);
|
||||||
delay.delay_millis(100);
|
|
||||||
rtc.sleep_deep(&[&timer]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user