diff --git a/examples/LoRaWAN/LoRaWAN_ABP/LoRaWAN_ABP.ino b/examples/LoRaWAN/LoRaWAN_ABP/LoRaWAN_ABP.ino index 7b199c3e..99c65225 100644 --- a/examples/LoRaWAN/LoRaWAN_ABP/LoRaWAN_ABP.ino +++ b/examples/LoRaWAN/LoRaWAN_ABP/LoRaWAN_ABP.ino @@ -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); diff --git a/examples/LoRaWAN/LoRaWAN_ABP/configABP.h b/examples/LoRaWAN/LoRaWAN_ABP/configABP.h index 5d8d29e1..a536ff14 100644 --- a/examples/LoRaWAN/LoRaWAN_ABP/configABP.h +++ b/examples/LoRaWAN/LoRaWAN_ABP/configABP.h @@ -3,10 +3,10 @@ #include -// 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------ @@ -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 @@ -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); @@ -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]; @@ -133,5 +129,4 @@ void arrayDump(uint8_t *buffer, uint16_t len) { Serial.println(); } - #endif diff --git a/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino b/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino index 23d2ef75..ad49a261 100644 --- a/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino +++ b/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino @@ -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: ")); diff --git a/examples/LoRaWAN/LoRaWAN_Reference/config.h b/examples/LoRaWAN/LoRaWAN_Reference/config.h index b9c1bf71..cb681da2 100644 --- a/examples/LoRaWAN/LoRaWAN_Reference/config.h +++ b/examples/LoRaWAN/LoRaWAN_Reference/config.h @@ -3,14 +3,14 @@ #include -// 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 @@ -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 ... @@ -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); @@ -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]; @@ -128,5 +123,4 @@ void arrayDump(uint8_t *buffer, uint16_t len) { Serial.println(); } - #endif diff --git a/examples/LoRaWAN/LoRaWAN_Starter/LoRaWAN_Starter.ino b/examples/LoRaWAN/LoRaWAN_Starter/LoRaWAN_Starter.ino index 72c65096..0914c1c0 100644 --- a/examples/LoRaWAN/LoRaWAN_Starter/LoRaWAN_Starter.ino +++ b/examples/LoRaWAN/LoRaWAN_Starter/LoRaWAN_Starter.ino @@ -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); diff --git a/examples/LoRaWAN/LoRaWAN_Starter/config.h b/examples/LoRaWAN/LoRaWAN_Starter/config.h index b9c1bf71..cb681da2 100644 --- a/examples/LoRaWAN/LoRaWAN_Starter/config.h +++ b/examples/LoRaWAN/LoRaWAN_Starter/config.h @@ -3,14 +3,14 @@ #include -// 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 @@ -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 ... @@ -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); @@ -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]; @@ -128,5 +123,4 @@ void arrayDump(uint8_t *buffer, uint16_t len) { Serial.println(); } - #endif diff --git a/keywords.txt b/keywords.txt index 48efe632..cb129454 100644 --- a/keywords.txt +++ b/keywords.txt @@ -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 \ No newline at end of file +RADIOLIB_ERR_CHECKSUM_MISMATCH LITERAL1 +RADIOLIB_LORAWAN_NO_DOWNLINK LITERAL1 diff --git a/src/TypeDef.h b/src/TypeDef.h index 818d99d5..6cb67247 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -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) + /*! \} */ diff --git a/src/protocols/LoRaWAN/LoRaWAN.cpp b/src/protocols/LoRaWAN/LoRaWAN.cpp index 0e7692c3..a29aaf1b 100644 --- a/src/protocols/LoRaWAN/LoRaWAN.cpp +++ b/src/protocols/LoRaWAN/LoRaWAN.cpp @@ -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