RUI3 (RAK Unified Interface 3) - RAK4631

Public Member Functions

bool get (uint8_t *buf, uint32_t len)
 
bool set (uint8_t *buf, uint32_t len)
 

Detailed Description

Description
This api allows the user to get or set the network session key

Member Function Documentation

◆ get()

bool get ( uint8_t *  buf,
uint32_t  len 
)
Description
This api allows the user to get the network session key
Syntax
api.lorawan.nwkskey.get(buf, len)
Note
This function can only work in ABP mode0
Parameters
bufthe buffer to get network session key
lenthe length of network session key(must be 16 bytes)
Returns
bool
Return values
TRUEfor getting network session key successfully
FALSEfor getting network session key failure
Example
  // 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()

bool set ( uint8_t *  buf,
uint32_t  len 
)
Description
This api allows the user to set the network session key
Syntax
api.lorawan.nwkskey.set(buf, len)
Parameters
bufthe buffer to set network session key
lenthe length of network session key(must be 16 bytes)
Returns
bool
Return values
TRUEfor setting network session key successfully
FALSEfor setting network session key failure
Example
  // 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);
  }