Please include the following information, in order for us to help you as effectively as possible.
-
What product do you wish to discuss? RAK4631, RAK3372, RAK11200, RAK11310, RAK11722?
RAK11720 -
What firmware are you using? (RUI3 or Arduino BSP or other IDE (e.g. STM32CubeIDE)?
RUI3 V 4.1.1 -
What firmware version? Can it be obtained with AT+VER=?
AT+VER=RUI_4.1.1_RAK11720 -
Computer OS? (MacOS, Linux, Windows)
Linux -
What Computer OS version?
Ubuntu 24.04 LTS -
How often does the problem happen?
Adding multicast to ABP Sample -
How can we replicate the problem?
Take example Lorawan_ABP and add
/**Setting multicast seccion */
uint8_t assigned_dev_addr[4] = {0};
api.lorawan.daddr.get(assigned_dev_addr, 4);
Serial.printf(“Device Address is %02X%02X%02X%02X\r\n”, assigned_dev_addr[0], assigned_dev_addr[1], assigned_dev_addr[2], assigned_dev_addr[3]); // Check Device Address
memcpy(session.McAppSKey, node_mc_AppSKey, 16);
memcpy(session.McNwkSKey, node_mc_NwkSKey, 16);
session.McAddress = assigned_dev_addr[0] << 24 | assigned_dev_addr[1] << 16 | assigned_dev_addr[2] << 8 | assigned_dev_addr[3];//LoRaWAN Multicast Setting
if(api.lorawan.addmulc(session) == true) {
Serial.println(“Add Multicast Success”);
} else {
Serial.println(“Add Multicast Fail”);
} -
Provide source code if custom firmware is used or link to example if RAKwireless example code is used.
/***
- This example shows LoRaWan protocol joining the network in ABP mode, class A, region US915.
- Device will send uplink every 5 seconds.
***/
#define ABP_PERIOD (5000)
/*************************************
LoRaWAN band setting:
RAK_REGION_EU433
RAK_REGION_CN470
RAK_REGION_RU864
RAK_REGION_IN865
RAK_REGION_EU868
RAK_REGION_US915
RAK_REGION_AU915
RAK_REGION_KR920
RAK_REGION_AS923
*************************************/
#define ABP_BAND (RAK_REGION_US915)
#define ABP_DEVADDR {0x26, 0x0C, 0xFA, 0x55}
#define ABP_APPSKEY {0x45,0x53,0x43,0x2d,0x67,0x72,0x6f,0x75,0x70,0x20,0x4e,0x61,0x69,0x61,0x14,0x17}
#define ABP_NWKSKEY {0x45,0x53,0x43,0x2d,0x67,0x72,0x6f,0x75,0x70,0x20,0x4e,0x61,0x69,0x61,0x14,0x18}
uint16_t maskChannel = 0x0002;
//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,0x18};
uint8_t node_mc_NwkSKey[16] = {0x45,0x53,0x43,0x2d,0x67,0x72,0x6f,0x75,0x70,0x20,0x4e,0x61,0x69,0x61,0x14,0x18};
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 = 923300000,
.McDatarate = 8,
.McPeriodicity = 0,
.McGroupID = 2,
.entry = 0,
};
/** Packet buffer for sending */
uint8_t collected_data[64] = { 0 };
void recvCallback(SERVICE_LORA_RECEIVE_T * data)
{
if (data->BufferSize > 0) {
Serial.println(“Something received!”);
for (int i = 0; i < data->BufferSize; i++) {
Serial.printf(“%x”, data->Buffer[i]);
}
Serial.print(“\r\n”);
}
}
/*************************************
- enum type for LoRa Event
RAK_LORAMAC_STATUS_OK = 0,
RAK_LORAMAC_STATUS_ERROR,
RAK_LORAMAC_STATUS_TX_TIMEOUT,
RAK_LORAMAC_STATUS_RX1_TIMEOUT,
RAK_LORAMAC_STATUS_RX2_TIMEOUT,
RAK_LORAMAC_STATUS_RX1_ERROR,
RAK_LORAMAC_STATUS_RX2_ERROR,
RAK_LORAMAC_STATUS_JOIN_FAIL,
RAK_LORAMAC_STATUS_DOWNLINK_REPEATED,
RAK_LORAMAC_STATUS_TX_DR_PAYLOAD_SIZE_ERROR,
RAK_LORAMAC_STATUS_DOWNLINK_TOO_MANY_FRAMES_LOSS,
RAK_LORAMAC_STATUS_ADDRESS_FAIL,
RAK_LORAMAC_STATUS_MIC_FAIL,
RAK_LORAMAC_STATUS_MULTICAST_FAIL,
RAK_LORAMAC_STATUS_BEACON_LOCKED,
RAK_LORAMAC_STATUS_BEACON_LOST,
RAK_LORAMAC_STATUS_BEACON_NOT_FOUND,
*************************************/
void sendCallback(int32_t status)
{
if (status == RAK_LORAMAC_STATUS_OK) {
Serial.println(“Successfully sent”);
} else {
Serial.println(“Sending failed”);
}
}
void setup()
{
Serial.begin(115200, RAK_AT_MODE);
delay(2000);
Serial.println("RAKwireless LoRaWan ABP 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();
}
// ABP Device Address MSB first
uint8_t node_dev_addr[4] = ABP_DEVADDR;
// ABP Application Session Key
uint8_t node_app_skey[16] = ABP_APPSKEY;
// ABP Network Session Key
uint8_t node_nwk_skey[16] = ABP_NWKSKEY;
if (!api.lorawan.njm.set(RAK_LORA_ABP)) // Set the network join mode to ABP
{
Serial.printf("LoRaWan ABP - set network join mode is incorrect! \r\n");
return;
}
if (!api.lorawan.daddr.set(node_dev_addr, 4)) {
Serial.printf("LoRaWan ABP - set device addr is incorrect! \r\n");
return;
}
if (!api.lorawan.appskey.set(node_app_skey, 16)) {
Serial.printf("LoRaWan ABP - set application session key is incorrect! \r\n");
return;
}
if (!api.lorawan.nwkskey.set(node_nwk_skey, 16)) {
Serial.printf("LoRaWan ABP - set network session key is incorrect! \r\n");
return;
}
if (!api.lorawan.band.set(ABP_BAND)) {
Serial.printf("LoRaWan ABP - set band is incorrect! \r\n");
return;
}
if (!api.lorawan.deviceClass.set(RAK_LORA_CLASS_A)) {
Serial.printf("LoRaWan ABP - set device class is incorrect! \r\n");
return;
}
if (!api.lorawan.adr.set(true)) {
Serial.printf("LoRaWan ABP - set adaptive data rate is incorrect! \r\n");
return;
}
if (!api.lorawan.rety.set(1)) {
Serial.printf("LoRaWan ABP - set retry times is incorrect! \r\n");
return;
}
if (!api.lorawan.cfm.set(1)) {
Serial.printf("LoRaWan ABP - set confirm mode is incorrect! \r\n");
return;
}
/**Setting multicast seccion */
uint8_t assigned_dev_addr[4] = {0};
api.lorawan.daddr.get(assigned_dev_addr, 4);
Serial.printf("Device Address is %02X%02X%02X%02X\r\n", assigned_dev_addr[0], assigned_dev_addr[1], assigned_dev_addr[2], assigned_dev_addr[3]); // Check Device Address
memcpy(session.McAppSKey, node_mc_AppSKey, 16);
memcpy(session.McNwkSKey, node_mc_NwkSKey, 16);
session.McAddress = assigned_dev_addr[0] << 24 | assigned_dev_addr[1] << 16 | assigned_dev_addr[2] << 8 | assigned_dev_addr[3];
//LoRaWAN Multicast Setting
if(api.lorawan.addmulc(session) == true) {
Serial.println("Add Multicast Success");
} else {
Serial.println("Add Multicast Fail");
}
/** Check LoRaWan Status*/
Serial.printf("Duty cycle is %s\r\n", api.lorawan.dcs.get()? "ON" : "OFF"); // Check Duty Cycle status
Serial.printf("Packet is %s\r\n", api.lorawan.cfm.get()? "CONFIRMED" : "UNCONFIRMED"); // Check Confirm status
// uint8_t assigned_dev_addr[4] = { 0 };
api.lorawan.daddr.get(assigned_dev_addr, 4);
Serial.printf("Device Address is %02X%02X%02X%02X\r\n", assigned_dev_addr[0], assigned_dev_addr[1], assigned_dev_addr[2], assigned_dev_addr[3]); // Check Device Address
Serial.printf("Uplink period is %ums\r\n", ABP_PERIOD);
Serial.println("");
api.lorawan.registerRecvCallback(recvCallback);
api.lorawan.registerSendCallback(sendCallback);
}
void uplink_routine()
{
/** Payload of Uplink */
uint8_t data_len = 0;
collected_data[data_len++] = (uint8_t) ‘t’;
collected_data[data_len++] = (uint8_t) ‘e’;
collected_data[data_len++] = (uint8_t) ‘s’;
collected_data[data_len++] = (uint8_t) ‘t’;
Serial.println("Data Packet:");
for (int i = 0; i < data_len; i++) {
Serial.printf("0x%02X ", collected_data[i]);
}
Serial.println("");
/** Send the data package */
if (api.lorawan.send(data_len, (uint8_t *) & collected_data, 2, true, 1)) {
Serial.println("Sending is requested");
} else {
Serial.println("Sending failed");
}
}
void loop()
{
static uint64_t last = 0;
static uint64_t elapsed;
if ((elapsed = millis() - last) > ABP_PERIOD) {
uplink_routine();
last = millis();
}
//Serial.printf("Try sleep %ums..", ABP_PERIOD);
api.system.sleep.all(ABP_PERIOD);
//Serial.println("Wakeup..");
}
Console output adding multicast
RAKwireless LoRaWan ABP Example
Device Address is 260CFA55
Add Multicast Fail
Duty cycle is ON
Packet is CONFIRMED
Device Address is 260CFA55
Uplink period is 5000ms
Current Work Mode: LoRa P2P.
Data Packet:
0x74 0x65 0x73 0x74
Sending failed
Data Packet:
0x74 0x65 0x73 0x74
Sending failed
without multicast code
RAKwireless LoRaWan ABP Example
Duty cycle is ON
Packet is CONFIRMED
Device Address is 260CFA55
Uplink period is 5000ms
Current Work Mode: LoRaWAN.
Data Packet:
0x74 0x65 0x73 0x74
Sending is requested
Successfully sent