LoRaWAN
With version V4.1.1 of RUI3, the LoRa P2P functions are separated into a new class and API calls for LoRa have a changed syntax:
Old | New | Comment |
---|---|---|
api.lorawan.pXXX | api.lora.pXXX | All LoRa P2P API calls change. |
api.lorawan.registerPyyy | api.lora.registerPyyy | All LoRa P2P callback register API calls change. |
api.lorawan.nwm.set(1) | api.lorawan.nwm.set() | Set device to LoRaWAN mode. |
api.lorawan.nwm.set(0) | api.lora.nwm.set() | Set device to LoRa P2P mode. |
LoRaWAN Data Type
RAK_LORA_McSession
The structure of a multicast group
typedef struct
{
uint8_t McDevclass; ///< The device class of a multicast group
uint32_t McAddress; ///< The address of a multicast group
uint8_t McAppSKey[16]; ///< The application session key of a multicast group
uint8_t McNwkSKey[16]; ///< The Network session key of a multicast group
uint32_t McFrequency; ///< The frequency of a multicast group
int8_t McDatarate; ///< The data rate of a multicast group
uint16_t McPeriodicity; ///< The periodicity of a multicast group
int8_t McGroupID; ///< The group ID of a multicast group
uint8_t entry; ///< The entry of a multicast group
} RAK_LORA_McSession;
McDevclass
The device class of a multicast group
uint8_t McDevclass
McAddress
The address of a multicast group
uint32_t McAddress
McAppSKey
The application session key of a multicast group
uint8_t McAppSKey[16]
McNwkSKey
The Network session key of a multicast group
uint8_t McNwkSKey[16]
McFrequency
The frequency of a multicast group
uint32_t McFrequency
McDatarate
The data rate of a multicast group
int8_t McDatarate
McPeriodicity
The periodicity of a multicast group
uint16_t McPeriodicity
McGroupID
The group ID of a multicast group
int8_t McGroupID
entry
The entry of a multicast group
uint8_t entry
RAK_LORA_chan_rssi_t
The structure of a rssi data
typedef struct
{
uint32_t chan; ///< The channel of a rssi
uint16_t mask; ///< The mask of a rssi
int8_t rssi; ///< The rssi on reception
} RAK_LORA_chan_rssi;"
chan
The channel of a rssi
uint32_t chan
mask
The mask of a rssi
uint16_t mask
rssi
The rssi on reception
int8_t rssi
RAK_LORA_BAND
The regions of LoRa
enum _RAK_LORA_BAND
Enumerator | |
---|---|
RAK_REGION_EU433 | EU433 |
RAK_REGION_CN470 | CN470 ~ 510 |
RAK_REGION_RU864 | RU864 ~ 870 |
RAK_REGION_IN865 | IN865 ~ 867 |
RAK_REGION_EU868 | EU863 ~ 870 |
RAK_REGION_US915 | US902 ~ 928 |
RAK_REGION_AU915 | AU915 ~ 928 |
RAK_REGION_KR920 | KR920 ~ 923 |
RAK_REGION_AS923-1 | AS923-1 |
RAK_REGION_AS923-2 | AS923-2 |
RAK_REGION_AS923-3 | AS923-3 |
RAK_REGION_AS923-4 | AS923-4 |
RAK_REGION_LA915 | LA915 |
typedef enum
{
RAK_REGION_EU433 = 0, ///< EU433
RAK_REGION_CN470 = 1, ///< CN470 ~ 510
RAK_REGION_RU864 = 2, ///< RU864 ~ 870
RAK_REGION_IN865 = 3, ///< IN865 ~ 867
RAK_REGION_EU868 = 4, ///< EU863 ~ 870
RAK_REGION_US915 = 5, ///< US902 ~ 928
RAK_REGION_AU915 = 6, ///< AU915 ~ 928
RAK_REGION_KR920 = 7, ///< KR920 ~ 923
RAK_REGION_AS923_1 = 8, ///< AS923-1
RAK_REGION_AS923_2 = 9, ///< AS923-2
RAK_REGION_AS923_3 = 10, ///< AS923-3
RAK_REGION_AS923_4 = 11, ///< AS923-4
RAK_REGION_LA915 = 12, ///< LA915
} RAK_LORA_BAND;"
RAK_LORA_JOIN_MODE
The LoRaWAN network join modes
enum _RAK_LORA_JOIN_MODE
Enumerator | |
---|---|
RAK_LORA_ABP | Activation by personalization |
RAK_LORA_OTAA | Over-the-air activation |
typedef enum
{
RAK_LORA_ABP = 0, ///< activation by personalization
RAK_LORA_OTAA = 1 ///< over-the-air activation
} RAK_LORA_JOIN_MODE;
RAK_LORA_WORK_MODE
The LoRaWAN working modes
enum _RAK_LORA_WORK_MODE
Enumerator | |
---|---|
RAK_LORA_P2P | Switch to P2P mode |
RAK_LORAWAN | Switch to LoRaWAN mode |
RAK_LORA_FSK | Switch to FSK mode |
typedef enum
{
RAK_LORA_P2P = 0, ///< Switch to P2P mode
RAK_LORAWAN = 1, ///< Switch to LoRaWan mode
RAK_LORA_FSK = 2, ///< Switch to FSK mode
} RAK_LORA_WORK_MODE;"
RAK_LORA_CONFIRM_MODE
The status of confirm mode
enum _RAK_LORA_CONFIRM_MODE
Enumerator | |
---|---|
RAK_LORA_NO_ACK | The device will not get received data from network. |
RAL_LORA_ACK | The device will get received data from network. |
typedef enum
{
RAK_LORA_NO_ACK = 0, ///< The device will not get received data from network
RAL_LORA_ACK = 1, ///< The device will get received data from network
} RAK_LORA_CONFIRM_MODE;
RAK_LORA_CLASS
The LoRaWAN classes
enum _RAK_LORA_CLASS
Enumerator | |
---|---|
RAK_LORA_CLASS_A | The LoRaWAN will work in Class A. |
RAK_LORA_CLASS_B | The LoRaWAN will work in Class B. |
RAK_LORA_CLASS_C | The LoRaWAN will work in Class C. |
typedef enum
{
RAK_LORA_CLASS_A = 0, ///< The LoRaWan will work in Class A
RAK_LORA_CLASS_B = 1, ///< The LoRaWan will work in Class B
RAK_LORA_CLASS_C = 2, ///< The LoRaWan will work in Class C
} RAK_LORA_CLASS;"
SERVICE_LORA_RECEIVE_T
The LoRaWAN receive frame control structure
typedef struct SERVICE_LORA_RECEIVE
{
uint8_t Port;
uint8_t RxDatarate;
uint8_t *Buffer;
uint8_t BufferSize;
int16_t Rssi;
int8_t Snr;
uint32_t DownLinkCounter;
} SERVICE_LORA_RECEIVE_T;
Port
Application port
uint8_t Port
RxDatarate
Downlink datarate
uint8_t RxDatarate;
Buffer
Pointer to the received LoRaWAN data stream
uint8_t *Buffer;
BufferSize
Size of the received LoRaWAN data stream
uint8_t BufferSize;
Rssi
Rssi of the LoraWAN received packet
int16_t Rssi;
Snr
Signal-to-noise ratio of the LoRaWAN received packet
int8_t Snr;
DownLinkCounter
The downlink counter value for the received frame
uint32_t DownLinkCounter;
rui_lora_p2p_revc_t
The LoRa P2P receive frame control structure
typedef struct rui_lora_p2p_revc
{
uint8_t *Buffer;
uint8_t BufferSize;
int16_t Rssi;
int8_t Snr;
} rui_lora_p2p_recv_t;
Buffer
Pointer to the received LoRa P2P data stream
uint8_t *Buffer;
BufferSize
Size of the received LoRa P2P data stream
uint8_t BufferSize;
Rssi
Rssi of the received LoRa P2P packet
int16_t Rssi;
Snr
Signal-to-noise ratio of the received P2P packet
int8_t Snr;
RAKLoRaMacEventInfoStatus
The Mac event results can be received in RX, TX, and Join callbacks.
Enumerator | Description |
---|---|
RAK_LORAMAC_STATUS_OK | Service performed successfully |
RAK_LORAMAC_STATUS_ERROR | An error occurred during the execution of the service |
RAK_LORAMAC_STATUS_TX_TIMEOUT | A Tx timeout occurred |
RAK_LORAMAC_STATUS_RX1_TIMEOUT | An Rx timeout occurred on receive window 1 |
RAK_LORAMAC_STATUS_RX2_TIMEOUT | An Rx timeout occurred on receive window 2 |
RAK_LORAMAC_STATUS_RX1_ERROR | An Rx error occurred on receive window 1 |
RAK_LORAMAC_STATUS_RX2_ERROR | An Rx error occurred on receive window 2 |
RAK_LORAMAC_STATUS_JOIN_FAIL | An error occurred in the join procedure |
RAK_LORAMAC_STATUS_DOWNLINK_REPEATED | A frame with an invalid downlink counter was received. The downlink counter of the frame is equal to the local copy of the downlink counter of the node. |
RAK_LORAMAC_STATUS_TX_DR_PAYLOAD_SIZE_ERROR | The MAC could not retransmit a frame since the MAC decreased the data rate. The payload size does not apply to the data rate. |
RAK_LORAMAC_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS | The node has lost MAX_FCNT_GAP or more frames. |
RAK_LORAMAC_STATUS_ADDRESS_FAIL | An address error occurred |
RAK_LORAMAC_STATUS_MIC_FAIL | Message integrity check failure |
RAK_LORAMAC_STATUS_MULTICAST_FAIL | Multicast error occurred |
RAK_LORAMAC_STATUS_BEACON_LOCKED | Beacon locked |
RAK_LORAMAC_STATUS_BEACON_LOST | Beacon lost |
RAK_LORAMAC_STATUS_BEACON_NOT_FOUND | Beacon not found |
typedef enum RAKLoRaMacEventInfoStatus {
RAK_LORAMAC_STATUS_OK = 0,
RAK_LORAMAC_STATUS_ERROR,
RAK_LORAMAC_STATUS_TX_TIMEOUT,
RAK_LORAMAC_STATUS_RX1_TIMEOUT,
RAK_LORAMAC_STATUS_RX2_TIMEOUT,
RAK_LORAMAC_STATUS_RX1_ERROR,
RAK_LORAMAC_STATUS_RX2_ERROR,
RAK_LORAMAC_STATUS_JOIN_FAIL,
RAK_LORAMAC_STATUS_DOWNLINK_REPEATED,
RAK_LORAMAC_STATUS_TX_DR_PAYLOAD_SIZE_ERROR,
RAK_LORAMAC_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS,
RAK_LORAMAC_STATUS_ADDRESS_FAIL,
RAK_LORAMAC_STATUS_MIC_FAIL,
RAK_LORAMAC_STATUS_MULTICAST_FAIL,
RAK_LORAMAC_STATUS_BEACON_LOCKED,
RAK_LORAMAC_STATUS_BEACON_LOST,
RAK_LORAMAC_STATUS_BEACON_NOT_FOUND
};
LoRa Network Management
nwm
Switch to LoRaWAN mode
RAKLorawan::nwm
get()
This API gets the network working mode (0 = P2P, 1 = LoRaWAN, 2 = FSK).
api.lorawan.nwm.get();
Function | int get() |
---|---|
Returns | the network working mode |
Return Values | 0 - P2P mode 1 - LoRaWAN mode 2 - FSK mode |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the network working mode %s\r\n", api.lorawan.nwm.set() ? "Success" : "Fail");
}
void loop()
{
Serial.printf("Network working mode = %s\r\n", api.lorawan.nwm.get() ? "LoRaWan" : "P2P");
delay(1000);
}
set()
This API sets the network working mode to LoRaWAN.
api.lorawan.nwm.set();
Function | bool set() |
---|---|
Returns | bool |
Return Values | TRUE for setting network working mode success FALSE for setting network working mode failure |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the network working mode %s\r\n", api.lorawan.nwm.set() ? "Success" : "Fail");
}
void loop()
{
Serial.printf("Network working mode = %s\r\n", api.lorawan.nwm.get() ? "LoRaWan" : "P2P");
delay(1000);
}