From 483c82f9f5e11a5ba7d9e3774948846812c14f57 Mon Sep 17 00:00:00 2001 From: REGIOIGER Date: Tue, 25 Jun 2024 16:50:31 -0600 Subject: [PATCH 1/2] fix: esp32 #197 Downlink no longer works --- src/arduino-rfm/lorawan-arduino-rfm.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/arduino-rfm/lorawan-arduino-rfm.cpp b/src/arduino-rfm/lorawan-arduino-rfm.cpp index 8981b63..8deb168 100644 --- a/src/arduino-rfm/lorawan-arduino-rfm.cpp +++ b/src/arduino-rfm/lorawan-arduino-rfm.cpp @@ -112,8 +112,8 @@ bool LoRaWANClass::init(void) LoRa_Settings.Channel_Hopping = 0x00; //0x00 no channel hopping, 0x01 channel hopping // Set default rx delay and window - LoRa_Settings.Rx1_Delay = 1000; // Thing stack seems to be 5000 ms (so Rx2_delay 6000 ms) - LoRa_Settings.Rx2_Delay = 2000; // Rx2_Delay >= Rx1_Delay + RX1_Window + LoRa_Settings.Rx1_Delay = 5000; // Thing stack seems to be 5000 ms (so Rx2_delay 6000 ms) + LoRa_Settings.Rx2_Delay = 6000; // Rx2_Delay >= Rx1_Delay + RX1_Window LoRa_Settings.RX1_Window = 1000; LoRa_Settings.RX2_Window = 1000; @@ -263,7 +263,10 @@ void LoRaWANClass::setAppSKey(const char *ApskKey_in) void LoRaWANClass::setDevAddr(const char *devAddr_in) { - memset(Session_Data.DevAddr, 0x30, sizeof(Session_Data.DevAddr)); + //memset(Session_Data.DevAddr, 0x30, sizeof(Session_Data.DevAddr)); + + size_t devAddrSize = sizeof(Session_Data.DevAddr); + memset(Session_Data.DevAddr, 0x30, devAddrSize); //Check if it is a set command and there is enough data sent Address_Tx[0] = ASCII2Hex(devAddr_in[0], devAddr_in[1]); @@ -340,7 +343,8 @@ void LoRaWANClass::sendACK() //Set new command for RFM RFM_Command_Status = NEW_RFM_COMMAND; upMsg_Type = MSG_ACK; - sprintf(Str, ""); + //sprintf(Str, ""); + Str[0] = '\0'; memcpy(Buffer_Tx.Data, Str, sizeof(Str)); } @@ -503,7 +507,8 @@ void LoRaWANClass::update(void) bool isConfirmed = ((Message_Rx.MAC_Header & 0xE0)>>5) == 5 ? true : false ; // MType uint8_t fPort = Message_Rx.Frame_Port; if(lora.messageCallback) lora.messageCallback(&Buffer_Rx, isConfirmed, fPort); - Buffer_Rx.Counter = 0x00; // clear counter for the next cycle + //Buffer_Rx.Counter = 0x00; // clear counter for the next cycle + Rx_Status = NEW_RX; Serial.println("Data received over RX1"); } From 35b2d3227fd7a186a0f3dcf801ae23b08b9bd379 Mon Sep 17 00:00:00 2001 From: REGIOIGER Date: Fri, 2 Aug 2024 12:46:00 -0600 Subject: [PATCH 2/2] refactor: RX2 delay setting --- src/arduino-rfm/lorawan-arduino-rfm.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/arduino-rfm/lorawan-arduino-rfm.cpp b/src/arduino-rfm/lorawan-arduino-rfm.cpp index 8deb168..9201612 100644 --- a/src/arduino-rfm/lorawan-arduino-rfm.cpp +++ b/src/arduino-rfm/lorawan-arduino-rfm.cpp @@ -112,10 +112,12 @@ bool LoRaWANClass::init(void) LoRa_Settings.Channel_Hopping = 0x00; //0x00 no channel hopping, 0x01 channel hopping // Set default rx delay and window - LoRa_Settings.Rx1_Delay = 5000; // Thing stack seems to be 5000 ms (so Rx2_delay 6000 ms) - LoRa_Settings.Rx2_Delay = 6000; // Rx2_Delay >= Rx1_Delay + RX1_Window LoRa_Settings.RX1_Window = 1000; LoRa_Settings.RX2_Window = 1000; + + LoRa_Settings.Rx1_Delay = 5000; // Thing stack seems to be 5000 ms (so Rx2_delay 6000 ms) + LoRa_Settings.Rx2_Delay = LoRa_Settings.Rx1_Delay + LoRa_Settings.RX1_Window; + // Initialise buffer for data to transmit memset(Data_Tx, 0x00, sizeof(Data_Tx)); @@ -507,7 +509,6 @@ void LoRaWANClass::update(void) bool isConfirmed = ((Message_Rx.MAC_Header & 0xE0)>>5) == 5 ? true : false ; // MType uint8_t fPort = Message_Rx.Frame_Port; if(lora.messageCallback) lora.messageCallback(&Buffer_Rx, isConfirmed, fPort); - //Buffer_Rx.Counter = 0x00; // clear counter for the next cycle Rx_Status = NEW_RX; Serial.println("Data received over RX1");