Browse Source

Add example for packet sending support

This way, the one-way-link example (basically) works!
main
Leonora Tindall 1 month ago
parent
commit
aa6d70b3a2
Signed by: nora <nora@nora.codes> GPG Key ID: 7A8B52EC67E09AAF
1 changed files with 37 additions and 0 deletions
  1. +37
    -0
      examples/lora_packet_tx.rs

+ 37
- 0
examples/lora_packet_tx.rs 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));
}
}

Loading…
Cancel
Save