From aa6d70b3a24f97f7de012726d39281ea516334bb Mon Sep 17 00:00:00 2001 From: Leonora Tindall Date: Sun, 30 Aug 2020 09:52:09 -0500 Subject: [PATCH] Add example for packet sending support This way, the one-way-link example (basically) works! --- examples/lora_packet_tx.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/lora_packet_tx.rs diff --git a/examples/lora_packet_tx.rs b/examples/lora_packet_tx.rs new file mode 100644 index 0000000..34f05ec --- /dev/null +++ b/examples/lora_packet_tx.rs @@ -0,0 +1,37 @@ +use rn2903::{bytes_to_string, Rn2903}; +use std::env::args; +use std::process::exit; +use std::thread; +use std::time::Duration; +use std::time::{SystemTime, UNIX_EPOCH}; + +fn main() { + let args: Vec<_> = args().collect(); + if args.len() <= 1 { + eprintln!("rn2903_lora_packet_tx "); + eprintln!("\tSend LoRa packets with the current UNIX time every 5 seconds."); + exit(1); + } + + let mut txvr = Rn2903::new_at(&args[1]).expect("Could not open device. Error"); + println!( + "Successfully connected. Version: {}", + txvr.system_version() + .expect("Could not read from device. Error:") + ); + + txvr.mac_pause().unwrap(); + txvr.transact(b"sys set pindig GPIO10 0").unwrap(); + loop { + txvr.transact(b"sys set pindig GPIO10 1").unwrap(); + let now = SystemTime::now(); + let since_the_epoch = now + .duration_since(UNIX_EPOCH) + .expect("Time went backwards") + .as_millis(); + println!("sending: {}", since_the_epoch); + txvr.radio_tx(format!("{}", since_the_epoch)); + txvr.transact(b"sys set pindig GPIO10 0").unwrap(); + thread::sleep(Duration::from_millis(100)); + } +}