[LoRaWAN] Custom return codes for session begin

This commit is contained in:
StevenCellist 2024-05-10 11:55:17 +02:00
parent f29f4b25ba
commit b7748206a2
5 changed files with 21 additions and 8 deletions

View file

@ -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"));
}

View file

@ -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: ");

View file

@ -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"));
}

View file

@ -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
/*!

View file

@ -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<uint32_t>(&this->bufferSession[RADIOLIB_LW_SESSION_HOMENET_ID], this->homeNetId);
LoRaWANNode::hton<uint8_t>(&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 {