Add example for packet sending support

This way, the one-way-link example (basically) works!
This commit is contained in:
Leonora Tindall 2020-08-30 09:52:09 -05:00
parent 774f4a9f9e
commit aa6d70b3a2
Signed by: nora
GPG Key ID: 7A8B52EC67E09AAF
1 changed files with 37 additions and 0 deletions

View File

@ -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 <serial port>");
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));
}
}