A Rusty interface for the RN2903 LoRa module's serial protocol
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

38 linhas
1.2KB

  1. use rn2903::{bytes_to_string, Rn2903};
  2. use std::env::args;
  3. use std::process::exit;
  4. use std::thread;
  5. use std::time::Duration;
  6. use std::time::{SystemTime, UNIX_EPOCH};
  7. fn main() {
  8. let args: Vec<_> = args().collect();
  9. if args.len() <= 1 {
  10. eprintln!("rn2903_lora_packet_tx <serial port>");
  11. eprintln!("\tSend LoRa packets with the current UNIX time every 5 seconds.");
  12. exit(1);
  13. }
  14. let mut txvr = Rn2903::new_at(&args[1]).expect("Could not open device. Error");
  15. println!(
  16. "Successfully connected. Version: {}",
  17. txvr.system_version()
  18. .expect("Could not read from device. Error:")
  19. );
  20. txvr.mac_pause().unwrap();
  21. txvr.transact(b"sys set pindig GPIO10 0").unwrap();
  22. loop {
  23. txvr.transact(b"sys set pindig GPIO10 1").unwrap();
  24. let now = SystemTime::now();
  25. let since_the_epoch = now
  26. .duration_since(UNIX_EPOCH)
  27. .expect("Time went backwards")
  28. .as_millis();
  29. println!("sending: {}", since_the_epoch);
  30. txvr.radio_tx(format!("{}", since_the_epoch));
  31. txvr.transact(b"sys set pindig GPIO10 0").unwrap();
  32. thread::sleep(Duration::from_millis(100));
  33. }
  34. }