# LoRaWAN

# 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 AS923
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 = 8, ///< AS923
} 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;"

# Keys, IDs, and EUIs Management

# appeui

This API allows to view or change the LoRaWAN APPEUI and use it to set up the LoRaWAN connection.

RAKLorawan::appeui

# get()

This API allows the user to get the global application identifier.

bool get(uint8_t * buf, uint32_t len)
Syntax api.lorawan.appeui.get(buf, 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

 // 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.

bool set(uint8_t * buf, uint32_t len)
Syntax api.lorawan.appeui.set(buf, 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

    // 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 allows to view or change the LoRaWAN APPKEY and use it to setup the LoRaWAN connection.

RAKLorawan::appkey

# get()

This API allows the user to get the application key.

bool get(uint8_t* buf, uint32_t len)
Syntax api.lorawan.appkey.get(buf, 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

// 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.

bool set(uint8_t* buf, uint32_t len)
Syntax api.lorawan.appkey.set(buf, 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

// 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.

RAKLorawan::appskey

# get()

This API allows the user to get the application session key.

bool get(uint8_t* buf, uint32_t len)
Syntax api.lorawan.appskey.get(buf, 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

📝 NOTE

Syntax function can only work in ABP Mode.


// 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.

bool set(uint8_t* buf, uint32_t len)
Syntax api.lorawan.appskey.set(buf, 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

// 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);
}

# daddr

This API allows the user to access the device address.

RAKLorawan::daddr

# get()

This API allows the user to get the device address.

bool get(uint8_t* buf, uint32_t len)
Syntax api.lorawan.daddr.get(buf, len);
Parameters buf: the buffer to get the device address
len: the length of the device address (must be 4 bytes)
Returns bool
Return Values TRUE for getting device address successfully
FALSE for getting device address failure

📝 NOTE

The Syntax function can only work in ABP mode.


// ABP Device Address
uint8_t node_dev_addr[4] = {0x05, 0x05, 0x06, 0x06};

void setup()
{
    Serial.begin(115200);

    api.lorawan.njm.set(RAK_LORA_ABP); // Set LoRaWan join mode to ABP

    if(api.lorawan.daddr.set(node_dev_addr, 4) == true)
        Serial.println("LoRaWan device address set success");
    else
        Serial.println("LoRaWan device address set fail");
}

void loop()
{
    uint8_t buff[4];

    if(api.lorawan.daddr.get(buff, 4) == true) {
        Serial.print("LoRaWan device address = 0x");
        for(int i = 0; i < 4; i++) {
            Serial.printf("%02X", buff[i]);
        }
        Serial.println("");
    } else {
        Serial.println("LoRaWan device address get fail");
    }

    delay(1000);
}

# set()

This API allows the user to set the device address.

bool set(uint8_t* buf, uint32_t len)
Syntax api.lorawan.daddr.set(buf, len);
Parameters buf: the buffer to set the device address
len: the length of the device address (must be 4 bytes)
Returns bool
Return Values TRUE for setting device address successfully
FALSE for setting device address failure

// ABP Device Address
uint8_t node_dev_addr[4] = {0x05, 0x05, 0x06, 0x06};

void setup()
{
    Serial.begin(115200);

    api.lorawan.njm.set(RAK_LORA_ABP); // Set LoRaWan join mode to ABP

    if(api.lorawan.daddr.set(node_dev_addr, 4) == true)
        Serial.println("LoRaWan device address set success");
    else
        Serial.println("LoRaWan device address set fail");
}

void loop()
{
    uint8_t buff[4];

    if(api.lorawan.daddr.get(buff, 4) == true) {
        Serial.print("LoRaWan device address = 0x");
        for(int i = 0; i < 4; i++) {
            Serial.printf("%02X", buff[i]);
        }
        Serial.println("");
    } else {
        Serial.println("LoRaWan device address get fail");
    }

    delay(1000);
}

# deui

This API allows to view or change the LoRaWAN DEUI and use it to setup the LoRaWAN connection.

RAKLorawan::deui

# get()

This API allows the user to get the global end-device ID.

bool get(uint8_t* buf, uint32_t len)
Syntax api.lorawan.deui.get(buf, len);
Parameters buf: the buffer to get the device EUI
len: the length of the device EUI (must be 8 bytes)
Returns bool
Return Values TRUE for getting device EUI successfully
FALSE for getting device EUI failure
// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};

void setup()
{
    Serial.begin(115200);

    api.lorawan.njm.set(RAK_LORA_OTAA); // Set LoRaWan join mode to OTAA

    if(api.lorawan.deui.set(node_device_eui, 8) == true)
        Serial.println("LoRaWan device EUI set success");
    else
        Serial.println("LoRaWan device EUI set fail");
}

void loop()
{
    uint8_t buff[8];

    if(api.lorawan.deui.get(buff, 8) == true) {
        Serial.print("LoRaWan device EUI = 0x");
        for(int i = 0; i < 8; i++) {
            Serial.printf("%02X", buff[i]);
        }
        Serial.println("");
    } else {
        Serial.println("LoRaWan device EUI get fail");
    }

    delay(1000);
}

# set()

This API allows the user to set the global end-device ID.

bool set(uint8_t* buf, uint32_t len)
Syntax api.lorawan.deui.set(buf, len);
Parameters buf: the buffer to set the device EUI
len: the length of the device EUI (must be 8 bytes)
Returns bool
Return Values TRUE for setting device EUI successfully
FALSE for setting device EUI failure

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};

void setup()
{
    Serial.begin(115200);

    api.lorawan.njm.set(RAK_LORA_OTAA); // Set LoRaWan join mode to OTAA

    if(api.lorawan.deui.set(node_device_eui, 8) == true)
        Serial.println("LoRaWan device EUI set success");
    else
        Serial.println("LoRaWan device EUI set fail");
}

void loop()
{
    uint8_t buff[8];

    if(api.lorawan.deui.get(buff, 8) == true) {
        Serial.print("LoRaWan device EUI = 0x");
        for(int i = 0; i < 8; i++) {
            Serial.printf("%02X", buff[i]);
        }
        Serial.println("");
    } else {
        Serial.println("LoRaWan device EUI get fail");
    }

    delay(1000);
}

# netid

This API allows the user to access the network identifier (NetID).

RAKLorawan::netid

# get()

This API allows the user to get the network identifier (NetID).

bool get(uint8_t* buf, uint32_t len)
Syntax api.lorawan.netid.get(buf, len);
Parameters buf: the buffer to get the network identifier (NetID)
len: the length of the network identifier (NetID) (must be 3 bytes)
Returns bool
Return Values TRUE for getting the network identifier (NetID) successfully
FALSE for getting the network identifier (NetID) failure

📝 NOTE

Even though the length of network identifier(NetID) is 3 bytes, you should give 4-byte buffer for natural alignment.


// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t buff[4];

    if(api.lorawan.netid.get(buff, 4) == true) {
        Serial.print("LoRaWan network identifier(NetID) = 0x");
        for(int i = 0; i < 3; i++) {
            Serial.printf("%02X", buff[i]);
        }
        Serial.println("");
    } else {
        Serial.println("LoRaWan network identifier(NetID) get fail");
    }

    delay(1000);
}

# nwkskey

This API allows the user to get or set the network session key.

RAKLorawan::nwkskey

# get()

This API allows the user to get the network session key.

bool get(uint8_t* buf, uint32_t len)
Syntax api.lorawan.nwkskey.get(buf, len);
Parameters buf: the buffer to get the network session key
len: the length of the network session key (must be 16 bytes)
Returns bool
Return Values TRUE for getting the network session key successfully
FALSE for getting the network session key failure

📝 NOTE

This function can only work in ABP mode0.


// ABP Network Session Key
uint8_t node_nwk_skey[16] = {0xD6, 0x03, 0x37, 0xAC, 0x97, 0x4C, 0x43, 0x2F, 0xF3, 0x7A, 0xF9, 0xA7, 0x9B, 0xE8, 0x50, 0xF7};

void setup()
{
    Serial.begin(115200);

    api.lorawan.njm.set(RAK_LORA_ABP); // Set LoRaWan join mode to ABP

    if(api.lorawan.nwkskey.set(node_nwk_skey, 16) == true)
        Serial.println("LoRaWan network session key set success");
    else
        Serial.println("LoRaWan network session key set fail");
}

void loop()
{
    uint8_t buff[16];

    if(api.lorawan.nwkskey.get(buff, 16) == true) {
        Serial.print("LoRaWan network session key = 0x");
        for(int i = 0; i < 16; i++) {
            Serial.printf("%02X", buff[i]);
        }
        Serial.println("");
    } else {
        Serial.println("LoRaWan network session key get fail");
    }

    delay(1000);
}

# set()

This API allows the user to set the network session key.

bool set(uint8_t* buf, uint32_t len)
Syntax api.lorawan.nwkskey.set(buf, len);
Parameters buf: the buffer to set the network session key
len: the length of the network session key (must be 16 bytes)
Returns TRUE for setting the network session key successfully
FALSE for setting the network session key failure

// ABP Network Session Key
uint8_t node_nwk_skey[16] = {0xD6, 0x03, 0x37, 0xAC, 0x97, 0x4C, 0x43, 0x2F, 0xF3, 0x7A, 0xF9, 0xA7, 0x9B, 0xE8, 0x50, 0xF7};

void setup()
{
    Serial.begin(115200);

    api.lorawan.njm.set(RAK_LORA_ABP); // Set LoRaWan join mode to ABP

    if(api.lorawan.nwkskey.set(node_nwk_skey, 16) == true)
        Serial.println("LoRaWan network session key set success");
    else
        Serial.println("LoRaWan network session key set fail");
}

void loop()
{
    uint8_t buff[16];

    if(api.lorawan.nwkskey.get(buff, 16) == true) {
        Serial.print("LoRaWan network session key = 0x");
        for(int i = 0; i < 16; i++) {
            Serial.printf("%02X", buff[i]);
        }
        Serial.println("");
    } else {
        Serial.println("LoRaWan network session key get fail");
    }

    delay(1000);
}

# Joining and Sending Data on LoRa® Network

# rety

This API gets or sets the times of retransmission of Confirm packet data.

RAKLorawan::rety

# get()

This API allows to get the times of retransmission of Confirm packet data.

uint8_t get()	
Syntax api.lorawan.rety.get();
Returns the retry times for retransmission
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set the times of retransmission %s\n\r", api.lorawan.rety.set(1) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("The time of retransmission = %d\n\r", api.lorawan.rety.get());

    delay(1000);
}

# set()

This API allows to set the times of retransmission of Confirm packet data.

bool set(uint8_t value)	
Syntax api.lorawan.rety.set(value);
Parameters value - the retry times for retransmission
Returns bool
Return Values TRUE for setting retry time success
FALSE for setting retry times failure

📝 NOTE

Can only input 0 ~ 7 times.

void setup()
{
    Serial.begin(115200);

    Serial.printf("Set the times of retransmission %s\n\r", api.lorawan.rety.set(1) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("The times of retransmission = %d\n\r", api.lorawan.rety.get());

    delay(1000);
}

# cfm

This API allows the user to access the notification on received data coming from the network.

RAKLorawan::cfm

# get()

This API allows the user to get the notification on received data coming from the network.

bool get()
Syntax api.lorawan.cfm.get();
Returns bool
Return Values TRUE - LoRaWAN uplink is not on confirm mode
FALSE - LoRaWAN uplink is on confirm mode

void setup()
{
    Serial.begin(115200);
    
    Serial.printf("Set confirm mode status %s\n\r", api.lorawan.cfm.set(1) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("Packet is %s\n\r", api.lorawan.cfm.get() ? "CONFIRMED" : "UNCONFIRMED");

    delay(1000);
}

# set()

This API allows the user to set the notification on received data coming from the network.

bool set(bool value)
Syntax api.lorawan.cfm.set(value);
Parameters value: the mode of confirm mode to set
Returns bool
Return Values TRUE for setting confirm mode success
FALSE for setting confirm mode failure

void setup()
{
    Serial.begin(115200);

    Serial.printf("Set confirm mode status %s\n\r", api.lorawan.cfm.set(1) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("Packet is %s\n\r", api.lorawan.cfm.get() ? "CONFIRMED" : "UNCONFIRMED");

    delay(1000);
}

# cfs

RAKLorawan::cfs

# get()

This API allows the user to access the status of the last SEND command.

bool get()
Syntax api.lorawan.cfs.get();
Returns TRUE: Confirm success
FALSE: Confirm failure

📝 NOTE

This API can only work when confirm mode is on.

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t payload[] = "example";
    
    if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
        Serial.println("Send Success");
        Serial.printf("Send confirm %s\r\n", api.lorawan.cfs.get() ? "Success" : "Fail");
    
    } else {
        Serial.println("Send fail");

    }
    
    delay(5000);
}

# njm

RAKLorawan::njm

This API allows the user to access the network join mode.

# get()

This API allows the user to get the network join mode.

bool get()
Syntax api.lorawan.njm.get();
Returns bool
Return Values TRUE: OTAA
FALSE: ABP

void setup()
{
    Serial.begin(115200);

    Serial.printf("Set network join mode %s\n\r", api.lorawan.njm.set(1) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("Network join mode is %s\n\r", api.lorawan.cfm.get() ? "OTAA" : "ABP");

    delay(1000);
}

# set()

This API allows the user to set the network join mode.

bool set(bool value)
Syntax api.lorawan.njm.set(value);
Parameters value: the mode of network join mode
ABP - 0
OTAA - 1
Returns bool
Return Values TRUE for setting network join mode success
FALSE for setting network join mode failure

void setup()
{
    Serial.begin(115200);

    Serial.printf("Set network join mode %s\n\r", api.lorawan.njm.set(1) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("Network join mode is %s\n\r", api.lorawan.njm.get() ? "OTAA" : "ABP");

    delay(1000);
}

# njs

This API allows the user to access the current status of the LoRa® link.

RAKLorawan::njs

# get()

This API allows the user to get the current status of the LoRa® link.

bool get()
Syntax api.lorawan.njs.get();
Returns bool
Return Values TRUE: Network join
FALSE: Network not join

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
}

# join()

This API does a join request to the network.

bool join()
Syntax api.lorawan.join();
Returns bool
Return Values TRUE for join success
FALSE for join failure

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
}

# send()

This API provides the way to send data on a dedicated port number.

bool send(uint8_t length,uint8_t * payload, uint8_t fport, bool confirm = true, uint8_t retry)
Syntax api.lorawan.send(length, payload, fport);
api.lorawan.send(length, payload, fport, confirm);
api.lorawan.send(length, payload, fport, confirm, retry);
Parameters length - the length of the payload
payload - the date to uplink
fport - allow 1 ~ 223
confirm - Override cfm setting to get confirm message from gateway (just for this time)
retry - Override retry setting to retry if sending failed (just for this time)
Returns bool
Return Values TRUE for sending uplink success
FALSE for sending uplink

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t payload[] = "example";

    if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
        Serial.println("Send Success");
    } else {
        Serial.println("Send fail");

    }

    delay(5000);
}

# lpsend()

This API provides a way to send long packet (1024 bytes) text data.

bool lpsend	(uint8_t port, bool ack, uint8_t * payload, int	length)	
Syntax api.lorawan.lpsend(port, ack, payload, length);
Parameters port - application port to be transmitted
ack - indicate this is a confirmed message or not
payload the date you want to send
length - the length of the payload
Returns bool
Return Values TRUE for sending data success
FALSE for sending data failure

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t payload[] = "12345678901234567890";

    if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
        Serial.println("Send Success");
    } else {
        Serial.println("Send fail");

    }

    delay(5000);
}

# registerRecvCallback()

This API is used to register a callback function, so that application can be notified on receiving LoRaWAN data.

bool registerRecvCallback(service_lora_recv_cb callback)
Syntax api.lorawan.registerRecvCallback(service_lora_recv_cb callback);
Parameters The callback function
Returns bool
Return Values TRUE for setting callback function success
FALSE for setting callback function failure

void recv_cb(SERVICE_LORA_RECEIVE_T *data) {
  Serial.println("Something received!");
  for (int i = 0 ; i < data->BufferSize ; i++) {
    Serial.printf("%x", data->Buffer[i]);
  }
  Serial.print("\r\n");
}

void join_cb(int32_t status) {
  Serial.printf("Join status: %d\r\n", status);
}

void send_cb(int32_t status) {
  Serial.printf("Send status: %d\r\n", status);
}

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();
    api.lorawan.registerRecvCallback(recv_cb);
api.lorawan.registerJoinCallback(join_cb);
    api.lorawan.registerSendCallback(send_cb);

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t payload[] = "example";

    if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
        Serial.println("Send Success");
    } else {
        Serial.println("Send fail");

    }

    delay(5000);
}

# registerJoinCallback()

This API is used to register a callback function, so that application can be notified when joining process is done.

bool registerJoinCallback(service_lora_join_cb callback)	
Syntax api.lorawan.registerJoinCallback(service_lora_join_cb callback);
Parameters The callback function
Returns bool
Return Values TRUE for setting callback function success
FALSE for setting callback function failure
void recv_cb(SERVICE_LORA_RECEIVE_T *data) {
  Serial.println("Something received!");
  for (int i = 0 ; i < data->BufferSize ; i++) {
    Serial.printf("%x", data->Buffer[i]);
  }
  Serial.print("\r\n");
}

void join_cb(int32_t status) {
  Serial.printf("Join status: %d\r\n", status);
}

void send_cb(int32_t status) {
  Serial.printf("Send status: %d\r\n", status);
}

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();
    api.lorawan.registerRecvCallback(recv_cb);
api.lorawan.registerJoinCallback(join_cb);
    api.lorawan.registerSendCallback(send_cb);

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t payload[] = "example";

    if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
        Serial.println("Send Success");
    } else {
        Serial.println("Send fail");

    }

    delay(5000);
}

# registerSendCallback()

This API is used to register a callback function, so that application can be notified when uplink process is done.

bool registerSendCallback(service_lora_send_cb callback)	
Syntax api.lorawan.registerSendCallback(service_lora_send_cb callback);
Parameters The callback function
Returns bool
Return Values TRUE for setting callback function success
FALSE for setting callback function failure

void recv_cb(SERVICE_LORA_RECEIVE_T *data) {
  Serial.println("Something received!");
  for (int i = 0 ; i < data->BufferSize ; i++) {
    Serial.printf("%x", data->Buffer[i]);
  }
  Serial.print("\r\n");
}

void join_cb(int32_t status) {
  Serial.printf("Join status: %d\r\n", status);
}

void send_cb(int32_t status) {
  Serial.printf("Send status: %d\r\n", status);
}

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();
    api.lorawan.registerRecvCallback(recv_cb);
api.lorawan.registerJoinCallback(join_cb);
    api.lorawan.registerSendCallback(send_cb);

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t payload[] = "example";

    if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
        Serial.println("Send Success");
    } else {
        Serial.println("Send fail");

    }

    delay(5000);
}

# LoRa® Network Management

# adr

This API allows the user to access the adaptive data rate.

RAKLorawan::adr

📝 NOTE

The default value of the ADR is 1 (enabled).

# get()

This API allows the user to get the adaptive data rate.

bool get()
Syntax api.lorawan.adr.get();
Returns bool
Return Values TRUE - enable adaptive data rate
FALSE - disable adaptive data rate

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 set the adaptive data rate.

bool set(bool value)
Syntax api.lorawan.adr.set(value);
Parameters value - the status of adaptive data rate
Returns bool
Return Values TRUE for setting status of adr success
FALSE for setting status of adr failure

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.

uint8_t get()
Syntax api.lorawan.deviceClass.get();
Returns the LoRaWan class (Type: int)
Return Values 0 - Class A
1 - Class B
2 - Class C

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.

bool set(uint8_t value)
Syntax api.lorawan.deviceClass.set(value);
Parameters value - the LoRaWAN class
Returns bool
Return Values TRUE for setting LoRaWAN class success
FALSE for setting LoRaWAN class failure

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 access the duty cycle parameter

RAKLorawan::dcs

# get()

This API allows the user to get the duty cycle parameter.

bool get()
Syntax api.lorawan.dcs.get();
Returns bool
Return Values TRUE - enable duty cycle
FALSE - disable duty cycle

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 set the duty cycle parameter.

bool set(uint8_t dutyCycle)	
Syntax api.lorawan.dcs.set(dutyCycle);
Parameters dutyCycle - the LoRaWAN duty cycle
Returns bool
Return Values TRUE for setting duty cycle success
FALSE for setting duty cycle fail

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.

RAKLorawan::dr

# get()

This API allows the user to get the data rate.

uint8_t get()
Syntax api.lorawan.dr.get();
Returns the data rate

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.

bool set(uint8_t value)
Syntax api.lorawan.dr.set(value);
Parameters value - the data rate
Returns bool
Return Values TRUE for setting data rate success
FALSE for setting date rate failure

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.

int get()
Syntax api.lorawan.jn1dl.get();
Returns the join delay on RX window 1 (Type: int)

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.

bool set(int value)
Syntax api.lorawan.jn1dl.set(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

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.

int get()
Syntax api.lorawan.jn2dl.get();
Returns the join delay on RX window 2 (Type: bool)

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.

bool set(int value)
Syntax api.lorawan.jn2dl.set(value);
Parameters value - the join delay on RX window 2
Returns bool
Return Values TRUE for setting join delay success
FALSE for setting join delay failure
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.

bool get()
Syntax api.lorawan.pnm.get();
Returns bool
Return Values TRUE: On
FALSE: Off

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.

bool set(bool value)
Syntax api.lorawan.pnm.set(value);
Parameters value - the public network mode
Returns bool
Return Values TRUE for setting public network mode success
FALSE for setting public network mode failure

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.

int get()
Syntax api.lorawan.rx1dl.get();
Returns the delay of the received window 1

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.

bool set(int value)
Syntax api.lorawan.rx1dl.set(value);
Parameters value - the delay of the received window 1
Returns bool
Return Values TRUE for setting delay success
FALSE for setting delay failure

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

int get()
Syntax api.lorawan.rx2dl.get();
Returns the delay of the received window 2
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

bool set(int value)
Syntax api.lorawan.rx2dl.set(value)
Parameters value - the delay of the received window 2
Returns bool
Return Values TRUE for setting delay success
FALSE for setting delay failure
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.

uint8_t get()
Syntax api.lorawan.rx2dr.get();
Returns the data rate of received window 2
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.

bool set(uint8_t value)
Syntax api.lorawan.rx2dr.set(value);
Parameters value - the date rate of received window 2
Returns bool
Return Values TRUE for setting data rate success
FALSE for setting data rate failure
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.

long get()
Syntax api.lorawan.rx2fq.get();
Returns the frequency of the received window 2
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.

RAKLorawan::txp

# get()

This API allows the user to get the transmit power.

uint8_t get()
Syntax api.lorawan.txp.get();
Returns the LoRaWAN transmit power

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.

bool set(uint8_t value)
Syntax api.lorawan.txp.set(value);
Parameters value - the LoRaWAN transmit power
Returns TRUE for setting transmit power success
FALSE for setting transmit power failure
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.

uint32_t get()
Syntax api.lorawan.linkcheck.get();
Returns The mode of verifying network link status
Return Values 0 disable link check
1 execute link check one time
2 module will automatically execute one time link check after every upload of data
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.

bool set(uint8_t value)	
Syntax api.lorawan.linkcheck.set(value);
Parameters value - the mode of verifying network link status
Returns bool
Return Values TRUE for setting mode of verifying network link status
FALSE for setting mode of verifying network link status failure )
  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);
  }

# Class B Mode

# pgslot

This API allows the user to get or set the unicast ping slot periodicity.

RAKLorawan::pgslot

# get()

This API allows the user to get the unicast ping slot periodicity.

uint8_t get()
Syntax api.lorawan.pgslot.get();
Returns the ping slot periodicity
// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.deviceClass.set(1);
    Serial.printf("Set the unicast ping slot periodicity %s\r\n", api.lorawan.pgslot.set(0) ? "Success" : "Fail");
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    Serial.printf("The unicast ping slot periodicity is %d\r\n", api.lorawan.pgslot.get());
    delay(1000);
}

# set()

This API allows the user to set the unicast ping slot periodicity.

bool set(uint8_t value)
Syntax api.lorawan.pgslot.set(value);
Parameters value - the unicast ping slot periodicity
Returns bool
Return Values TRUE for setting ping slot periodicity success
FALSE for setting ping slot periodicity failure
// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.deviceClass.set(1);
    Serial.printf("Set the unicast ping slot periodicity %s\r\n", api.lorawan.pgslot.set(0) ? "Success" : "Fail");
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    Serial.printf("The unicast ping slot periodicity is %d\r\n", api.lorawan.pgslot.get());
    delay(1000);
}

# bfreq

This API allows the user to access the current beacon (default broadcast) frequency

RAKLorawan::bfreq

# get()

This API allows the user to access the current beacon (default broadcast) frequency.

float get()
Syntax api.lorawan.bfreq.get();
Returns the current beacon frequency (Type: long)
// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.deviceClass.set(1);
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    Serial.printf("The current beacon frequency =  %.0f\r\n", api.lorawan.bfreq.get());
    delay(1000);
}

# btime

This API allows the user to access the current beacon time

RAKLorawan::btime

# get()

This API allows the user to access the current beacon time.

long get()
Syntax api.lorawan.btime.get()
Returns the current beacon time(b)
// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.deviceClass.set(1);
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    Serial.printf("The current beacon time = %l\r\n", api.lorawan.btime.get());
    delay(1000);
}

# bgw

This API allows the user to access the gateway GPS coordinate, NetID and GwID

RAKLorawan::bgw

# get()

This API allows the user to access the gateway GPS coordinate, NetID, and GwID.

beacon_bgw_t get()
Syntax api.lorawan.bgw.get();
Returns beacon_bgw_t
beacon_bgw_t beaconBGW;

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
  //Serial.begin(115200);

  api.lorawan.appeui.set(node_app_eui, 8);
  api.lorawan.appkey.set(node_app_key, 16);
  api.lorawan.deui.set(node_device_eui, 8);

  api.lorawan.band.set(4);
  api.lorawan.deviceClass.set(1);
  api.lorawan.njm.set(1);
  api.lorawan.join();

  //Wait for Join success 
  while (api.lorawan.njs.get() == 0)
  {
    Serial.print("Waiting for Lorawan join...");
    api.lorawan.join();
    delay(10000);
  }
}

void loop()
{
  beaconBGW = api.lorawan.bgw.get();

  Serial.printf("GPS Coordinate = %u\r\n", (unsigned int)beaconBGW.GPS_coordinate);
  Serial.printf("Latitude = %f\r\n", (float)beaconBGW.latitude*(float)90/(float)8388607);
  Serial.printf("longitude = %f\r\n", (float)beaconBGW.longitude*(float)180/(float)8388607);
  Serial.printf("Net ID = %u\r\n", (unsigned int)beaconBGW.net_ID);
  Serial.printf("Gateway ID = %u\r\n", (unsigned int)beaconBGW.gateway_ID);

  delay(1000);
}

# ltime()

This API allows the user to access the local time in a UTC format

RAKLorawan::bgw

# get()

This API allows the user to get the local time in a UTC format.

string get()
Syntax api.lorawan.ltime.get();
Returns the local time in a UTC format (Type: bool)
// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.deviceClass.set(1);
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    Serial.printf("The local time(UTC) is %s\r\n", api.lorawan.ltime.get().c_str());
    delay(1000);
}

# Information

# rssi

This API allows the user to access the RSSI on reception

RAKLorawan::rssi

📝 NOTE

When the connection is successful, get the RSSI of the last received packet.

# get()

This API allows the user to access the RSSI on reception.

int get()
Syntax api.lorawan.rssi.get();
Returns the RSSI on reception (Type: int)
// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t payload[] = "example";

    if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
        Serial.println("Send Success");
    Serial.printf("LoRaWan RSSI = %d\r\n", api.lorawan.rssi.get());

    } else {
        Serial.println("Send fail");
    }

    delay(5000);
}

# snr

This API allows the user to access the SNR of the last received packet

RAKLorawan::snr

📝 NOTE

When the connection is successful, get the SNR of the last received packet.

# get()

This API allows the user to get the SNR of the last received packet.

int get()
Syntax api.lorawan.snr.get();
Returns the SNR of the last received packet (Type: int)
// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};

void setup()
{
    Serial.begin(115200);

    api.lorawan.appeui.set(node_app_eui, 8);
    api.lorawan.appkey.set(node_app_key, 16);
    api.lorawan.deui.set(node_device_eui, 8);

    api.lorawan.band.set(4);
    api.lorawan.njm.set(1);
    api.lorawan.join();

    //wait for Join success
    while (api.lorawan.njs.get() == 0)
    {
      Serial.print("Waiting for Lorawan join...");
      api.lorawan.join();
      delay(10000);
    }
}

void loop()
{
    uint8_t payload[] = "example";

    if (api.lorawan.send(sizeof(payload), payload, 129, true, 1)) {
        Serial.println("Send Success");
        Serial.printf("LoRaWan SNR = %d\r\n", api.lorawan.snr.get());

    } else {
        Serial.println("Send fail");
    }

    delay(5000);
}

# ver

This API allows the user to get the LoRaWAN version.

RAKLorawan::ver

# get()

This API allows the user to get the LoRaWAN version.

string get()
Syntax api.lorawan.ver.get();
Returns the LoRaWAN version (Type: string)
void setup()
{
    Serial.begin(115200);
}

void loop()
{
    Serial.printf("The LoRaWan version is %s\r\n", api.lorawan.ver.get().c_str());
    delay(1000);
}

# arssi()

This API can access all open channel rssi.

bool arssi(RAK_LORA_chan_rssi * iterator)	
Syntax api.lorawan.arssi(chan_arssi);
Parameters chan_arssi - the structure array to store arssi
Returns bool
Return Values TRUE for getting arssi success
Fail for getting arssi failure
// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x03};
// 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, 0x3C};
     
void setup()
{
  Serial.begin(115200);

  api.lorawan.appeui.set(node_app_eui, 8);
  api.lorawan.appkey.set(node_app_key, 16);
  api.lorawan.deui.set(node_device_eui, 8);
  api.lorawan.band.set(4);

  api.lorawan.njm.set(1);
  api.lorawan.join();
  
  //Wait for Join success
  while (api.lorawan.njs.get() == 0)
  {
    Serial.print("Waiting for Lorawan join...");
    api.lorawan.join();
    delay(10000);
  }
}

void loop()
{
  RAK_LORA_chan_rssi chan_arssi;

  Serial.print("Get All open channel RSSI =");
  while (api.lorawan.arssi(&chan_arssi) == true) {
    if (chan_arssi.mask != 0) {
      Serial.printf("channel : %d,mask : %d, rssi : %d\r\n", chan_arssi.chan, chan_arssi.mask, chan_arssi.rssi);
    }
  }
  Serial.print("\r\n");

  delay(5000);
} 

# Supplement

# mask

This API configures the channel of the device by setting the hexadecimal channel mask.

RAKLorawan::mask

# get()

This API allows the user to get the channel mask, close or open the channel.

bool get(uint16_t * buff)	
Syntax api.lorawan.mask.get(buff);
Parameters buff - the buffer to store channel mask
Returns bool
Return Values TRUE for getting channel mask success
FALSE for getting channel mask failure
uint16_t maskBuff = 0x0003;

void setup()
{
    Serial.begin(115200);

    api.lorawan.band.set(5);
    Serial.printf("Set channel mask %s\r\n", api.lorawan.mask.set(&maskBuff) ? "Success" : "Fail");

}

void loop()
{
    
    Serial.printf("Get channel mask %s\r\n", api.lorawan.mask.get(&maskBuff) ? "Success" : "Fail");
    Serial.printf("Channel mask = %04X\r\n", maskBuff);
    delay(1000);
}

# set()

This API allows the user to set the channel mask, close or open the channel.

bool set(uint16_t * value)	
Syntax api.lorawan.mask.set(value);
Parameters value - the buffer to set the channel mask
Returns bool
Return Values TRUE for setting channel mask success
FALSE for setting channel mask failure
uint16_t maskBuff = 0x0003;

void setup()
{
    Serial.begin(115200);

    api.lorawan.band.set(5);
    Serial.printf("Set channel mask %s\r\n", api.lorawan.mask.set(&maskBuff) ? "Success" : "Fail");

}

void loop()
{

    Serial.printf("Get channel mask %s\r\n", api.lorawan.mask.get(&maskBuff) ? "Success" : "Fail");
    Serial.printf("Channel mask = %04X\r\n", maskBuff);
    delay(1000);
}

# band

This API set number corresponding to active regions.

RAKLorawan::band

📝 NOTE

0: EU433
1: CN470
2: RU864
3: IN865
4: EU868
5: US915
6: AU915
7: KR920
8: AS923

# get()

This API gets the number corresponding to active regions.

int32_t get()	
Syntax api.lorawan.band.get();
Returns the active region
Return Values 0 - EU433
1 - CN470
2 - RU864
3 IN865
4 - EU868
5 - US915
6 - AU915
7 - KR920
8 - AS923
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set LoRa region %s\r\n", api.lorawan.band.set(4) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("LoRa region = %d\r\n", api.lorawan.band.get());

    delay(1000);
}
# set()

This API set number corresponding to active regions.


bool set(uint8_t value)	
Syntax api.lorawan.band.set(value);
Parameters value - the active region to set
Returns bool
Return Values TRUE for setting active region success
FALSE for setting active region failure
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set LoRa region %s\r\n", api.lorawan.band.set(4) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("LoRa region = %d\r\n", api.lorawan.band.get());

    delay(1000);
}

# P2P Instructions

# nwm

Switch to point-to-point mode, or LoRaWAN mode, or FSK mode [0:Point to point, 1:LoRaWAN, 2:FSK]

RAKLorawan::nwm

# get()

This API allows to get the network working mode (0 = P2P, 1 = LoRaWAN, 2 = FSK).

int get()
Syntax api.lorawan.nwm.get();
Returns the network working mode
Return Values 0 - P2P mode
1 - LoRaWAN mode
2 - FSK mode
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set the network working mode %s\r\n", api.lorawan.nwm.set(1) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("Network working mode = %s\r\n", api.lorawan.nwm.get() ? "LoRaWan" : "P2P");

    delay(1000);
}

# set()

This API allows to set the network working mode (0 = P2P, 1 = LoRaWAN, 2 = FSK).


bool set(uint8_t value)	
Syntax api.lorawan.nwm.set(value));
Parameters value - the network working mode
Returns bool
Return Values TRUE for setting network working mode success
FALSE for setting network working mode failure

void setup()
{
    Serial.begin(115200);

    Serial.printf("Set the network working mode %s\r\n", api.lorawan.nwm.set(1) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("Network working mode = %s\r\n", api.lorawan.nwm.get() ? "LoRaWan" : "P2P");

    delay(1000);
}

# pfreq

This API provides configuration frequency for the P2P mode.

RAKLorawan::pfreq

# get()

This API allows to get the P2P frequency.

uint32_t get()
Syntax api.lorawan.pfreq.get();
Returns The frequency for P2P mode
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");   
    Serial.printf("Set P2P mode frequency %s\r\n", api.lorawan.pfreq.set(868000000) ? "Success" : "Fail");   
}

void loop()
{
    Serial.printf("P2P mode frequency = %d\r\n", api.lorawan.pfreq.get());

    delay(1000);
}

# set()

This API allows to set the P2P frequency.

bool set(uint32_t value)	
Syntax api.lorawan.pfreq.set(value);
Parameters value - the frequency for P2P mode
Returns bool
Return Values TRUE for setting frequency success
FALSE for setting frequency failure
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode frequency %s\r\n", api.lorawan.pfreq.set(868000000) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("P2P mode frequency = %d\r\n", api.lorawan.pfreq.get());

    delay(1000);
}

# psf

This API provides a configuration Spreading Factor for the P2P mode.

RAKLorawan::psf

# get()

This API allows to get P2P Spreading Factor (6, 7, 8, 9, 10, 11, 12).

uint8_t get()	
Syntax api.lorawan.psf.get();
Returns The P2P spreading factor
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode spreading factor %s\r\n", api.lorawan.psf.set(12) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("P2P mode spreading factor = %d\r\n", api.lorawan.psf.get());

    delay(1000);
}

# set()

This API allows to set P2P Spreading Factor (6,7, 8, 9, 10, 11, 12).

bool set(uint8_t value)	
Syntax api.lorawan.psf.set(value);
Parameters value - the P2P spreading factor
Returns bool
Return Values TRUE for setting P2P spreading factor success
FALSE for setting P2P spreading factor failure
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode spreading factor %s\r\n", api.lorawan.psf.set(12) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("P2P mode spreading factor = %d\r\n", api.lorawan.psf.get());

    delay(1000);
}

# pbw

This API provides configuration bandwidth for the P2P mode.

RAKLorawan::pbw

# get()

This API allows to get P2P bandwidth (125, 250, 500).

uint32_t get()
Syntax api.lorawan.pbw.get();
Returns The P2P bandwidth
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode bandwidth %s\r\n", api.lorawan.pbw.set(125) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("P2P mode bandwidth = %d\r\n", api.lorawan.pbw.get());

    delay(1000);
}

# set()

This API allow to set P2P Bandwidth (125, 250, 500).

bool set(uint32_t value)
Syntax api.lorawan.pbw.set(value);
Parameters value - the P2P bandwidth
Returns bool
Return Values TRUE for setting P2P bandwidth success
FALSE for setting P2P bandwidth failure
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode bandwidth %s\r\n", api.lorawan.pbw.set(125) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("P2P mode bandwidth = %d\r\n", api.lorawan.pbw.get());

    delay(1000);
}

# pcr

This API provides the configuration code rate for the P2P mode.

RAKLorawan::pcr

# get()

This API allows to get code rate for the P2P mode.

uint8_t get()
Syntax api.lorawan.pcr.get();
Returns The code rate
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode code rate %s\r\n", api.lorawan.pcr.set(0) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("P2P mode code rate = %d\r\n", api.lorawan.pcr.get());

    delay(1000);
}

# set()

This API allows to set code rate for the P2P mode.

bool set(uint8_t value)	
Syntax api.lorawan.pcr.set(value);
Parameters value - the code rate for P2P mode
Returns bool
Return Values TRUE for setting code rate success
FALSE for setting code rate failure
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode code rate %s\r\n", api.lorawan.pcr.set(0) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("P2P mode code rate = %d\r\n", api.lorawan.pcr.get());

    delay(1000);
}

# ppl

This API provides configuration Preamble Length for the P2P mode.

RAKLorawan::ppl

# get()

This API allows to get P2P Preamble Length (2-65535).

uint16_t get()
Syntax api.lorawan.ppl.get();
Returns The Preamble length
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode preamble length %s\r\n", api.lorawan.ppl.set(8) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("P2P mode preamble length = %d\r\n", api.lorawan.ppl.get());

    delay(1000);
}

# set()

This API allows to set P2P Preamble Length (2-65535).

bool set(uint16_t value)	
Syntax api.lorawan.ppl.set(value);
Parameters value - the P2P preamble length(2-65536)
Returns TRUE for setting P2P preamble length success
FALSE for setting preamble length fail (Type: bool)
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode preamble length %s\r\n", api.lorawan.ppl.set(8) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("P2P mode preamble length = %d\r\n", api.lorawan.ppl.get());

    delay(1000);
}

# ptp

This API provides configuration power for the P2P mode.

RAKLorawan::ptp

# get()

This API allows to get P2P TX Power (5-22).

Syntax api.lorawan.ptp.get();
Returns The Tx power for P2P mode
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode tx power %s\r\n", api.lorawan.ptp.set(22) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("P2P mode tx power = %d\r\n", api.lorawan.ptp.get());

    delay(1000);
}

# set()

This API allows to set P2P TX Power (5-22).

bool set(uint8_t value)	
Syntax api.lorawan.ptp.set(value);
Parameters value - the P2P Tx power
Returns bool
Return Values TRUE for setting P2P Tx power success
FALSE for setting P2P Tx power failure
void setup()
{
    Serial.begin(115200);

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode tx power %s\r\n", api.lorawan.ptp.set(22) ? "Success" : "Fail");
}

void loop()
{
    Serial.printf("P2P mode tx power = %d\r\n", api.lorawan.ptp.get());

    delay(1000);
}

# encry

This API configures P2P mode encryption.

RAKLorawan::encry

# get()

This API allows to get the status of P2P mode encryption.

bool get()	
Syntax api.lorawan.encry.get();
Returns bool
Return Values TRUE: P2P mode encryption is enable
FALSE: P2P mode encryption is disable
long startTime;
uint8_t node_encrypt_key[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
uint8_t encrypt_buff[8];

void setup()
{
    Serial.begin(115200);
    startTime = millis();
  
    Serial.println("P2P Start");
    
    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode frequency %s\r\n", api.lorawan.pfreq.set(868000000) ? "Success" : "Fail");
    Serial.printf("Set P2P mode spreading factor %s\r\n", api.lorawan.psf.set(12) ? "Success" : "Fail");
    Serial.printf("Set P2P mode bandwidth %s\r\n", api.lorawan.pbw.set(125) ? "Success" : "Fail");
    Serial.printf("Set P2P mode code rate %s\r\n", api.lorawan.pcr.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode preamble length %s\r\n", api.lorawan.ppl.set(8) ? "Success" : "Fail");
    Serial.printf("Set P2P mode tx power %s\r\n", api.lorawan.ptp.set(22) ? "Success" : "Fail");
Serial.printf("Set P2P mode encryption status %s\r\n", api.lorawan.encry.set(1) ? "Success" : "Fail");
Serial.printf("Set P2P mode encryption Key %s\r\n\r\n", api.lorawan.enckey.set(node_encrypt_key, 8) ? "Success" : "Fail");

    Serial.printf("P2P encryption status = %s\r\n", api.lorawan.encry.get() ? "Enable" : "Disable");

api.lorawan.enckey.get(encrypt_buff, 8);
Serial.printf("P2P encryption Key = 0x");
    for (int i = 0 ; i < 8 ; i++) {
        Serial.printf("%02X", encrypt_buff[i]);
    }
Serial.println("");
  
    randomSeed(millis());
}

void loop()
{
    uint8_t payload[] = "payload";

    int rxDelay = random(3000, 5000);
  
    // Receive P2P data every 10 seconds
    if(millis() - startTime >= 10*1000) {
      Serial.printf("P2P Rx start for %d millisSeconds\r\n", rxDelay);
      startTime = millis();
      Serial.printf("P2P set Rx mode %s\r\n",api.lorawan.precv(rxDelay) ? "Success" : "Fail");
      delay(rxDelay);
    } else {
    
      Serial.printf("P2P send %s\r\n", api.lorawan.psend(sizeof(payload), payload)? "Success" : "Fail");
      delay(1000);
    }

}

# set()

This API allows to enable or disable P2P mode encryption.

bool set(bool value)	
Syntax api.lorawan.encry.set(value);
Parameters value - the status of P2P mode encryption
Returns bool
Return Values TRUE for setting status of encryption success
FALSE for setting status of encryption failure
long startTime;
uint8_t node_encrypt_key[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
uint8_t encrypt_buff[8];

void setup()
{
    Serial.begin(115200);
    startTime = millis();
  
    Serial.println("P2P Start");
    
    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode frequency %s\r\n", api.lorawan.pfreq.set(868000000) ? "Success" : "Fail");
    Serial.printf("Set P2P mode spreading factor %s\r\n", api.lorawan.psf.set(12) ? "Success" : "Fail");
    Serial.printf("Set P2P mode bandwidth %s\r\n", api.lorawan.pbw.set(125) ? "Success" : "Fail");
    Serial.printf("Set P2P mode code rate %s\r\n", api.lorawan.pcr.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode preamble length %s\r\n", api.lorawan.ppl.set(8) ? "Success" : "Fail");
    Serial.printf("Set P2P mode tx power %s\r\n", api.lorawan.ptp.set(22) ? "Success" : "Fail");
Serial.printf("Set P2P mode encryption status %s\r\n", api.lorawan.encry.set(1) ? "Success" : "Fail");
Serial.printf("Set P2P mode encryption Key %s\r\n\r\n", api.lorawan.enckey.set(node_encrypt_key, 8) ? "Success" : "Fail");

    Serial.printf("P2P encryption status = %s\r\n", api.lorawan.encry.get() ? "Enable" : "Disable");

api.lorawan.enckey.get(encrypt_buff, 8);
Serial.printf("P2P encryption Key = 0x");
    for (int i = 0 ; i < 8 ; i++) {
        Serial.printf("%02X", encrypt_buff[i]);
    }
Serial.println("");
  
    randomSeed(millis());
}

void loop()
{
    uint8_t payload[] = "payload";

    int rxDelay = random(3000, 5000);
  
    // Receive P2P data every 10 seconds
    if(millis() - startTime >= 10*1000) {
      Serial.printf("P2P Rx start for %d millisSeconds\r\n", rxDelay);
      startTime = millis();
      Serial.printf("P2P set Rx mode %s\r\n",api.lorawan.precv(rxDelay) ? "Success" : "Fail");
      delay(rxDelay);
    } else {
    
      Serial.printf("P2P send %s\r\n", api.lorawan.psend(sizeof(payload), payload)? "Success" : "Fail");
      delay(1000);
    }
}

# enckey

This API will encrypt the date being sent and received.

RAKLorawan::enckey

# get()

This API allows to get the key of P2P mode encryption.

bool get(uint8_t * buff, uint32_t len)
Syntax api.lorawan.enckey.get(buff, len);
Parameters buff - the buffer to store encryption key
len - the length of encryption key (must be 8 bytes)
Returns bool
Return Values TRUE for getting encryption key success
FALSE for getting encryption key failure
long startTime;
uint8_t node_encrypt_key[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
uint8_t encrypt_buff[8];

void setup()
{
    Serial.begin(115200);
    startTime = millis();
  
    Serial.println("P2P Start");
    
    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode frequency %s\r\n", api.lorawan.pfreq.set(868000000) ? "Success" : "Fail");
    Serial.printf("Set P2P mode spreading factor %s\r\n", api.lorawan.psf.set(12) ? "Success" : "Fail");
    Serial.printf("Set P2P mode bandwidth %s\r\n", api.lorawan.pbw.set(125) ? "Success" : "Fail");
    Serial.printf("Set P2P mode code rate %s\r\n", api.lorawan.pcr.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode preamble length %s\r\n", api.lorawan.ppl.set(8) ? "Success" : "Fail");
    Serial.printf("Set P2P mode tx power %s\r\n", api.lorawan.ptp.set(22) ? "Success" : "Fail");
Serial.printf("Set P2P mode encryption status %s\r\n", api.lorawan.encry.set(1) ? "Success" : "Fail");
Serial.printf("Set P2P mode encryption Key %s\r\n\r\n", api.lorawan.enckey.set(node_encrypt_key, 8) ? "Success" : "Fail");

    Serial.printf("P2P encryption status = %s\r\n", api.lorawan.encry.get() ? "Enable" : "Disable");

api.lorawan.enckey.get(encrypt_buff, 8);
Serial.printf("P2P encryption Key = 0x");
    for (int i = 0 ; i < 8 ; i++) {
        Serial.printf("%02X", encrypt_buff[i]);
    }
Serial.println("");
  
    randomSeed(millis());
}

void loop()
{
    uint8_t payload[] = "payload";

    int rxDelay = random(3000, 5000);
  
    // Receive P2P data every 10 seconds
    if(millis() - startTime >= 10*1000) {
      Serial.printf("P2P Rx start for %d millisSeconds\r\n", rxDelay);
      startTime = millis();
      Serial.printf("P2P set Rx mode %s\r\n",api.lorawan.precv(rxDelay) ? "Success" : "Fail");
      delay(rxDelay);
    } else {
    
      Serial.printf("P2P send %s\r\n", api.lorawan.psend(sizeof(payload), payload)? "Success" : "Fail");
      delay(1000);
    }

}

# set()

This API allows to set the key of P2P mode encryption.

bool set(uint8_t * buff, uint32_t len)	
Syntax api.lorawan.enckey.set(buff, len);
Parameters buff - the buffer to set encryption key
len - the length of encryption key (must be 8 bytes)
Returns bool
Return Values TRUE for setting encryption key success
FALSE for setting encryption failure
long startTime;
uint8_t node_encrypt_key[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
uint8_t encrypt_buff[8];

void setup()
{
    Serial.begin(115200);
    startTime = millis();
  
    Serial.println("P2P Start");
    
    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode frequency %s\r\n", api.lorawan.pfreq.set(868000000) ? "Success" : "Fail");
    Serial.printf("Set P2P mode spreading factor %s\r\n", api.lorawan.psf.set(12) ? "Success" : "Fail");
    Serial.printf("Set P2P mode bandwidth %s\r\n", api.lorawan.pbw.set(125) ? "Success" : "Fail");
    Serial.printf("Set P2P mode code rate %s\r\n", api.lorawan.pcr.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode preamble length %s\r\n", api.lorawan.ppl.set(8) ? "Success" : "Fail");
    Serial.printf("Set P2P mode tx power %s\r\n", api.lorawan.ptp.set(22) ? "Success" : "Fail");
Serial.printf("Set P2P mode encryption status %s\r\n", api.lorawan.encry.set(1) ? "Success" : "Fail");
Serial.printf("Set P2P mode encryption Key %s\r\n\r\n", api.lorawan.enckey.set(node_encrypt_key, 8) ? "Success" : "Fail");

    Serial.printf("P2P encryption status = %s\r\n", api.lorawan.encry.get() ? "Enable" : "Disable");

api.lorawan.enckey.get(encrypt_buff, 8);
Serial.printf("P2P encryption Key = 0x");
    for (int i = 0 ; i < 8 ; i++) {
        Serial.printf("%02X", encrypt_buff[i]);
    }
Serial.println("");
  
    randomSeed(millis());
}

void loop()
{
    uint8_t payload[] = "payload";

    int rxDelay = random(3000, 5000);
  
    // Receive P2P data every 10 seconds
    if(millis() - startTime >= 10*1000) {
      Serial.printf("P2P Rx start for %d millisSeconds\r\n", rxDelay);
      startTime = millis();
      Serial.printf("P2P set Rx mode %s\r\n",api.lorawan.precv(rxDelay) ? "Success" : "Fail");
      delay(rxDelay);
    } else {
    
      Serial.printf("P2P send %s\r\n", api.lorawan.psend(sizeof(payload), payload)? "Success" : "Fail");
      delay(1000);
    }

}

# pbr

This API configures the P2P FSK modem bitrate (600 b/s - 307200 b/s).

RAKLorawan::pbr

# get()

This API allows to get the P2P FSK modem bitrate (600 b/s - 307200 b/s).

uint32_t get()	
Syntax api.lorawan.pbr.get();
Returns The P2P FSK modem bitrate

# set()

This API allows to set the P2P FSK modem bitrate (600 b/s - 307200 b/s).

bool set(uint32_t value)
Syntax api.lorawan.pbr.get();
Parameters value

# pfdev

This API configures the P2P FSK modem frequency deviation.

RAKLorawan::pfdev

# get()

This API allows to get the P2P FSK modem frequency deviation.

uint32_t get()	
Syntax api.lorawan.pfdev.get();
Returns The P2P FSK modem frequency deviation

# set()

This API allows to set the P2P FSK modem frequency deviation.

bool set(uint32_t value)	
Syntax api.lorawan.pfdev.set(value);
Parameters value

# registerPRecvCallback()

This API is used to register a callback function, so that application can be notified on receiving P2P data.

bool registerPRecvCallback(service_lora_p2p_recv_cb_type callback)	
Syntax api.lorawan.registerPRecvCallback(service_lora_p2p_recv_cb_type callback);
Parameters The - callback function
Returns bool
Return Values TRUE for setting callback function success
FALSE for setting callback function failure
void recv_cb(rui_lora_p2p_recv_t data) {
  Serial.println("Receive something");
}

void send_cb(void) {
  Serial.println("I send something");
}

long startTime;

void setup()
{
  Serial.begin(115200);

  delay(2000);
  startTime = millis();

  Serial.println("P2P Start");
  
  Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
  Serial.printf("Set P2P mode frequency %s\r\n", api.lorawan.pfreq.set(868000000) ? "Success" : "Fail");
  Serial.printf("Set P2P mode spreading factor %s\r\n", api.lorawan.psf.set(12) ? "Success" : "Fail");
  Serial.printf("Set P2P mode bandwidth %s\r\n", api.lorawan.pbw.set(125) ? "Success" : "Fail");
  Serial.printf("Set P2P mode code rate %s\r\n", api.lorawan.pcr.set(0) ? "Success" : "Fail");
  Serial.printf("Set P2P mode preamble length %s\r\n", api.lorawan.ppl.set(8) ? "Success" : "Fail");
  Serial.printf("Set P2P mode tx power %s\r\n", api.lorawan.ptp.set(22) ? "Success" : "Fail");

  api.lorawan.registerPRecvCallback(recv_cb);
  api.lorawan.registerPSendCallback(send_cb);

  randomSeed(millis());
}

void loop()
{
  uint8_t payload[] = "payload";

  int rxDelay = random(3000, 5000);

  // Receive P2P data every 10 seconds
  if(millis() - startTime >= 10*1000) {
    Serial.printf("P2P Rx start for %d millisSeconds\r\n", rxDelay);
    startTime = millis();
    Serial.printf("P2P set Rx mode %s\r\n",api.lorawan.precv(rxDelay) ? "Success" : "Fail");
    delay(rxDelay);
  } else {
  
    Serial.printf("P2P send %s\r\n", api.lorawan.psend(sizeof(payload), payload)? "Success" : "Fail");
    delay(1000);
  }

}  


# registerPSendCallback()

This API is used to register a callback function, so that application can be notified when P2P uplink process is done.

bool registerPSendCallback(service_lora_p2p_send_cb_type callback)	
Syntax api.lorawan.registerPSendCallback(service_lora_p2p_send_cb_type callback);
Parameters The - callback function
Returns bool
Return Values TRUE for setting callback function success
FALSE for setting callback function failure
void recv_cb(rui_lora_p2p_recv_t data) {
  Serial.println("Receive something");
}

void send_cb(void) {
  Serial.println("I send something");
}

long startTime;

void setup()
{
  Serial.begin(115200);

  delay(2000);
  startTime = millis();

  Serial.println("P2P Start");
  
  Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
  Serial.printf("Set P2P mode frequency %s\r\n", api.lorawan.pfreq.set(868000000) ? "Success" : "Fail");
  Serial.printf("Set P2P mode spreading factor %s\r\n", api.lorawan.psf.set(12) ? "Success" : "Fail");
  Serial.printf("Set P2P mode bandwidth %s\r\n", api.lorawan.pbw.set(125) ? "Success" : "Fail");
  Serial.printf("Set P2P mode code rate %s\r\n", api.lorawan.pcr.set(0) ? "Success" : "Fail");
  Serial.printf("Set P2P mode preamble length %s\r\n", api.lorawan.ppl.set(8) ? "Success" : "Fail");
  Serial.printf("Set P2P mode tx power %s\r\n", api.lorawan.ptp.set(22) ? "Success" : "Fail");

  api.lorawan.registerPRecvCallback(recv_cb);
  api.lorawan.registerPSendCallback(send_cb);

  randomSeed(millis());
}

void loop()
{
  uint8_t payload[] = "payload";

  int rxDelay = random(3000, 5000);

  // Receive P2P data every 10 seconds
  if(millis() - startTime >= 10*1000) {
    Serial.printf("P2P Rx start for %d millisSeconds\r\n", rxDelay);
    startTime = millis();
    Serial.printf("P2P set Rx mode %s\r\n",api.lorawan.precv(rxDelay) ? "Success" : "Fail");
    delay(rxDelay);
  } else {
  
    Serial.printf("P2P send %s\r\n", api.lorawan.psend(sizeof(payload), payload)? "Success" : "Fail");
    delay(1000);
  }

}    

# psend()

This API provides the way to P2P send data.

bool psend(uint8_t length, uint8_t * payload)	
Syntax api.lorawan.psend(length, payload);
Parameters length - the length of the payload
payload - the data send to the other device
Returns bool
Return Values TRUE for sending data success
FALSE for sending data failure
void setup()
{
    Serial.begin(115200);

    Serial.println("P2P Start");

    Serial.printf("Set Node device work mode %s\r\n", api.lorawan.nwm.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode frequency %s\r\n", api.lorawan.pfreq.set(868000000) ? "Success" : "Fail");
    Serial.printf("Set P2P mode spreading factor %s\r\n", api.lorawan.psf.set(12) ? "Success" : "Fail");
    Serial.printf("Set P2P mode bandwidth %s\r\n", api.lorawan.pbw.set(125) ? "Success" : "Fail");
    Serial.printf("Set P2P mode code rate %s\r\n", api.lorawan.pcr.set(0) ? "Success" : "Fail");
    Serial.printf("Set P2P mode preamble length %s\r\n", api.lorawan.ppl.set(8) ? "Success" : "Fail");
    Serial.printf("Set P2P mode tx power %s\r\n", api.lorawan.ptp.set(22) ? "Success" : "Fail");
}

void loop()
{
    uint8_t payload[] = "payload";
    Serial.printf("P2P send %s\r\n", api.lorawan.psend(sizeof(payload), payload)? "Success" : "Fail"); 

    delay(5000);
}

# Multicast Group Command

# addmulc()

This API adds a new multicast group configure multicast parameters.

bool addmulc(RAK_LORA_McSession session)	
Syntax api.lorawan.addmulc(session);
Parameters session - The structure of session
Returns bool
Return Values TRUE for adding multicast group success
FALSE for adding multicast group failure
void setup()
{
  Serial.begin(115200);

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x88};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x0E};
// 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};



//LoRaWan Multicast Session

uint8_t node_mc_address[4] = {0x01, 0x02, 0x03, 0x04};
uint8_t node_mc_AppSKey[16] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
uint8_t node_mc_NwkSKey[16] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};

RAK_LORA_McSession session = {
    .McDevclass = 2,
    .McAddress = node_mc_address[0]<<24 | node_mc_address[1]<<16 | node_mc_address[2]<<8 | node_mc_address[3],
    .McFrequency = 869525000,
    .McDatarate = 0,
    .McPeriodicity = 0,
    .McGroupID = 2,
    .entry = 0,
};
  memcpy(session.McAppSKey, node_mc_AppSKey, 16);
  memcpy(session.McNwkSKey, node_mc_NwkSKey, 16);

  api.lorawan.appeui.set(node_app_eui, 8);
  api.lorawan.appkey.set(node_app_key, 16);
  api.lorawan.deui.set(node_device_eui, 8);
   
  api.lorawan.band.set(4);
  api.lorawan.njm.set(1);
  api.lorawan.deviceClass.set(2);
  api.lorawan.join();

  //Wait for Join success 
  while (api.lorawan.njs.get() == 0)
  {
    Serial.print("Waiting for Lorawan join...");
    api.lorawan.join();
    delay(10000);
  }

  api.lorawan.adr.set(true);
  api.lorawan.rety.set(1);
  api.lorawan.cfm.set(1);

  //LoRaWAN Multicast Setting
  if(api.lorawan.addmulc(session) == true) {
    Serial.println("Add Multicast Success");
  } else {
    Serial.println("Add Multicast Fail");
  }
  
}

void loop()
{

}

# rmvmulc()

This API allows the removal of a configured multicast group.

bool rmvmulc(uint32_t devAddr)	
Syntax api.lorawan.rmvmulc(devAddr);
Parameters devAddr - the address to remove a multicast group
Returns bool
Return Values TRUE for removing success
FALSE for removing failure

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x88};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x0E};
// 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};

//LoRaWan Multicast Session
uint8_t node_mc_address[4] = {0x01, 0x02, 0x03, 0x04};
uint8_t node_mc_AppSKey[16] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
uint8_t node_mc_NwkSKey[16] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};


void setup()
{
  Serial.begin(115200);

  RAK_LORA_McSession session = {
      .McDevclass = 2,
      .McAddress = node_mc_address[0]<<24 | node_mc_address[1]<<16 | node_mc_address[2]<<8 | node_mc_address[3],
      .McFrequency = 869525000,
      .McDatarate = 0,
      .McPeriodicity = 0,
      .McGroupID = 2,
      .entry = 0,
  };
  memcpy(session.McAppSKey, node_mc_AppSKey, 16);
  memcpy(session.McNwkSKey, node_mc_NwkSKey, 16);

  api.lorawan.appeui.set(node_app_eui, 8);
  api.lorawan.appkey.set(node_app_key, 16);
  api.lorawan.deui.set(node_device_eui, 8);
   
  api.lorawan.band.set(4);
  api.lorawan.njm.set(1);
  api.lorawan.deviceClass.set(2);
  api.lorawan.join();

  //Wait for Join success 
  while (api.lorawan.njs.get() == 0)
  {
    Serial.print("Waiting for Lorawan join...");
    api.lorawan.join();
    delay(10000);
  }

  api.lorawan.adr.set(true);
  api.lorawan.rety.set(1);
  api.lorawan.cfm.set(1);

  //LoRaWAN Multicast Setting
  if(api.lorawan.addmulc(session) == true) {
    Serial.println("Add Multicast Success");
  } else {
    Serial.println("Add Multicast Fail");
  }
  
}

void loop()
{
  if(millis() > 100000) {
     Serial.printf("Remove a multicast group %s\r\n", api.lorawan.rmvmulc(node_mc_address[0]<<24 | node_mc_address[1]<<16 | node_mc_address[2]<<8 | node_mc_address[3]));
   } 
}

# lstmulc()

This command can view current configured multicast group information.

bool lstmulc(RAK_LORA_McSession * iterator)	
Syntax api.lorawan.lstmulc(&multicast_list);
Parameters multicast_list - a RAK_LORA_McSession variable
Returns bool
Return Values TRUE for getting multicast list success
FALSE for getting multicast failure
void setup()
{
  Serial.begin(115200);

// OTAA Device EUI MSB
uint8_t node_device_eui[8] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x88};
// OTAA Application EUI MSB
uint8_t node_app_eui[8] = {0x0E, 0x0D, 0x0D, 0x01, 0x0E, 0x01, 0x02, 0x0E};
// 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};



//LoRaWan Multicast Session

uint8_t node_mc_address[4] = {0x01, 0x02, 0x03, 0x04};
uint8_t node_mc_AppSKey[16] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
uint8_t node_mc_NwkSKey[16] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};

RAK_LORA_McSession session = {
    .McDevclass = 2,
    .McAddress = node_mc_address[0]<<24 | node_mc_address[1]<<16 | node_mc_address[2]<<8 | node_mc_address[3],
    .McFrequency = 869525000,
    .McDatarate = 0,
    .McPeriodicity = 0,
    .McGroupID = 2,
    .entry = 0,
};
  memcpy(session.McAppSKey, node_mc_AppSKey, 16);
  memcpy(session.McNwkSKey, node_mc_NwkSKey, 16);

  api.lorawan.appeui.set(node_app_eui, 8);
  api.lorawan.appkey.set(node_app_key, 16);
  api.lorawan.deui.set(node_device_eui, 8);
   
  api.lorawan.band.set(4);
  api.lorawan.njm.set(1);
  api.lorawan.deviceClass.set(2);
  api.lorawan.join();

  //Wait for Join success 
  while (api.lorawan.njs.get() == 0)
  {
    Serial.print("Waiting for Lorawan join...");
    api.lorawan.join();
    delay(10000);
  }

  api.lorawan.adr.set(true);
  api.lorawan.rety.set(1);
  api.lorawan.cfm.set(1);

  //LoRaWAN Multicast Setting
  if(api.lorawan.addmulc(session) == true) {
    Serial.println("Add Multicast Success");
  } else {
    Serial.println("Add Multicast Fail");
  }
  
}

void loop()
{
  RAK_LORA_McSession multicast_list;

  Serial.println("Get all multicast groups");
  while (api.lorawan.lstmulc(&multicast_list) == true) {
    if (multicast_list.McDevclass != 0) {
      Serial.printf("Device class = %d\r\n", multicast_list.McDevclass);
      Serial.printf("Device address = %08X\r\n", multicast_list.McAddress);

      Serial.print("Multicast AppSKey = 0x");
      for (int i=0; i<16; i++) {
        Serial.printf("%02X", multicast_list.McAppSKey[i]);
      }
      Serial.println("");

      Serial.print("Multicast NwkSKey = 0x");
      for (int i=0; i<16; i++) {
        Serial.printf("%02X", multicast_list.McNwkSKey[i]);
      }
      Serial.println("");

      Serial.printf("Frequency = %d\r\n", multicast_list.McFrequency);
      Serial.printf("Data rate = %d\r\n", multicast_list.McDatarate);
      Serial.printf("Periodicity = %d\r\n", multicast_list.McPeriodicity);
      Serial.printf("Group ID = %d\r\n", multicast_list.McGroupID);
      Serial.printf("Entry = %d\r\n", multicast_list.entry);
    }
  }

  delay(5000);

}