Skip to content

Commit

Permalink
[LoRaWAN] Added specific error code for no downlink received
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Mar 27, 2024
1 parent b91fd2b commit 78211e7
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 49 deletions.
2 changes: 1 addition & 1 deletion examples/LoRaWAN/LoRaWAN_ABP/LoRaWAN_ABP.ino
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void loop() {

// Perform an uplink
int state = node.sendReceive(uplinkPayload, sizeof(uplinkPayload));
debug((state != RADIOLIB_ERR_RX_TIMEOUT) && (state != RADIOLIB_ERR_NONE), F("Error in sendReceive"), state, false);
debug((state != RADIOLIB_LORAWAN_NO_DOWNLINK) && (state != RADIOLIB_ERR_NONE), F("Error in sendReceive"), state, false);

// Wait until next uplink - observing legal & TTN FUP constraints
delay(uplinkIntervalSeconds * 1000UL);
Expand Down
21 changes: 8 additions & 13 deletions examples/LoRaWAN/LoRaWAN_ABP/configABP.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#include <RadioLib.h>

// How often to send an uplink - consider legal & FUP constraints - see notes
// how often to send an uplink - consider legal & FUP constraints - see notes
const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds

// Device address - either a development address or one assigned
// device address - either a development address or one assigned
// to the LoRaWAN Service Provider - TTN will generate one for you
#ifndef RADIOLIB_LORAWAN_DEV_ADDR // Replace with your DevAddr
#define RADIOLIB_LORAWAN_DEV_ADDR 0x------
Expand All @@ -25,11 +25,10 @@ const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
#define RADIOLIB_LORAWAN_APPS_KEY 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--
#endif

// For the curious, the #ifndef blocks allow for automated testing &/or you can
// for the curious, the #ifndef blocks allow for automated testing &/or you can
// put your EUI & keys in to your platformio.ini - see wiki for more tips


// Regional choices: EU868, US915, AU915, AS923, IN865, KR920, CN780, CN500
// regional choices: EU868, US915, AU915, AS923, IN865, KR920, CN780, CN500
const LoRaWANBand_t Region = EU868;
const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0

Expand Down Expand Up @@ -99,20 +98,17 @@ const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0

#endif


// Copy over the keys in to the something that will not compile if incorrectly formatted
// copy over the keys in to the something that will not compile if incorrectly formatted
uint32_t devAddr = RADIOLIB_LORAWAN_DEV_ADDR;
uint8_t NwkSKey[] = { RADIOLIB_LORAWAN_NWKS_KEY };
uint8_t SNwkSIntKey[] = { RADIOLIB_LORAWAN_SNWKSINT_KEY }; // Previously sNwkSIntKey
uint8_t NwkSEncKey[] = { RADIOLIB_LORAWAN_NWKSENC_KEY }; // Previously fNwkSIntKey
uint8_t AppSKey[] = { RADIOLIB_LORAWAN_APPS_KEY };


// Create the LoRaWAN node
// create the LoRaWAN node
LoRaWANNode node(&radio, &Region, subBand);


// Helper function to display any issues
// helper function to display any issues
void debug(bool isFail, const __FlashStringHelper* message, int state, bool Freeze) {
if (isFail) {
Serial.print(message);
Expand All @@ -123,7 +119,7 @@ void debug(bool isFail, const __FlashStringHelper* message, int state, bool Free
}
}

// Helper function to display a byte array
// helper function to display a byte array
void arrayDump(uint8_t *buffer, uint16_t len) {
for(uint16_t c = 0; c < len; c++) {
char b = buffer[c];
Expand All @@ -133,5 +129,4 @@ void arrayDump(uint8_t *buffer, uint16_t len) {
Serial.println();
}


#endif
5 changes: 3 additions & 2 deletions examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ void loop() {
} else {
state = node.sendReceive(uplinkPayload, sizeof(uplinkPayload), Port, downlinkPayload, &downlinkSize);
}
debug((state != RADIOLIB_ERR_RX_TIMEOUT) && (state != RADIOLIB_ERR_NONE), F("Error in sendReceive"), state, false);
debug((state != RADIOLIB_LORAWAN_NO_DOWNLINK) && (state != RADIOLIB_ERR_NONE), F("Error in sendReceive"), state, false);

if(state == RADIOLIB_ERR_NONE) {
// Check if downlink was received
if(state != RADIOLIB_LORAWAN_NO_DOWNLINK) {
// Did we get a downlink with data for us
if (downlinkSize > 0) {
Serial.println(F("Downlink data: "));
Expand Down
24 changes: 9 additions & 15 deletions examples/LoRaWAN/LoRaWAN_Reference/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

#include <RadioLib.h>

// How often to send an uplink - consider legal & FUP constraints - see notes
// how often to send an uplink - consider legal & FUP constraints - see notes
const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds

// JoinEUI - previous versions of LoRaWAN called this AppEUI
// joinEUI - previous versions of LoRaWAN called this AppEUI
// for development purposes you can use all zeros - see wiki for details
#define RADIOLIB_LORAWAN_JOIN_EUI 0x0000000000000000

// The Device EUI & two keys can be generated on the TTN console
// the Device EUI & two keys can be generated on the TTN console
#ifndef RADIOLIB_LORAWAN_DEV_EUI // Replace with your Device EUI
#define RADIOLIB_LORAWAN_DEV_EUI 0x---------------
#endif
Expand All @@ -21,16 +21,13 @@ const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
#define RADIOLIB_LORAWAN_NWK_KEY 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--
#endif

// For the curious, the #ifndef blocks allow for automated testing &/or you can
// for the curious, the #ifndef blocks allow for automated testing &/or you can
// put your EUI & keys in to your platformio.ini - see wiki for more tips



// Regional choices: EU868, US915, AU915, AS923, IN865, KR920, CN780, CN500
// regional choices: EU868, US915, AU915, AS923, IN865, KR920, CN780, CN500
const LoRaWANBand_t Region = EU868;
const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0


// ============================================================================
// Below is to support the sketch - only make changes if the notes say so ...

Expand Down Expand Up @@ -96,18 +93,16 @@ const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0

#endif


// Copy over the EUI's & keys in to the something that will not compile if incorrectly formatted
// copy over the EUI's & keys in to the something that will not compile if incorrectly formatted
uint64_t joinEUI = RADIOLIB_LORAWAN_JOIN_EUI;
uint64_t devEUI = RADIOLIB_LORAWAN_DEV_EUI;
uint8_t appKey[] = { RADIOLIB_LORAWAN_APP_KEY };
uint8_t nwkKey[] = { RADIOLIB_LORAWAN_NWK_KEY };

// Create the LoRaWAN node
// create the LoRaWAN node
LoRaWANNode node(&radio, &Region, subBand);


// Helper function to display any issues
// helper function to display any issues
void debug(bool isFail, const __FlashStringHelper* message, int state, bool Freeze) {
if (isFail) {
Serial.print(message);
Expand All @@ -118,7 +113,7 @@ void debug(bool isFail, const __FlashStringHelper* message, int state, bool Free
}
}

// Helper function to display a byte array
// helper function to display a byte array
void arrayDump(uint8_t *buffer, uint16_t len) {
for(uint16_t c = 0; c < len; c++) {
char b = buffer[c];
Expand All @@ -128,5 +123,4 @@ void arrayDump(uint8_t *buffer, uint16_t len) {
Serial.println();
}


#endif
2 changes: 1 addition & 1 deletion examples/LoRaWAN/LoRaWAN_Starter/LoRaWAN_Starter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void loop() {

// Perform an uplink
int state = node.sendReceive(uplinkPayload, sizeof(uplinkPayload));
debug((state != RADIOLIB_ERR_RX_TIMEOUT) && (state != RADIOLIB_ERR_NONE), F("Error in sendReceive"), state, false);
debug((state != RADIOLIB_LORAWAN_NO_DOWNLINK) && (state != RADIOLIB_ERR_NONE), F("Error in sendReceive"), state, false);

Serial.print(F("Uplink complete, next in "));
Serial.print(uplinkIntervalSeconds);
Expand Down
24 changes: 9 additions & 15 deletions examples/LoRaWAN/LoRaWAN_Starter/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

#include <RadioLib.h>

// How often to send an uplink - consider legal & FUP constraints - see notes
// how often to send an uplink - consider legal & FUP constraints - see notes
const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds

// JoinEUI - previous versions of LoRaWAN called this AppEUI
// joinEUI - previous versions of LoRaWAN called this AppEUI
// for development purposes you can use all zeros - see wiki for details
#define RADIOLIB_LORAWAN_JOIN_EUI 0x0000000000000000

// The Device EUI & two keys can be generated on the TTN console
// the Device EUI & two keys can be generated on the TTN console
#ifndef RADIOLIB_LORAWAN_DEV_EUI // Replace with your Device EUI
#define RADIOLIB_LORAWAN_DEV_EUI 0x---------------
#endif
Expand All @@ -21,16 +21,13 @@ const uint32_t uplinkIntervalSeconds = 5UL * 60UL; // minutes x seconds
#define RADIOLIB_LORAWAN_NWK_KEY 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--, 0x--
#endif

// For the curious, the #ifndef blocks allow for automated testing &/or you can
// for the curious, the #ifndef blocks allow for automated testing &/or you can
// put your EUI & keys in to your platformio.ini - see wiki for more tips



// Regional choices: EU868, US915, AU915, AS923, IN865, KR920, CN780, CN500
// regional choices: EU868, US915, AU915, AS923, IN865, KR920, CN780, CN500
const LoRaWANBand_t Region = EU868;
const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0


// ============================================================================
// Below is to support the sketch - only make changes if the notes say so ...

Expand Down Expand Up @@ -96,18 +93,16 @@ const uint8_t subBand = 0; // For US915, change this to 2, otherwise leave on 0

#endif


// Copy over the EUI's & keys in to the something that will not compile if incorrectly formatted
// copy over the EUI's & keys in to the something that will not compile if incorrectly formatted
uint64_t joinEUI = RADIOLIB_LORAWAN_JOIN_EUI;
uint64_t devEUI = RADIOLIB_LORAWAN_DEV_EUI;
uint8_t appKey[] = { RADIOLIB_LORAWAN_APP_KEY };
uint8_t nwkKey[] = { RADIOLIB_LORAWAN_NWK_KEY };

// Create the LoRaWAN node
// create the LoRaWAN node
LoRaWANNode node(&radio, &Region, subBand);


// Helper function to display any issues
// helper function to display any issues
void debug(bool isFail, const __FlashStringHelper* message, int state, bool Freeze) {
if (isFail) {
Serial.print(message);
Expand All @@ -118,7 +113,7 @@ void debug(bool isFail, const __FlashStringHelper* message, int state, bool Free
}
}

// Helper function to display a byte array
// helper function to display a byte array
void arrayDump(uint8_t *buffer, uint16_t len) {
for(uint16_t c = 0; c < len; c++) {
char b = buffer[c];
Expand All @@ -128,5 +123,4 @@ void arrayDump(uint8_t *buffer, uint16_t len) {
Serial.println();
}


#endif
3 changes: 2 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -436,4 +436,5 @@ RADIOLIB_ERR_N_FCNT_DOWN_INVALID LITERAL1
RADIOLIB_ERR_A_FCNT_DOWN_INVALID LITERAL1
RADIOLIB_ERR_DATA_RATE_INVALID LITERAL1
RADIOLIB_ERR_DWELL_TIME_EXCEEDED LITERAL1
RADIOLIB_ERR_CHECKSUM_MISMATCH LITERAL1
RADIOLIB_ERR_CHECKSUM_MISMATCH LITERAL1
RADIOLIB_LORAWAN_NO_DOWNLINK LITERAL1
5 changes: 5 additions & 0 deletions src/TypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,11 @@
*/
#define RADIOLIB_ERR_CHECKSUM_MISMATCH (-1115)

/*!
\brief No downlink was received - most likely none was sent from the server.
*/
#define RADIOLIB_LORAWAN_NO_DOWNLINK (-1116)

/*!
\}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/LoRaWAN/LoRaWAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ int16_t LoRaWANNode::downlinkCommon() {
this->phyLayer->invertIQ(false);
}

return(RADIOLIB_ERR_RX_TIMEOUT);
return(RADIOLIB_LORAWAN_NO_DOWNLINK);
}

// wait for the DIO to fire indicating a downlink is received
Expand Down

0 comments on commit 78211e7

Please sign in to comment.