LoRaWAN

Build Status ![Latest Version] ![Docs] Gitter chat

The lorawan library provides structures and tools for reading and writing LoRaWAN 1.0.2 messages from and to slices of bytes.

Sample Packet manipulation

Use the library

toml [dependencies] lorawan = "0.5.0"

Packet generation

```rust use lorawan::{creator, keys, maccommands}; use heapless;

fn main() { let mut phy = creator::JoinAcceptCreator::new(); let key = keys::AES128([1; 16]); let appnoncebytes = [1; 3]; phy.setappnonce(&appnoncebytes); phy.setnetid(&[1; 3]); phy.setdevaddr(&[1; 4]); phy.setdlsettings(2); phy.setrxdelay(1); let mut freqs: heapless::Vec = heapless::Vec::new(); freqs.push(maccommands::Frequency::new(&[0x58, 0x6e, 0x84,]).unwrap()).unwrap(); freqs.push(maccommands::Frequency::new(&[0x88, 0x66, 0x84,]).unwrap()).unwrap(); phy.setcf_list(freqs).unwrap(); let payload = phy.build(&key).unwrap(); println!("Payload: {:x?}", payload); } ```

Packet parsing

```rust use lorawan::parser::; use lorawan::keys::;

fn main() { let data = vec![0x40, 0x04, 0x03, 0x02, 0x01, 0x80, 0x01, 0x00, 0x01, 0xa6, 0x94, 0x64, 0x26, 0x15, 0xd6, 0xc3, 0xb5, 0x82]; if let Ok(PhyPayload::Data(DataPayload::Encrypted(phy))) = parse(data) { let key = AES128([1; 16]); let decrypted = phy.decrypt(None, Some(&key), 1).unwrap(); if let Ok(FRMPayload::Data(datapayload)) = decrypted.frmpayload() { println!("{}", String::fromutf8lossy(data_payload)); } } else { panic!("failed to parse data payload"); } } ```

Contributing

Please read the contributing guidelines

Used code and inspiration

I would like to thank the projects lorawan by brocaar for the inspiration and useful examples.