RadioLib
Universal wireless communication library for Arduino
LoRaWANNode Class Reference

LoRaWAN-compatible node (class A device). More...

#include <LoRaWAN.h>

Public Member Functions

 LoRaWANNode (PhysicalLayer *phy, const LoRaWANBand_t *band)
 Default constructor. More...
 
void wipe ()
 Wipe internal persistent parameters. This will reset all counters and saved variables, so the device will have to rejoin the network.
 
int16_t restore ()
 Restore session by loading information from persistent storage. More...
 
int16_t beginOTAA (uint64_t joinEUI, uint64_t devEUI, uint8_t *nwkKey, uint8_t *appKey, uint8_t joinDr=RADIOLIB_LORAWAN_DATA_RATE_UNUSED, bool force=false)
 Join network by performing over-the-air activation. By this procedure, the device will perform an exchange with the network server and set all necessary configuration. More...
 
int16_t beginABP (uint32_t addr, uint8_t *nwkSKey, uint8_t *appSKey, uint8_t *fNwkSIntKey=NULL, uint8_t *sNwkSIntKey=NULL, bool force=false)
 Join network by performing activation by personalization. In this procedure, all necessary configuration must be provided by the user. More...
 
bool isJoined ()
 Whether there is an ongoing session active.
 
int16_t saveSession ()
 Save the current state of the session. All variables are compared to what is saved and only the differences are rewritten. More...
 
int16_t uplink (const char *str, uint8_t port, bool isConfirmed=false, LoRaWANEvent_t *event=NULL)
 Send a message to the server. More...
 
int16_t uplink (uint8_t *data, size_t len, uint8_t port, bool isConfirmed=false, LoRaWANEvent_t *event=NULL)
 Send a message to the server. More...
 
int16_t downlink (uint8_t *data, size_t *len, LoRaWANEvent_t *event=NULL)
 Wait for downlink from the server in either RX1 or RX2 window. More...
 
int16_t sendReceive (const char *strUp, uint8_t port, uint8_t *dataDown, size_t *lenDown, bool isConfirmed=false, LoRaWANEvent_t *eventUp=NULL, LoRaWANEvent_t *eventDown=NULL)
 Send a message to the server and wait for a downlink during Rx1 and/or Rx2 window. More...
 
int16_t sendReceive (uint8_t *dataUp, size_t lenUp, uint8_t port, uint8_t *dataDown, size_t *lenDown, bool isConfirmed=false, LoRaWANEvent_t *eventUp=NULL, LoRaWANEvent_t *eventDown=NULL)
 Send a message to the server and wait for a downlink during Rx1 and/or Rx2 window. More...
 
void setDeviceStatus (uint8_t battLevel)
 Set device status. More...
 
uint32_t getFcntUp ()
 Returns the last uplink's frame counter.
 
int16_t setDatarate (uint8_t drUp)
 Set uplink datarate. This should not be used when ADR is enabled. More...
 
void setADR (bool enable=true)
 Toggle ADR to on or off. More...
 
int16_t setTxPower (int8_t txPower)
 Configure TX power of the radio module. More...
 
int16_t selectSubband (uint8_t idx)
 Select a single subband (8 channels) for fixed bands such as US915. Only available before joining a network. More...
 
int16_t selectSubband (uint8_t startChannel, uint8_t endChannel)
 Select a set of channels for fixed bands such as US915. Only available before joining a network. More...
 
void setCSMA (uint8_t backoffMax, uint8_t difsSlots, bool enableCSMA=false)
 Configures CSMA for LoRaWAN as per TR-13, LoRa Alliance. More...
 

Public Attributes

uint8_t rx1DrOffset
 
LoRaWANChannel_t rx2
 

Detailed Description

LoRaWAN-compatible node (class A device).

Constructor & Destructor Documentation

◆ LoRaWANNode()

LoRaWANNode::LoRaWANNode ( PhysicalLayer phy,
const LoRaWANBand_t band 
)

Default constructor.

Parameters
phyPointer to the PhysicalLayer radio module.
bandPointer to the LoRaWAN band to use.

Member Function Documentation

◆ beginABP()

int16_t LoRaWANNode::beginABP ( uint32_t  addr,
uint8_t *  nwkSKey,
uint8_t *  appSKey,
uint8_t *  fNwkSIntKey = NULL,
uint8_t *  sNwkSIntKey = NULL,
bool  force = false 
)

Join network by performing activation by personalization. In this procedure, all necessary configuration must be provided by the user.

Parameters
addrDevice address.
nwkSKeyPointer to the network session AES-128 key (LoRaWAN 1.0) or MAC command network session key (LoRaWAN 1.1).
appSKeyPointer to the application session AES-128 key.
fNwkSIntKeyPointer to the network session F key (LoRaWAN 1.1), unused for LoRaWAN 1.0.
sNwkSIntKeyPointer to the network session S key (LoRaWAN 1.1), unused for LoRaWAN 1.0.
forceSet to true to force a new session, even if one exists.
Returns
Status Codes

◆ beginOTAA()

int16_t LoRaWANNode::beginOTAA ( uint64_t  joinEUI,
uint64_t  devEUI,
uint8_t *  nwkKey,
uint8_t *  appKey,
uint8_t  joinDr = RADIOLIB_LORAWAN_DATA_RATE_UNUSED,
bool  force = false 
)

Join network by performing over-the-air activation. By this procedure, the device will perform an exchange with the network server and set all necessary configuration.

Parameters
joinEUI8-byte application identifier.
devEUI8-byte device identifier.
nwkKeyPointer to the network AES-128 key.
appKeyPointer to the application AES-128 key.
joinDr(OTAA:) The datarate at which to send the join-request; (ABP:) ignored
forceSet to true to force joining even if previously joined.
Returns
Status Codes

◆ downlink()

int16_t LoRaWANNode::downlink ( uint8_t *  data,
size_t *  len,
LoRaWANEvent_t event = NULL 
)

Wait for downlink from the server in either RX1 or RX2 window.

Parameters
dataBuffer to save received data into.
lenPointer to variable that will be used to save the number of received bytes.
eventPointer to a structure to store extra information about the event (port, frame counter, etc.). If set to NULL, no extra information will be passed to the user.
Returns
Status Codes

◆ restore()

int16_t LoRaWANNode::restore ( )

Restore session by loading information from persistent storage.

Returns
Status Codes

◆ saveSession()

int16_t LoRaWANNode::saveSession ( )

Save the current state of the session. All variables are compared to what is saved and only the differences are rewritten.

Returns
Status Codes

◆ selectSubband() [1/2]

int16_t LoRaWANNode::selectSubband ( uint8_t  idx)

Select a single subband (8 channels) for fixed bands such as US915. Only available before joining a network.

Parameters
idxThe subband to be used (starting from 1!)
Returns
Status Codes

◆ selectSubband() [2/2]

int16_t LoRaWANNode::selectSubband ( uint8_t  startChannel,
uint8_t  endChannel 
)

Select a set of channels for fixed bands such as US915. Only available before joining a network.

Parameters
startChannelThe first channel of the band to be used (inclusive)
endChannelThe last channel of the band to be used (inclusive)
Returns
Status Codes

◆ sendReceive() [1/2]

int16_t LoRaWANNode::sendReceive ( const char *  strUp,
uint8_t  port,
uint8_t *  dataDown,
size_t *  lenDown,
bool  isConfirmed = false,
LoRaWANEvent_t eventUp = NULL,
LoRaWANEvent_t eventDown = NULL 
)

Send a message to the server and wait for a downlink during Rx1 and/or Rx2 window.

Parameters
strUpC-string that will be transmitted.
portPort number to send the message to.
dataDownBuffer to save received data into.
lenDownPointer to variable that will be used to save the number of received bytes.
isConfirmedWhether to send a confirmed uplink or not.
eventUpPointer to a structure to store extra information about the uplink event (port, frame counter, etc.). If set to NULL, no extra information will be passed to the user.
eventDownPointer to a structure to store extra information about the downlink event (port, frame counter, etc.). If set to NULL, no extra information will be passed to the user.
Returns
Status Codes

◆ sendReceive() [2/2]

int16_t LoRaWANNode::sendReceive ( uint8_t *  dataUp,
size_t  lenUp,
uint8_t  port,
uint8_t *  dataDown,
size_t *  lenDown,
bool  isConfirmed = false,
LoRaWANEvent_t eventUp = NULL,
LoRaWANEvent_t eventDown = NULL 
)

Send a message to the server and wait for a downlink during Rx1 and/or Rx2 window.

Parameters
dataUpData to send.
lenUpLength of the data.
portPort number to send the message to.
dataDownBuffer to save received data into.
lenDownPointer to variable that will be used to save the number of received bytes.
isConfirmedWhether to send a confirmed uplink or not.
eventUpPointer to a structure to store extra information about the uplink event (port, frame counter, etc.). If set to NULL, no extra information will be passed to the user.
eventDownPointer to a structure to store extra information about the downlink event (port, frame counter, etc.). If set to NULL, no extra information will be passed to the user.
Returns
Status Codes

◆ setADR()

void LoRaWANNode::setADR ( bool  enable = true)

Toggle ADR to on or off.

Parameters
enableWhether to disable ADR or not.

◆ setCSMA()

void LoRaWANNode::setCSMA ( uint8_t  backoffMax,
uint8_t  difsSlots,
bool  enableCSMA = false 
)

Configures CSMA for LoRaWAN as per TR-13, LoRa Alliance.

Parameters
backoffMaxNum of BO slots to be decremented after DIFS phase. 0 to disable BO.
difsSlotsNum of CADs to estimate a clear CH.
enableCSMAenable/disable CSMA for LoRaWAN.

◆ setDatarate()

int16_t LoRaWANNode::setDatarate ( uint8_t  drUp)

Set uplink datarate. This should not be used when ADR is enabled.

Parameters
drDatarate to use for uplinks.
Returns
Status Codes

◆ setDeviceStatus()

void LoRaWANNode::setDeviceStatus ( uint8_t  battLevel)

Set device status.

Parameters
battLevelBattery level to set. 0 for external power source, 1 for lowest battery, 254 for highest battery, 255 for unable to measure.

◆ setTxPower()

int16_t LoRaWANNode::setTxPower ( int8_t  txPower)

Configure TX power of the radio module.

Parameters
txPowerOutput power during TX mode to be set in dBm.
Returns
Status Codes

◆ uplink() [1/2]

int16_t LoRaWANNode::uplink ( const char *  str,
uint8_t  port,
bool  isConfirmed = false,
LoRaWANEvent_t event = NULL 
)

Send a message to the server.

Parameters
strC-string that will be transmitted.
portPort number to send the message to.
isConfirmedWhether to send a confirmed uplink or not.
eventPointer to a structure to store extra information about the event (port, frame counter, etc.). If set to NULL, no extra information will be passed to the user.
Returns
Status Codes

◆ uplink() [2/2]

int16_t LoRaWANNode::uplink ( uint8_t *  data,
size_t  len,
uint8_t  port,
bool  isConfirmed = false,
LoRaWANEvent_t event = NULL 
)

Send a message to the server.

Parameters
dataData to send.
lenLength of the data.
portPort number to send the message to.
isConfirmedWhether to send a confirmed uplink or not.
eventPointer to a structure to store extra information about the event (port, frame counter, etc.). If set to NULL, no extra information will be passed to the user.
Returns
Status Codes

The documentation for this class was generated from the following files: