diff --git a/examples/LoRaWAN/LoRaWAN_ABP/LoRaWAN_ABP.ino b/examples/LoRaWAN/LoRaWAN_ABP/LoRaWAN_ABP.ino index 637efa80..02ffb7d6 100644 --- a/examples/LoRaWAN/LoRaWAN_ABP/LoRaWAN_ABP.ino +++ b/examples/LoRaWAN/LoRaWAN_ABP/LoRaWAN_ABP.ino @@ -43,7 +43,7 @@ void setup() { Serial.println(F("Initialise LoRaWAN Network credentials")); state = node.beginABP(devAddr, fNwkSIntKey, sNwkSIntKey, nwkSEncKey, appSKey, true); - debug(state < RADIOLIB_ERR_NONE, F("Session setup failed"), state, true); + debug(state != RADIOLIB_LORAWAN_NEW_SESSION, F("Session setup failed"), state, true); Serial.println(F("Ready!\n")); } diff --git a/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino b/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino index f45830a1..7e2947a6 100644 --- a/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino +++ b/examples/LoRaWAN/LoRaWAN_Reference/LoRaWAN_Reference.ino @@ -46,11 +46,11 @@ void setup() { debug(state != RADIOLIB_ERR_NONE, F("Initialise radio failed"), state, true); // Override the default join rate - // uint8_t joinDR = 3; + uint8_t joinDR = 4; Serial.println(F("Join ('login') to the LoRaWAN Network")); - state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey, true); - debug(state < RADIOLIB_ERR_NONE, F("Join failed"), state, true); + state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey, true, joinDR); + debug(state != RADIOLIB_LORAWAN_NEW_SESSION, F("Join failed"), state, true); // Print the DevAddr Serial.print("[LoRaWAN] DevAddr: "); diff --git a/examples/LoRaWAN/LoRaWAN_Starter/LoRaWAN_Starter.ino b/examples/LoRaWAN/LoRaWAN_Starter/LoRaWAN_Starter.ino index c9b32eb3..6b802572 100644 --- a/examples/LoRaWAN/LoRaWAN_Starter/LoRaWAN_Starter.ino +++ b/examples/LoRaWAN/LoRaWAN_Starter/LoRaWAN_Starter.ino @@ -35,8 +35,8 @@ void setup() { debug(state != RADIOLIB_ERR_NONE, F("Initialise radio failed"), state, true); Serial.println(F("Join ('login') to the LoRaWAN Network")); - state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey, true); - debug(state < RADIOLIB_ERR_NONE, F("Join failed"), state, true); + state = node.beginOTAA(joinEUI, devEUI, nwkKey, appKey); + debug(state != RADIOLIB_LORAWAN_NEW_SESSION, F("Join failed"), state, true); Serial.println(F("Ready!\n")); } diff --git a/src/TypeDef.h b/src/TypeDef.h index 245eb72a..c90c0ebe 100644 --- a/src/TypeDef.h +++ b/src/TypeDef.h @@ -563,6 +563,16 @@ */ #define RADIOLIB_LORAWAN_NO_DOWNLINK (-1116) +/*! + \brief The LoRaWAN session was successfully re-activated. +*/ +#define RADIOLIB_LORAWAN_SESSION_RESTORED (-1117) + +/*! + \brief A new LoRaWAN session is started. +*/ +#define RADIOLIB_LORAWAN_NEW_SESSION (-1118) + // LR11x0-specific status codes /*! diff --git a/src/protocols/LoRaWAN/LoRaWAN.cpp b/src/protocols/LoRaWAN/LoRaWAN.cpp index 32c7b83b..2ca3760e 100644 --- a/src/protocols/LoRaWAN/LoRaWAN.cpp +++ b/src/protocols/LoRaWAN/LoRaWAN.cpp @@ -452,7 +452,7 @@ int16_t LoRaWANNode::beginOTAA(uint64_t joinEUI, uint64_t devEUI, uint8_t* nwkKe // if the device is activated with a valid session, and user didn't force a new session, return if(this->isJoined() && !force) { - return(RADIOLIB_ERR_NONE); + return(RADIOLIB_LORAWAN_SESSION_RESTORED); } int16_t state = RADIOLIB_ERR_UNKNOWN; @@ -718,7 +718,7 @@ int16_t LoRaWANNode::beginOTAA(uint64_t joinEUI, uint64_t devEUI, uint8_t* nwkKe LoRaWANNode::hton(&this->bufferSession[RADIOLIB_LW_SESSION_HOMENET_ID], this->homeNetId); LoRaWANNode::hton(&this->bufferSession[RADIOLIB_LW_SESSION_VERSION], this->rev); - return(RADIOLIB_ERR_NONE); + return(RADIOLIB_LORAWAN_NEW_SESSION); } int16_t LoRaWANNode::beginABP(uint32_t addr, uint8_t* fNwkSIntKey, uint8_t* sNwkSIntKey, uint8_t* nwkSEncKey, uint8_t* appSKey, bool force, uint8_t initialDr) { @@ -1955,6 +1955,9 @@ void LoRaWANNode::setADR(bool enable) { void LoRaWANNode::setDutyCycle(bool enable, RadioLibTime_t msPerHour) { this->dutyCycleEnabled = enable; + if(!enable) { + this->dutyCycle = 0; + } if(msPerHour <= 0) { this->dutyCycle = this->band->dutyCycle; } else {