I am using the RUI3 library for the first time and facing some problems with the returned values for RX1DL and RX2DL.
RAK3172
Latest FW version 4.2.1
The function bellow does the module initialization:
#define OTAA_BAND RAK_REGION_LA915
#define OTAA_DEVEUI {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x88}
#define OTAA_APPEUI {0x6a, 0x22, 0x2b, 0x60, 0x3f, 0x2e, 0xd0, 0xba}
#define OTAA_APPKEY {0x6a, 0x22, 0x2b, 0x60, 0x3f, 0x2e, 0xd0, 0xba, 0x43, 0x3e, 0xfb, 0x10, 0x05, 0xb4, 0x4b, 0x1c}
#define OTAA_JN1DL 5
#define OTAA_JN2DL 6
#define OTAA_RX1DL 5
#define OTAA_RX2DL 6
uint8_t gui8_Device_EUI[8]; // OTAA Device EUI MSB first
uint8_t gui8_App_EUI[8]; // OTAA Application EUI MSB first
uint8_t gui8_App_KEY[16]; // OTAA Application Key MSB first
void Init_LoRa(void)
{
uint8_t ui8_DEF_Device_EUI[8] = OTAA_DEVEUI;
uint8_t ui8_DEF_App_EUI[8] = OTAA_APPEUI;
uint8_t ui8_DEF_App_KEY[16] = OTAA_APPKEY;
uint8_t ui8_NoMatch;
if (api.lorawan.nwm.get() != 1U) {
Serial.printf("Set network working mode %s\r\n", api.lorawan.nwm.set() ? "Success" : "Fail");
}
if (api.lorawan.band.get() != OTAA_BAND) {
Serial.printf("Set network band %s\r\n", api.lorawan.band.set(OTAA_BAND) ? "Success" : "Fail");
}
if (api.lorawan.njm.get() != RAK_LORA_OTAA) {
Serial.printf("Set network activation mode %s\r\n", api.lorawan.njm.set(RAK_LORA_OTAA) ? "Success" : "Fail");
}
if (api.lorawan.adr.get() != true) {
Serial.printf("Set network ADR %s\r\n", api.lorawan.adr.set(true) ? "Success" : "Fail");
}
if (api.lorawan.pnm.get() != true) {
Serial.printf("Set public network mode %s\r\n", api.lorawan.pnm.set(true) ? "Success" : "Fail");
}
if (api.system.lpmlvl.get() != 2U) {
Serial.printf("Set low power level %s\r\n", api.system.lpmlvl.set(2U) ? "Success" : "Fail");
}
if (api.system.lpm.get() != true) {
Serial.printf("Set low power mode %s\r\n", api.system.lpm.set(1U) ? "Success" : "Fail");
}
api.lorawan.deui.get(gui8_Device_EUI, 8U); // Device EUI
ui8_NoMatch = 0U;
for(uint8_t i=0U;i<=7U;i++) {
if(gui8_Device_EUI[i] != ui8_DEF_Device_EUI[i]) {
ui8_NoMatch = 1U;
}
}
if(ui8_NoMatch == 1U) {
Serial.printf("Set Device EUI %s\r\n", api.lorawan.deui.set(ui8_DEF_Device_EUI, 8U) ? "Success" : "Fail");
}
api.lorawan.appeui.get(gui8_App_EUI, 8U); // App EUI
ui8_NoMatch = 0U;
for(uint8_t i=0U;i<=7U;i++) {
if(gui8_App_EUI[i] != ui8_DEF_App_EUI[i]) {
ui8_NoMatch = 1U;
}
}
if(ui8_NoMatch == 1U) {
Serial.printf("Set App EUI %s\r\n", api.lorawan.appeui.set(ui8_DEF_App_EUI, 8U) ? "Success" : "Fail");
}
api.lorawan.appkey.get(gui8_App_KEY, 16U); // App KEY
ui8_NoMatch = 0U;
for(uint8_t i=0U;i<=15U;i++) {
if(gui8_App_KEY[i] != ui8_DEF_App_KEY[i]) {
ui8_NoMatch = 1U;
}
}
if(ui8_NoMatch == 1U) {
Serial.printf("Set App KEY %s\r\n", api.lorawan.appkey.set(ui8_DEF_App_KEY, 16U) ? "Success" : "Fail");
}
if (api.lorawan.deviceClass.get() != 0U) {
Serial.printf("Set device class %s\r\n", api.lorawan.deviceClass.set(0U) ? "Success" : "Fail");
}
if (api.lorawan.jn1dl.get() != OTAA_JN1DL) {
Serial.printf("Set join delay on RX window 1 %s\r\n", api.lorawan.jn1dl.set(OTAA_JN1DL) ? "Success" : "Fail");
}
if (api.lorawan.jn2dl.get() != OTAA_JN2DL) {
Serial.printf("Set join delay on RX window 2 %s\r\n", api.lorawan.jn2dl.set(OTAA_JN2DL) ? "Success" : "Fail");
}
Serial.printf("RX1DL before: %d\r\n", api.lorawan.rx1dl.get());
if (api.lorawan.rx1dl.get() != OTAA_RX1DL) {
Serial.printf("Set join delay on received window 1 %s\r\n", api.lorawan.rx1dl.set(OTAA_RX1DL) ? "Success" : "Fail");
}
Serial.printf("RX1DL after: %d\r\n", api.lorawan.rx1dl.get());
Serial.printf("RX2DL before: %d\r\n", api.lorawan.rx2dl.get());
if (api.lorawan.rx2dl.get() != OTAA_RX2DL) {
Serial.printf("Set join delay on received window 2 %s\r\n", api.lorawan.rx2dl.set(OTAA_RX2DL) ? "Success" : "Fail");
}
Serial.printf("RX2DL after: %d\r\n", api.lorawan.rx2dl.get());
}
The code is working as expected, read the parameter, compare and program only in case it is different. To avoid flash memory wearing out. Please, confirm this is the correct way to do it.
But, for the last two comands, RX1DL and RX2DL, the Get value is strange and does not match with the value read via AT command.
I added some Prints before and after for debug reasons:
Serial.printf("RX1DL before: %d\r\n", api.lorawan.rx1dl.get());
if (api.lorawan.rx1dl.get() != OTAA_RX1DL) {
Serial.printf("Set join delay on received window 1 %s\r\n", api.lorawan.rx1dl.set(OTAA_RX1DL) ? "Success" : "Fail");
}
Serial.printf("RX1DL after: %d\r\n", api.lorawan.rx1dl.get());
Serial.printf("RX2DL before: %d\r\n", api.lorawan.rx2dl.get());
if (api.lorawan.rx2dl.get() != OTAA_RX2DL) {
Serial.printf("Set join delay on received window 2 %s\r\n", api.lorawan.rx2dl.set(OTAA_RX2DL) ? "Success" : "Fail");
}
Serial.printf("RX2DL after: %d\r\n", api.lorawan.rx2dl.get());
See the output:
RX1DL before: -994
Set join delay on received window 1 Success
RX1DL after: 5
RX2DL before: 1005
Set join delay on received window 2 Success
RX2DL after: 6
Reading after via AT comands, the results do not match with the Get API:
AT+RX1DL=?
AT+RX1DL=4294966
AT+RX2DL=?
AT+RX2DL=0
When restarting the board, all previous commands are already programmed in the flash and the SET commands are not executed. But for the RX1DL and RX2DL they are always executed…
I tested it with previous FW versions and same problem.
Please, what can be wrong here?
