aboutsummaryrefslogtreecommitdiff
path: root/examples/rp/src/bin/lora_lorawan.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/rp/src/bin/lora_lorawan.rs')
-rw-r--r--examples/rp/src/bin/lora_lorawan.rs74
1 files changed, 0 insertions, 74 deletions
diff --git a/examples/rp/src/bin/lora_lorawan.rs b/examples/rp/src/bin/lora_lorawan.rs
deleted file mode 100644
index e7e81863e..000000000
--- a/examples/rp/src/bin/lora_lorawan.rs
+++ /dev/null
@@ -1,74 +0,0 @@
1//! This example runs on the Raspberry Pi Pico with a Waveshare board containing a Semtech Sx1262 radio.
2//! It demonstrates LoRaWAN join functionality.
3
4#![no_std]
5#![no_main]
6#![macro_use]
7#![feature(type_alias_impl_trait)]
8
9use defmt::*;
10use embassy_executor::Spawner;
11use embassy_lora::iv::GenericSx126xInterfaceVariant;
12use embassy_lora::LoraTimer;
13use embassy_rp::gpio::{Input, Level, Output, Pin, Pull};
14use embassy_rp::spi::{Config, Spi};
15use embassy_time::Delay;
16use lora_phy::mod_params::*;
17use lora_phy::sx1261_2::SX1261_2;
18use lora_phy::LoRa;
19use lorawan::default_crypto::DefaultFactory as Crypto;
20use lorawan_device::async_device::lora_radio::LoRaRadio;
21use lorawan_device::async_device::{region, Device, JoinMode};
22use lorawan_device::{AppEui, AppKey, DevEui};
23use {defmt_rtt as _, panic_probe as _};
24
25const LORAWAN_REGION: region::Region = region::Region::EU868; // warning: set this appropriately for the region
26
27#[embassy_executor::main]
28async fn main(_spawner: Spawner) {
29 let p = embassy_rp::init(Default::default());
30
31 let miso = p.PIN_12;
32 let mosi = p.PIN_11;
33 let clk = p.PIN_10;
34 let spi = Spi::new(p.SPI1, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default());
35
36 let nss = Output::new(p.PIN_3.degrade(), Level::High);
37 let reset = Output::new(p.PIN_15.degrade(), Level::High);
38 let dio1 = Input::new(p.PIN_20.degrade(), Pull::None);
39 let busy = Input::new(p.PIN_2.degrade(), Pull::None);
40
41 let iv = GenericSx126xInterfaceVariant::new(nss, reset, dio1, busy, None, None).unwrap();
42
43 let lora = {
44 match LoRa::new(SX1261_2::new(BoardType::RpPicoWaveshareSx1262, spi, iv), true, Delay).await {
45 Ok(l) => l,
46 Err(err) => {
47 info!("Radio error = {}", err);
48 return;
49 }
50 }
51 };
52
53 let radio = LoRaRadio::new(lora);
54 let region: region::Configuration = region::Configuration::new(LORAWAN_REGION);
55 let mut device: Device<_, Crypto, _, _> = Device::new(region, radio, LoraTimer::new(), embassy_rp::clocks::RoscRng);
56
57 defmt::info!("Joining LoRaWAN network");
58
59 // TODO: Adjust the EUI and Keys according to your network credentials
60 match device
61 .join(&JoinMode::OTAA {
62 deveui: DevEui::from([0, 0, 0, 0, 0, 0, 0, 0]),
63 appeui: AppEui::from([0, 0, 0, 0, 0, 0, 0, 0]),
64 appkey: AppKey::from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
65 })
66 .await
67 {
68 Ok(()) => defmt::info!("LoRaWAN network joined"),
69 Err(err) => {
70 info!("Radio error = {}", err);
71 return;
72 }
73 };
74}