RUI3 (RAK Unified Interface 3) - RAK4631
Multicast Group Command

Functions

bool addmulc (RAK_LORA_McSession session)
 
bool rmvmulc (uint32_t devAddr)
 
bool lstmulc (RAK_LORA_McSession *iterator)
 

Detailed Description

Function Documentation

◆ addmulc()

bool addmulc ( RAK_LORA_McSession  session)
Description
This command adds a new multicast group configure multicast parameters
Syntax
api.lorawan.addmulc(session)
Parameters
sessionThe structure of session
Returns
bool
Return values
TRUEfor adding multicast group success
FALSEfor adding multicast group failure
Example
  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()

bool rmvmulc ( uint32_t  devAddr)
Description
This command allows the removal of a configured multicast group
Syntax
api.lorawan.rmvmulc(devAddr)
Parameters
devAddrthe address to remvoe a multicast group
Returns
bool
Return values
TRUEfor removing success
FALSEfor removing failure
Example
  // 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()

bool lstmulc ( RAK_LORA_McSession iterator)
Description
This command can view current configured multicast group information
Syntax
api.lorawan.lstmulc(&multicast_list)
Parameters
multicast_lista RAK_LORA_McSession variable
Returns
bool
Return values
TRUEfor getting multicast list success
FALSEfor getting multicast failure
Example
  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);
  
  }