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);
}
adr
This API allows the user to access the adaptive data rate.
RAKLorawan::adr
The default value of the ADR is 1 (enabled).
get()
This API allows the user to get the enabled/disabled status of adaptive data rate.
api.lorawan.adr.get();
Function | bool get() |
---|---|
Returns | bool |
Return Values | TRUE - adaptive data rate enabled FALSE - adaptive data rate disabled |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set adaptive data rate %s\r\n", api.lorawan.adr.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("Adaptive data rate is %s\r\n", api.lorawan.adr.get() ? "Enable" : "Disable");
delay(1000);
}
set()
This API allows the user to enable/disable the adaptive data rate.
api.lorawan.adr.set(value);
Function | bool set(bool value) |
---|---|
Parameters | value - the status of adaptive data rate - TRUE ADR enabled - FALSE ADR disabled |
Returns | bool |
Return Values | TRUE for setting status of adr success FALSE for setting status of adr failure |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set adaptive data rate %s\r\n", api.lorawan.adr.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("Adaptive data rate is %s\r\n", api.lorawan.adr.get() ? "Enable" : "Disable");
delay(1000);
}
deviceClass
This API allows the user to access the LoRaWAN class.
RAKLorawan::deviceClass
get()
This API allows the user to get the LoRaWAN class.
api.lorawan.deviceClass.get();
Function | uint8_t get() |
---|---|
Returns | the LoRaWan class (Type: int) |
Return Values | 0 - Class A 1 - Class B 2 - Class C |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set device class to Class_A %s\r\n", api.lorawan.deviceClass.set(0) ? "Success" : "Fail");
}
void loop()
{
switch(api.lorawan.deviceClass.get()) {
case 0:
Serial.println("Device is in Class A");
break;
case 1:
Serial.println("Device is in Class B");
break;
case 2:
Serial.println("Device is in Class C");
break;
}
delay(1000);
}
set()
This API allows the user to set the LoRaWAN class.
api.lorawan.deviceClass.set(value);
Function | bool set(uint8_t value) |
---|---|
Parameters | value - the LoRaWAN class 0 - Class A 1 - Class B 2 - Class C |
Returns | bool |
Return Values | TRUE for setting LoRaWAN class success FALSE for setting LoRaWAN class failure |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set device class to Class_A %s\r\n", api.lorawan.deviceClass.set(0) ? "Success" : "Fail");
}
void loop()
{
switch(api.lorawan.deviceClass.get()) {
case 0:
Serial.println("Device is in Class A");
break;
case 1:
Serial.println("Device is in Class B");
break;
case 2:
Serial.println("Device is in Class C");
break;
}
delay(1000);
}
dcs
This api allows the user to enable/disable the duty cycle setting
RAKLorawan::dcs
get()
This API allows the user to get the duty cycle parameter.
api.lorawan.dcs.get();
Function | bool get() |
---|---|
Returns | bool |
Return Values | TRUE - duty cycle enabled FALSE - duty cycle disabled |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Enable duty cycle %s\r\n", api.lorawan.dcs.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("Duty cycle is %s\r\n", api.lorawan.adr.get() ? "Enable" : "Disable");
delay(1000);
}
set()
This API allows the user to enable/disable the duty cycle.
api.lorawan.dcs.set(dutyCycle);
Function | bool set(uint8_t dutyCycle) |
---|---|
Parameters | dutyCycle - the LoRaWAN duty cycle - TRUE - enable duty cycle - FALSE - disable duty cycle |
Returns | bool |
Return Values | TRUE for setting duty cycle success FALSE for setting duty cycle fail |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Enable duty cycle %s\r\n", api.lorawan.dcs.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("Duty cycle is %s\r\n", api.lorawan.adr.get() ? "Enable" : "Disable");
delay(1000);
}
dr
This API allows the user to access the data rate.
Complete information about DR parameter on each region can be found on RUI3 Appendix - LoRaWAN Regional Parameter (Data Rate).
- EU433 / RU864 / IN865 / EU868 / CN470 / KR920 and the data rate range of values is 0-5 (DR0-DR5).
- AS923 and the data rate range of values is 2-5 (DR2-DR5).
- US915 and the data rate range of values is 0-4 (DR0-DR4).
- AU915 and the data rate range of values is 0-6 (DR0-DR6).
- LA915 and the data rate range of values is 0-6 (DR0-DR6).
RAKLorawan::dr
get()
This API allows the user to get the data rate.
During the join process, the DR might be different from the defined DR. Some regions require a specific DR during the join process.
api.lorawan.dr.get();
Function | uint8_t get() |
---|---|
Returns | the data rate (Type: int) |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the data rate %s\r\n", api.lorawan.dr.set(5) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The data rate is %d\r\n", api.lorawan.dr.get());
delay(1000);
}
set()
This API allows the user to set the data rate.
api.lorawan.dr.set(value);
Function | bool set(uint8_t value) |
---|---|
Parameters | value - the data rate (Type: int) |
Returns | bool |
Return Values | TRUE for setting data rate success FALSE for setting data rate failure |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the data rate %s\r\n", api.lorawan.dr.set(5) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The data rate is %d\r\n", api.lorawan.dr.get());
delay(1000);
}
jn1dl
This API allows the user to access the join delay on RX window 1.
RAKLorawan::jn1dl
get()
This API allows the user to get the data rate.
api.lorawan.jn1dl.get();
Function | int get() |
---|---|
Returns | the join delay on RX window 1 (Type: int) |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the join delay on RX window 1 %s\r\n", api.lorawan.jn1dl.set(5000) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The join delay on RX window 1 is %d\r\n", api.lorawan.jn1dl.get());
delay(1000);
}
set()
This API allows the user to set the join delay on RX window 1. The range of acceptable values is 1 to 14 seconds.
api.lorawan.jn1dl.set(value);
Function | bool set(int value) |
---|---|
Parameters | value - the join delay on RX window 1 |
Returns | bool |
Return Values | TRUE for setting join delay success FALSE for setting join delay failure |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the join delay on RX window 1 %s\r\n", api.lorawan.jn1dl.set(5000) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The join delay on RX window 1 is %d\r\n", api.lorawan.jn1dl.get());
delay(1000);
}
jn2dl
RAKLorawan::jn2dl
get()
This API allows the user to access the join delay on RX window 2.
api.lorawan.jn2dl.get();
Function | int get() |
---|---|
Returns | the join delay on RX window 2 (Type: int) |
Click to view the code
void setup()
{
Serial.begin(115200);
}
void loop()
{
Serial.printf("The join delay on RX window 2 is %d\r\n", api.lorawan.jn2dl.get());
delay(1000);
}
set()
This API allows the user to set the join delay on RX window 2. The range of acceptable values is 2 to 15 seconds.
api.lorawan.jn2dl.set(value);
Function | bool set(int value) |
---|---|
Parameters | value - the join delay on RX window (Type: int)2 |
Returns | bool |
Return Values | TRUE for setting join delay success FALSE for setting join delay failure |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the join delay on RX window 2 %s\r\n", api.lorawan.jn2dl.set(5000) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The join delay on RX window 2 is %d\r\n", api.lorawan.jn2dl.get());
delay(1000);
}
pnm
This API allows the user to access the public network mode.
RAKLorawan::pnm
get()
This API allows the user to get the public network mode.
api.lorawan.pnm.get();
Function | bool get() |
---|---|
Returns | bool |
Return Values | TRUE: On FALSE: Off |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the public network mode %s\r\n", api.lorawan.pnm.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The public network mode is %d\r\n", api.lorawan.pnm.get() ? "On" : "Off");
delay(1000);
}
set()
This API allows the user to set the public network mode.
api.lorawan.pnm.set(value);
Function | bool set(bool value) |
---|---|
Parameters | value - the public network mode - TRUE set public network mode - FALSE set private network mode |
Returns | bool |
Return Values | TRUE for setting public network mode success FALSE for setting public network mode failure |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the public network mode %s\r\n", api.lorawan.pnm.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The public network mode is %d\r\n", api.lorawan.pnm.get() ? "On" : "Off");
delay(1000);
}
rx1dl
This API allows the user to access the delay of the received window 1.
RAKLorawan::rx1dl
get()
This API allows the user to get the delay of the received window 1.
api.lorawan.rx1dl.get();
Function | int get() |
---|---|
Returns | the delay of the received window 1 |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the received delay on RX window 1 %s\r\n", api.lorawan.rx1dl.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The received delay on RX window 1 is %d\r\n", api.lorawan.rx1dl.get());
delay(1000);
}
set()
This API allows the user to set the delay of the received window 1. The range of acceptable values is 1 to 15 seconds. Whenever RX 1 Delay
is updated, RX 2 Delay
is also updated automatically.
api.lorawan.rx1dl.set(value);
Function | bool set(int value) |
---|---|
Parameters | value - the delay of the received window 1 |
Returns | bool |
Return Values | TRUE for setting delay success FALSE for setting delay failure |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the received delay on RX window 1 %s\r\n", api.lorawan.rx1dl.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The received delay on RX window 1 is %d\r\n", api.lorawan.rx1dl.get());
delay(1000);
}
rx2dl
This API allows the user to access the delay of the received window 2
RAKLorawan::rx2dl
get()
This API allows the user to get the delay of the received window 2
api.lorawan.rx2dl.get();
Function | int get() |
---|---|
Returns | the delay of the received window 2 |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the received delay on RX window 2 %s\r\n", api.lorawan.rx2dl.set(2000) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The received delay on RX window 2 is %d\r\n", api.lorawan.rx2dl.get());
delay(1000);
}
set()
This API allows the user to set the delay of the received window 2. The range of acceptable values is 2 to 15 seconds. Whenever RX 2 Delay
is updated, RX 1 Delay
is also updated automatically.
api.lorawan.rx2dl.set(value)
Function | bool set(int value) |
---|---|
Parameters | value - the delay of the received window 2 |
Returns | bool |
Return Values | TRUE for setting delay success FALSE for setting delay failure |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the received delay on RX window 2 %s\r\n", api.lorawan.rx2dl.set(2000) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The received delay on RX window 2 is %d\r\n", api.lorawan.rx2dl.get());
delay(1000);
}
rx2dr
This API allows the user to access the data rate of received window 2.
RAKLorawan::rx2dr
get()
This API allows the user to get the data rate of received window 2.
api.lorawan.rx2dr.get();
Function | uint8_t get() |
---|---|
Returns | the data rate of received window 2 |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the data rate of received window 2 %s\r\n", api.lorawan.rx2dr.set(5) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The data rate of received window 2 is %d\r\n", api.lorawan.rx2dr.get());
delay(1000);
}
set()
This API allows the user to set the data rate of received window 2.
api.lorawan.rx2dr.set(value);
Function | bool set(uint8_t value) |
---|---|
Parameters | value - the data rate of received window 2 |
Returns | bool |
Return Values | TRUE for setting data rate success FALSE for setting data rate failure |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the data rate of received window 2 %s\r\n", api.lorawan.rx2dr.set(5) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The data rate of received window 2 is %d\r\n", api.lorawan.rx2dr.get());
delay(1000);
}
rx2fq
RAKLorawan::rx2fq
get()
This API allows the user to access the frequency of the received window 2.
api.lorawan.rx2fq.get();
Function | long get() |
---|---|
Returns | the frequency of the received window 2 |
Click to view the code
void setup()
{
Serial.begin(115200);
}
void loop()
{
Serial.printf("The frequency of received window 2 is %d\r\n", api.lorawan.rx2fq.get());
delay(1000);
}
txp
This API allows the user to access the transmit power.
Highest power start from 0. Complete information about TXP parameter on each region can be found on RUI3 Appendix - LoRaWAN Regional Parameter (TX Power).
- EU868 / RU864 / KR920 / AS923 / CN470 Transmit power range of values is 0-7.
- US915 / AU915 / LA915 Transmit power range of values is 0-14.
- EU433 Transmit power range of values is 0-5.
- IN865 Transmit power range of values is 0-10.
RAKLorawan::txp
get()
This API allows the user to get the transmit power.
api.lorawan.txp.get();
Function | uint8_t get() |
---|---|
Returns | the LoRaWAN transmit power |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the transmit power %s\r\n", api.lorawan.txp.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The transmit power is %d\r\n", api.lorawan.txp.get());
delay(1000);
}
set()
This API allows the user to set the transmit power.
api.lorawan.txp.set(value);
Function | bool set(uint8_t value) |
---|---|
Parameters | value - the LoRaWAN transmit power |
Returns | TRUE for setting transmit power success FALSE for setting transmit power failure |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set the transmit power %s\r\n", api.lorawan.txp.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("The transmit power is %d\r\n", api.lorawan.txp.get());
delay(1000);
}
linkcheck
This API allows the user to verify network link status.
RAKLorawan::linkcheck
get()
This API allows the user to verify network link status.
api.lorawan.linkcheck.get();
Function | uint32_t get() |
---|---|
Returns | The mode of verifying network link status |
Return Values | Link Check setting - 0 link check disabled - 1 execute link check one time - 2 module will automatically execute a link check after every upload of data |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set Verifying network link status %s\r\n", api.lorawan.linkcheck.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("Network link status = %d\r\n", api.lorawan.linkcheck.get());
delay(1000);
}
set()
This API allows the user to set the network link status.
api.lorawan.linkcheck.set(value);
Function | bool set(uint8_t value) |
---|---|
Parameters | value - the mode of verifying network link status - 0 link check disabled - 1 execute link check one time - 2 module will automatically execute a link check after every upload of data |
Returns | bool |
Return Values | TRUE for setting mode of verifying network link status FALSE for setting mode of verifying network link status failure ) |
Click to view the code
void setup()
{
Serial.begin(115200);
Serial.printf("Set Verifying network link status %s\r\n", api.lorawan.linkcheck.set(1) ? "Success" : "Fail");
}
void loop()
{
Serial.printf("Network link status = %d\r\n", api.lorawan.linkcheck.get());
delay(1000);
}
timereq
This api allows the user to verify the status of timereq flag for next uplink and request a network time on the next uplink
get()
This api allows the user to get the status of timereq flag for next uplink
api.lorawan.timereq.get();
Function | uint8_t get() |
---|---|
Returns | The status of timereq flag for next uplink |
Return Values | Time request setting - 0 timereq flag is disable - 1 timereq flag is enable |
Click to view the code
void setup()
{
Serial.begin(115200);
api.lorawan.join();
delay(10000);
if (api.lorawan.njs.get() == 1) {
Serial.printf("Set timereq flag %s\r\n", api.lorawan.timereq.set(1) ? "Success" : "Fail");
}
}
void loop()
{
Serial.printf("Get timereq flag = %d\r\n", api.lorawan.timereq.get());
delay(1000);
}
set()
This api allows the user to enable the timereq flag for next uplink.
api.lorawan.timereq.set(value);
Function | bool set(uint8_t value) |
---|---|
Parameters | value - enable/disable time request - 0 time request disabled - 1 time request enabled |
Returns | bool |
Return Values | TRUE for setting timereq flag be enable FALSE for setting timereq flag be disable |
Click to view the code
void setup()
{
Serial.begin(115200);
api.lorawan.join();
delay(10000);
if (api.lorawan.njs.get() == 1) {
Serial.printf("Set timereq flag %s\r\n", api.lorawan.timereq.set(1) ? "Success" : "Fail");
}
}
void loop()
{
Serial.printf("Get timereq flag = %d\r\n", api.lorawan.timereq.get());
delay(1000);
}
Keys, IDs, and EUIs Management
appeui
This API views or changes the LoRaWAN APPEUI and uses it to set up the LoRaWAN connection.
This function can only work in OTAA mode.
RAKLorawan::appeui
get()
This API allows the user to get the global application identifier.
api.lorawan.appeui.get(buf, len);
Function | bool get(uint8_t * buf, uint32_t len) |
---|---|
Parameters | buf : the buffer to get AppEUI len : the length of AppEUI (must be 8 bytes) |
Returns | bool |
Return Values | TRUE for getting AppEUI successfully FALSE for setting AppEUI failure |
Click to view the code
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
void setup()
{
Serial.begin(115200);
api.lorawan.njm.set(RAK_LORA_OTAA); // Set LoRaWan join mode to OTAA
if(api.lorawan.appeui.set(node_app_eui, 8) == true)
Serial.println("LoRaWan AppEUI set success");
else
Serial.println("LoRaWan AppEUI set fail");
}
void loop()
{
uint8_t buff[8];
if(api.lorawan.appeui.get(buff, 8) == true) {
Serial.print("LoRaWan AppEUI = 0x");
for(int i = 0; i < 8; i++) {
Serial.printf("%02X", buff[i]);
}
Serial.println("");
} else {
Serial.println("LoRaWan APPEUI get fail");
}
delay(1000);
}
set()
This API allows the user to set the global application identifier.
api.lorawan.appeui.set(buf, len);
Function | bool set(uint8_t * buf, uint32_t len) |
---|---|
Parameters | buf : the buffer to set AppEUI len : the length of AppEUI (must be 8 bytes) |
Returns | bool |
Return Values | TRUE for setting AppEUI successfully FALSE for setting AppEUI failure |
Click to view the code
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
void setup()
{
Serial.begin(115200);
api.lorawan.njm.set(RAK_LORA_OTAA); // Set LoRaWan join mode to OTAA
if(api.lorawan.appeui.set(node_app_eui, 8) == true)
Serial.println("LoRaWan AppEUI set success");
else
Serial.println("LoRaWan AppEUI set fail");
}
void loop()
{
uint8_t buff[8];
if(api.lorawan.appeui.get(buff, 8) == true) {
Serial.print("LoRaWan AppEUI = 0x");
for(int i = 0; i < 8; i++) {
Serial.printf("%02X", buff[i]);
}
Serial.println("");
} else {
Serial.println("LoRaWan AppEUI get fail");
}
delay(1000);
}
appkey
This API views or changes the LoRaWAN APPKEY and uses it to setup the LoRaWAN connection.
This function can only work in OTAA mode.
RAKLorawan::appkey
get()
This API allows the user to get the application key.
api.lorawan.appkey.get(buf, len);
Function | bool get(uint8_t* buf, uint32_t len) |
---|---|
Parameters | buf : the buffer to get AppKey len : the length of AppKey (must be 16 bytes) |
Returns | bool |
Return Values | TRUE for getting AppKey successfully FALSE for getting AppKey failure |
Click to view the code
// OTAA Application Key MSB
uint8_t node_app_key[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3E};
void setup()
{
Serial.begin(115200);
api.lorawan.njm.set(RAK_LORA_OTAA); // Set LoRaWan join mode to OTAA
if(api.lorawan.appkey.set(node_app_key, 16) == true)
Serial.println("LoRaWan AppKey set success");
else
Serial.println("LoRaWan AppKey set fail");
}
void loop()
{
uint8_t buff[16];
if(api.lorawan.appkey.get(buff, 16) == true) {
Serial.print("LoRaWan AppKey = 0x");
for(int i = 0; i < 16; i++) {
Serial.printf("%02X", buff[i]);
}
Serial.println("");
} else {
Serial.println("LoRaWan AppKey get fail");
}
delay(1000);
}
set()
This API allows the user to set the application key.
api.lorawan.appkey.set(buf, len);
Function | bool set(uint8_t* buf, uint32_t len) |
---|---|
Parameters | buf : the buffer to set AppKey len : the length of AppKey (must be 16 bytes) |
Returns | bool |
Return Values | TRUE for setting AppKey successfully FALSE for setting AppKey failure |
Click to view the code
// OTAA Application Key MSB
uint8_t node_app_key[16] = {0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3E};
void setup()
{
Serial.begin(115200);
api.lorawan.njm.set(RAK_LORA_OTAA); // Set LoRaWan join mode to OTAA
if(api.lorawan.appkey.set(node_app_key, 16) == true)
Serial.println("LoRaWan AppKey set success");
else
Serial.println("LoRaWan AppKey set fail");
}
void loop()
{
uint8_t buff[16];
if(api.lorawan.appkey.get(buff, 16) == true) {
Serial.print("LoRaWan AppKey = 0x");
for(int i = 0; i < 16; i++) {
Serial.printf("%02X", buff[i]);
}
Serial.println("");
} else {
Serial.println("LoRaWan AppKey get fail");
}
delay(1000);
}
appskey
This API allows the user to get or set the application session key.
This function can only work in ABP mode.
api.lorawan.appskey.get(buf, len);
get()
This API allows the user to get the application session key.
bool get(uint8_t* buf, uint32_t len)
Function | bool get(uint8_t* buf, uint32_t len) |
---|---|
Parameters | buf : the buffer to get AppSKey len : the length of AppSKey (must be 16 bytes) |
Returns | bool |
Return Values | TRUE for getting AppSKey successfully FALSE for getting AppSKey failure |
Click to view the code
// ABP Application Session Key
uint8_t node_app_skey[16] = {0x25, 0xC4, 0xF1, 0xD1, 0x78, 0xC8, 0x8D, 0x01, 0xA8, 0x80, 0xC2, 0x79, 0xA7, 0x9F, 0x34, 0x3B};
void setup()
{
Serial.begin(115200);
api.lorawan.njm.set(RAK_LORA_ABP); // Set LoRaWan join mode to ABP
if(api.lorawan.appskey.set(node_app_skey, 16) == true)
Serial.println("LoRaWan AppSKey set success");
else
Serial.println("LoRaWan AppSKey set fail");
}
void loop()
{
uint8_t buff[16];
if(api.lorawan.appskey.get(buff, 16) == true) {
Serial.print("LoRaWan AppSKey = 0x");
for(int i = 0; i < 16; i++) {
Serial.printf("%02X", buff[i]);
}
Serial.println("");
} else {
Serial.println("LoRaWan AppSKey get fail");
}
delay(1000);
}
set()
This API allows the user to set the application session key.
api.lorawan.appskey.set(buf, len);
Function | bool set(uint8_t* buf, uint32_t len) |
---|---|
Parameters | buf : the buffer to set AppSKey len : the length of AppSKey (must be 16 bytes) |
Returns | bool |
Return Values | TRUE for setting AppSKey successfully FALSE for setting AppSKey failure |
Click to view the code
// ABP Application Session Key
uint8_t node_app_skey[16] = {0x25, 0xC4, 0xF1, 0xD1, 0x78, 0xC8, 0x8D, 0x01, 0xA8, 0x80, 0xC2, 0x79, 0xA7, 0x9F, 0x34, 0x3B};
void setup()
{
Serial.begin(115200);
api.lorawan.njm.set(RAK_LORA_ABP); // Set LoRaWan join mode to ABP
if(api.lorawan.appskey.set(node_app_skey, 16) == true)
Serial.println("LoRaWan AppSKey set success");
else
Serial.println("LoRaWan AppSKey set fail");
}
void loop()
{
uint8_t buff[16];
if(api.lorawan.appskey.get(buff, 16) == true) {
Serial.print("LoRaWan AppSKey = 0x");
for(int i = 0; i < 16; i++) {
Serial.printf("%02X", buff[i]);
}
Serial.println("");
} else {
Serial.println("LoRaWan AppSKey get fail");
}
delay(1000);
}