RadioLib
Universal wireless communication library for Arduino
|
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) |
Send a message to the server. More... | |
int16_t | uplink (uint8_t *data, size_t len, uint8_t port, bool isConfirmed=false) |
Send a message to the server. More... | |
int16_t | downlink (uint8_t *data, size_t *len) |
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) |
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) |
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 | 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 |
LoRaWAN-compatible node (class A device).
LoRaWANNode::LoRaWANNode | ( | PhysicalLayer * | phy, |
const LoRaWANBand_t * | band | ||
) |
Default constructor.
phy | Pointer to the PhysicalLayer radio module. |
band | Pointer to the LoRaWAN band to use. |
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.
addr | Device address. |
nwkSKey | Pointer to the network session AES-128 key (LoRaWAN 1.0) or MAC command network session key (LoRaWAN 1.1). |
appSKey | Pointer to the application session AES-128 key. |
fNwkSIntKey | Pointer to the network session F key (LoRaWAN 1.1), unused for LoRaWAN 1.0. |
sNwkSIntKey | Pointer to the network session S key (LoRaWAN 1.1), unused for LoRaWAN 1.0. |
force | Set to true to force a new session, even if one exists. |
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.
joinEUI | 8-byte application identifier. |
devEUI | 8-byte device identifier. |
nwkKey | Pointer to the network AES-128 key. |
appKey | Pointer to the application AES-128 key. |
joinDr | (OTAA:) The datarate at which to send the join-request; (ABP:) ignored |
force | Set to true to force joining even if previously joined. |
int16_t LoRaWANNode::downlink | ( | uint8_t * | data, |
size_t * | len | ||
) |
Wait for downlink from the server in either RX1 or RX2 window.
data | Buffer to save received data into. |
len | Pointer to variable that will be used to save the number of received bytes. |
int16_t LoRaWANNode::restore | ( | ) |
Restore session by loading information from persistent storage.
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.
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.
idx | The subband to be used (starting from 1!) |
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.
startChannel | The first channel of the band to be used (inclusive) |
endChannel | The last channel of the band to be used (inclusive) |
int16_t LoRaWANNode::sendReceive | ( | const char * | strUp, |
uint8_t | port, | ||
uint8_t * | dataDown, | ||
size_t * | lenDown, | ||
bool | isConfirmed = false |
||
) |
Send a message to the server and wait for a downlink during Rx1 and/or Rx2 window.
strUp | C-string that will be transmitted. |
port | Port number to send the message to. |
dataDown | Buffer to save received data into. |
lenDown | Pointer to variable that will be used to save the number of received bytes. |
isConfirmed | Whether to send a confirmed uplink or not. |
int16_t LoRaWANNode::sendReceive | ( | uint8_t * | dataUp, |
size_t | lenUp, | ||
uint8_t | port, | ||
uint8_t * | dataDown, | ||
size_t * | lenDown, | ||
bool | isConfirmed = false |
||
) |
Send a message to the server and wait for a downlink during Rx1 and/or Rx2 window.
dataUp | Data to send. |
lenUp | Length of the data. |
port | Port number to send the message to. |
dataDown | Buffer to save received data into. |
lenDown | Pointer to variable that will be used to save the number of received bytes. |
isConfirmed | Whether to send a confirmed uplink or not. |
void LoRaWANNode::setADR | ( | bool | enable = true | ) |
Toggle ADR to on or off.
enable | Whether to disable ADR or not |
void LoRaWANNode::setCSMA | ( | uint8_t | backoffMax, |
uint8_t | difsSlots, | ||
bool | enableCSMA = false |
||
) |
Configures CSMA for LoRaWAN as per TR-13, LoRa Alliance.
backoffMax | Num of BO slots to be decremented after DIFS phase. 0 to disable BO. |
difsSlots | Num of CADs to estimate a clear CH. |
enableCSMA | enable/disable CSMA for LoRaWAN. |
int16_t LoRaWANNode::setDatarate | ( | uint8_t | drUp | ) |
Set uplink datarate. This should not be used when ADR is enabled.
dr | Datarate to use for uplinks. |
void LoRaWANNode::setDeviceStatus | ( | uint8_t | battLevel | ) |
Set device status.
battLevel | Battery level to set. 0 for external power source, 1 for lowest battery, 254 for highest battery, 255 for unable to measure. |
int16_t LoRaWANNode::uplink | ( | const char * | str, |
uint8_t | port, | ||
bool | isConfirmed = false |
||
) |
Send a message to the server.
str | C-string that will be transmitted. |
port | Port number to send the message to. |
isConfirmed | Whether to send a confirmed uplink or not. |
int16_t LoRaWANNode::uplink | ( | uint8_t * | data, |
size_t | len, | ||
uint8_t | port, | ||
bool | isConfirmed = false |
||
) |
Send a message to the server.
data | Data to send. |
len | Length of the data. |
port | Port number to send the message to. |
isConfirmed | Whether to send a confirmed uplink or not. |