From daf3ea24d7ecec4727ed036e8d431417999064cf Mon Sep 17 00:00:00 2001 From: Ulf Lilleengen Date: Mon, 4 Jul 2022 10:33:29 +0200 Subject: [PATCH] Document configuration options and handle optional downlink --- examples/stm32wl/src/bin/lorawan.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/stm32wl/src/bin/lorawan.rs b/examples/stm32wl/src/bin/lorawan.rs index 4f0dc7df..158c17e1 100644 --- a/examples/stm32wl/src/bin/lorawan.rs +++ b/examples/stm32wl/src/bin/lorawan.rs @@ -38,9 +38,22 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) { static mut RADIO_STATE: SubGhzState<'static> = SubGhzState::new(); let radio = unsafe { SubGhzRadio::new(&mut RADIO_STATE, radio, rfs, irq) }; - let region = region::EU868::default().into(); + let mut region: region::Configuration = region::EU868::default().into(); + + // NOTE: This is specific for TTN, as they have a special RX1 delay + region.set_receive_delay1(5000); + let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer, Rng::new(p.RNG)); + // Depending on network, this might be part of JOIN + device.set_datarate(region::DR::_0); // SF12 + + // device.set_datarate(region::DR::_1); // SF11 + // device.set_datarate(region::DR::_2); // SF10 + // device.set_datarate(region::DR::_3); // SF9 + // device.set_datarate(region::DR::_4); // SF8 + // device.set_datarate(region::DR::_5); // SF7 + defmt::info!("Joining LoRaWAN network"); // TODO: Adjust the EUI and Keys according to your network credentials @@ -55,7 +68,12 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) { .unwrap(); defmt::info!("LoRaWAN network joined"); + let mut rx: [u8; 255] = [0; 255]; defmt::info!("Sending 'PING'"); - device.send(b"PING", 1, false).await.ok().unwrap(); - defmt::info!("Message sent!"); + let len = device.send_recv(b"PING", &mut rx[..], 1, true).await.ok().unwrap(); + if len > 0 { + defmt::info!("Message sent, received downlink: {:?}", &rx[..len]); + } else { + defmt::info!("Message sent!"); + } }