Skip to content

LoRa Packet

Josh Perriman edited this page Aug 7, 2018 · 2 revisions

Overview

LoRaPacket is used to encode data into a packet in a suitable format to be transmitted over LoRAWAN and be collected by the things network.

generatePacket

uint8_t generatePacket(uint8_t* payload, uint8_t payloadLength, uint32_t DevAddr, uint8_t* NwkSKey, uint8_t* AppSKey, uint8_t LoRaMacBuffer[]);

A function used to create a data packet. This function will return the length of the buffer containing the data to be sent.

Args
  • payload = A buffer containing the data required to be sent
  • payloadLength = The length of the buffer containing the data to be sent
  • DevAddr = The Device address provided by the things network
  • NwkSKey = Network session key provided by the things network
  • AppSKey = Application session key provided by the things network
  • LoRaMacBuffer = An empty buffer where the data to be sent will be written to
Example
#include <packetEncoder.h>

uint8_t AppSKey[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10};
uint8_t NwkSKey[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10};
uint32_t DevAddr = 0x01234567;

uint8_t payload = {1, 2, 3, 4, 5};
uint8_t payloadLength = 5;

uint8_t buffer[MAXPAYLOAD];
uint8_t len = generatePacket(payload, payloadLength, DevAddr, NwkSKey, AppSKey, buffer);

This code encodes the data in payload into a LoRa packet which is then stored in 'buffer'. The length of the LoRa packet to be sent is stored in 'len'. This packet can then be sent using the LoRa library.


Clone this wiki locally