Multicast Fail with RAK3372 node, RAK2287 Gateway and ChirpStack network server

Product do you wish to discuss?
RAK3372, RAK2287

What firmware are you using?
RUI3

What firmware version?
AT+VER=RUI_4.2.0_RAK3172-E

Computer OS?
Linux

How often does the problem happen?
Always

Hello,
I can’t establish a multicast connection between my RAK3372 and ChirpStack. Each time I try to connect using Lorawan_Multicast sample code, I get the following messages:

RAKwireless LoRaWan Multicast Example
------------------------------------------------------
Waiting for Lorawan join...+EVT:JOINED
Add Multicast Fail
Current Work Mode: LoRaWAN.

Node:
Lorawan_Multicast sample code :

/***
 *  This example shows LoRaWan protocol joining the network in OTAA mode, class C, region EU868 and set multicast group.
***/
bool ret;
void setup() {
  Serial.begin(115200);
  delay(2000);

  Serial.println("RAKwireless LoRaWan Multicast Example");
  Serial.println("------------------------------------------------------");

  if (api.lorawan.nwm.get() != 1) {
	Serial.printf("Set Node device work mode %s\r\n",
              	api.lorawan.nwm.set() ? "Success" : "Fail");
	api.system.reboot();
  }

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

  if (!(ret = api.lorawan.appeui.set(node_app_eui, 8))) {
	Serial.printf("LoRaWan Multicast - set device EUI is incorrect! \r\n");
	return;
  }
  if (!(ret = api.lorawan.appkey.set(node_app_key, 16))) {
	Serial.printf("LoRaWan Multicast - set application EUI is incorrect! \r\n");
	return;
  }
  if (!(ret = api.lorawan.deui.set(node_device_eui, 8))) {
	Serial.printf("LoRaWan Multicast - set application key is incorrect! \r\n");
	return;
  }
  /*************************************
 	*
 	* LoRaWAN band setting:
 	*   EU433: 0
 	*   CN470: 1
 	*   RU864: 2
 	*   IN865: 3
 	*   EU868: 4
 	*   US915: 5
 	*   AU915: 6
 	*   KR920: 7
 	*   AS923: 8
 	*
 	* ************************************/

  if (!(ret = api.lorawan.band.set(4))) {
	Serial.printf("LoRaWan Multicast - set band is incorrect! \r\n");
	return;
  }
  if (!(ret = api.lorawan.njm.set(RAK_LORA_OTAA))) {
	Serial.printf("LoRaWan Multicast - set network join mode is incorrect! \r\n");
	return;
  }
  if (!(ret = api.lorawan.deviceClass.set(RAK_LORA_CLASS_C))) {
	Serial.printf("LoRaWan Multicast - set device class is incorrect! \r\n");
	return;
  }

  if (!(ret = api.lorawan.join())) {
	Serial.printf("LoRaWan Multicast - join fail! \r\n");
	return;
  }

  /**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() {
}

Gateway:
The RAK2287 gateway is connected to the linux computer using the “mPCIe to USB Board” interface. I’m running the packet_forwarder utility from the sx1302_hal project version 2.1.0 (sx1302_hal/packet_forwarder at master · Lora-net/sx1302_hal · GitHub) with the config file “configuration/chirpstack/chirpstack.toml” copied from “region_eu868.toml” and only the “eu868” region active.

Network server:
ChirpStack is running in a docker (chirpstack-docker v4.9.0). The server configuration is described below:
The gateway is online and configured for the eu868 region.
https://ibb.co/b1fHwnk

The “My_application2” application contains a “My_Device2” node with the “My_device” profile. The device is seen by my server (Last seen …)
https://ibb.co/djwWyqm

Node “My_Device2” is configured with Device EUI “0102030405060788” (node_device_eui from the Lorawan_Multicast example) with profile “My_device”.
https://ibb.co/h807mtQ

The OTAA key is “2b7e151628aed2a6abf7158809cf4f3e” (node_app_key from the Lorawan_Multicast example).
https://ibb.co/S7XP0sg

The “My_device” profile is set to EU868 (api.lorawan.band.set(4) from the Lorawan_Multicast example).
https://ibb.co/2tjttDJ

The application contains a Multicast group “My_Multicast_group2” for region EU868 and of type “CLASS_C” (api.lorawan.deviceClass.set(RAK_LORA_CLASS_C) from the Lorawan_Multicast example).
https://ibb.co/fSPVj2z

This Multicast group contains “My_Device2” with the DevEUI (0102030405060788).
https://ibb.co/NVg8C0P

This Multicast group is configured with the Multicast address: 01020304, Multicast network session key and Multicast application session key: 01020304050607080102030405060708 (node_mc_address, node_mc_AppSKey and node_mc_NwkSKey from the Lorawan_Multicast example). The region is set to EU868 with a frequency of 869525000Hz (.McFrequency = 869525000 from the Lorawan_Multicast example).
https://ibb.co/8j7WStG

I can’t figure out where my mistake is. Does anyone have any idea why I can’t connect in multicast mode?

PS: PS: Sorry for the image links, I’m not allowed to put more than two links or multiple images in the post.

Maybe this helps ==> RAK11720 Multicast Fail

Thank you for your reply.
I did see this post and it is true that I had not added the lines :

  // Get device address
  api.lorawan.daddr.get(node_mc_address, 4);
  Serial.printf("Device Address is % 02X % 02X % 02X % 02X\r\n", node_mc_address[0], node_mc_address[1], node_mc_address[2], node_mc_address[3]);  // Check Device Address
  // Add address to MC session
  session.McAddress = node_mc_address[0] << 24 | node_mc_address[1] << 16 | node_mc_address[2] << 8 | node_mc_address[3];
  Serial.printf("Session McAddress is % X\r\n", session.McAddress);  // Check Device Address

as you advised and I came back to a version of the code exactly identical to the post except for the RAK_REGION and McFrequency variable.

New code :

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

#define OTAA_BAND (RAK_REGION_EU868)
  // OTAA Device EUI MSB
  uint8_t node_device_eui[8] = { 0x50, 0x59, 0x00, 0x0A, 0x00, 0x00, 0x00, 0x01 };
  // 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] = { 0x45, 0x53, 0x43, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x4e, 0x61, 0x69, 0x61, 0x14, 0x17 };

  //LoRaWan Multicast Session

  uint8_t node_mc_address[4] = { 0x01, 0x02, 0x03, 0x04 };
  uint8_t node_mc_AppSKey[16] = { 0x45, 0x53, 0x43, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x4e, 0x61, 0x69, 0x61, 0x14, 0x17 };
  uint8_t node_mc_NwkSKey[16] = { 0x45, 0x53, 0x43, 0x2d, 0x67, 0x72, 0x6f, 0x75, 0x70, 0x20, 0x4e, 0x61, 0x69, 0x61, 0x14, 0x17 };

  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(OTAA_BAND);
  api.lorawan.njm.set(1);
  api.lorawan.deviceClass.set(RAK_LORA_CLASS_C);
  api.lorawan.join();

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

  // Get device address
  api.lorawan.daddr.get(node_mc_address, 4);
  Serial.printf("Device Address is % 02X % 02X % 02X % 02X\r\n", node_mc_address[0], node_mc_address[1], node_mc_address[2], node_mc_address[3]);  // Check Device Address
  // Add address to MC session
  session.McAddress = node_mc_address[0] << 24 | node_mc_address[1] << 16 | node_mc_address[2] << 8 | node_mc_address[3];
  Serial.printf("Session McAddress is % X\r\n", session.McAddress);  // Check Device Address

  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() {
}

Of course, I also changed the node_device_eui, node_mc_AppSKey and node_mc_NwkSKey in chirkstack accordingly.
Unfortunately, this didn’t solve my problem:

Waiting for Lorawan join…
+EVT:JOINED
Device Address is 01 D1 F1 25
Session McAddress is 1D1F125
Add Multicast Fail
Current Work Mode: LoRaWAN.

I have some doubts, however, about some of the session settings:

  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,		// 869.525 Mhz
	.McDatarate = 0,			// DR0
	.McPeriodicity = 0,			// ?
	.McGroupID = 2,			// ?
	.entry = 0,				// ?
  };

In my opinion, McFrequency and McDatarate correspond to the indications in LoRaWAN® Regional Parameters RP002-1.0.4.
Capture d’écran du 2024-09-20 17-07-16

But I don’t know what McPeriodicity, McGroupID, entry correspond to. I can’t find these configurations in chirpstack.
I also have a doubt about the Data-rate of the chirpstack config. Does it really correspond to DR0 and would therefore be 0?
I’m also wondering if there’s anything special to configure for multicast in the packet_forwarder for the gateway?

Best regards,

Hello,

I’ve looked a little harder and I’ve found a workaround that allows me to switch to multicast. However, this solution makes me think that there may be a bug in the RAK3172 API.
I debugged the program to find out what was going wrong and I realised that the problem was with the ‘service_lora_addmulc’ function called when the ‘api.lorawan.addmulc’ function was called.
I noticed that the function iterates over the McSession_group to find one with an address of 0 (*1). However, in my case, none of them is 0 and so I end up with the error ‘UDRV_PARAM_ERR’ (*2).

int32_t service_lora_addmulc(McSession_t McSession)
{
	LoRaMacStatus_t lorastatus;
	uint8_t i, j;
	McChannelParams_t channel;
	uint8_t status = 0x00;

	for (i = 0; i < 4; i++)
	{
		if (McSession.Address == McSession_group[i].Address)
			return -UDRV_PARAM_ERR;
	}

	for (i = 0; i < 4; i++)
	{
    		if (McSession_group[i].Address == 0) (*1)
    		{
                    …
    		}
	}
 	if (i == 4)
	{
    		memset(&McSession_group[i], 0, sizeof(McSession_t));
    		return -UDRV_PARAM_ERR;		(*2)
	}
	return UDRV_RETURN_OK;
}

I suspect that this involves the use of an uninitialised variable ‘McSession_t McSession_group[LORAMAC_MAX_MC_CTX];’. This structure can be initialised via the ‘service_lora_clear_multicast’ or ‘service_lora_rmvmulc’ functions, but these are never called in the example code.
I therefore modified the ‘api.lorawan.addmulc’ function to add the initialisation of the ‘McSession_group’ variable at the start of the call:

//Multicast
bool RAKLorawan::addmulc(RAK_LORA_McSession session) {
	if (SERVICE_LORAWAN != service_lora_get_nwm())
	{
    		return false;
	}
	service_lora_clear_multicast();		// Added by Me
	//create McSession_t instance
	McSession_t McSession;
	McSession.Devclass = session.McDevclass;
	McSession.Address = session.McAddress;
	memcpy(McSession.McAppSKey, session.McAppSKey, 16);
	memcpy(McSession.McNwkSKey, session.McNwkSKey, 16);
	McSession.Frequency = session.McFrequency;
	McSession.Datarate = session.McDatarate;
	McSession.Periodicity = session.McPeriodicity;
	McSession.GroupID = session.McGroupID;

	if (service_lora_addmulc(McSession) == UDRV_RETURN_OK) {
    	return true;
	} else {
    	return false;
	}
}

This allows me to connect in multicast mode.
Could you tell me if I’ve made an error in my test code? Is there another way of fixing this bug without modifying the API? Is this patch valid or does it pose a problem for connecting to a single multicast group as I do?

Another point, despite switching to multicast, I still can’t send data from my server to my device. The data is transmitted via Chirpstack/Swagger UI :
image10
And the sending went off without a hitch:


I can see the frame passing through the packet forwarder:

JSON down: {“txpk”:{“imme”:true,“rfch”:0,“powe”:29,“ant”:0,“brd”:0,“freq”:869.525,“modu”:“LORA”,“datr”:“SF12BW125”,“codr”:“4/5”,“ipol”:true,“size”:17,“data”:“YAQDAgEA4AABY6/gjNLktdU=”}}
INFO: [down] a packet will be sent in “immediate” mode
WARNING: Requested TX power is not supported (29dBm), actual power used: 27dBm

A frame that closely looks like a conventional frame without using multicast:

JSON down: {“txpk”:{“imme”:true,“rfch”:0,“powe”:29,“ant”:0,“brd”:0,“freq”:869.525,“modu”:“LORA”,“datr”:“SF12BW125”,“codr”:“4/5”,“ipol”:true,“size”:46,“data”:“YAQDAgEAaAACRyoeLNUx3VYPMwXq5JiMV11SM/AzTvCBDf/AQi8I3vfw16YXnw==”}}

But it doesn’t reach the callback :

void recvCallback(SERVICE_LORA_RECEIVE_T *data) {
  if (data->BufferSize > 0) {
	Serial.print("Something received!!!!!! Size: ");
	Serial.println(data->BufferSize);
  }
}

Do you have any idea why multicast frames are not being received?
Best regards,

Hello,

I still can’t solve the two problems concerning the configuration of the multicast mode for the RAK3172 and the reception of multicast data with my patch (addition of the service_lora_clear_multicast call in addmulc).

Could you tell me if github: GitHub - RAKWireless/WisBlock: Quickstart, tutorials and examples for the RAKwireless WisBlock product line. is the right repo to post my bug report?

Best regards

The repo you mentioned is not for RUI3.

You can post the issue in GitHub - RAKWireless/RAK-STM32-RUI: RUI3 BSP for RAK3172 modules instead.

Thanks for your reply,

I’ve posted the issue on the repo. Hope to get an answer from the developers.