[LoRaWAN] Added specific error code for no downlink received

pull/1044/head
jgromes 2024-03-27 18:48:16 +01:00
rodzic b91fd2bdad
commit 78211e7566
9 zmienionych plików z 39 dodań i 49 usunięć

Wyświetl plik

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

Wyświetl plik

@ -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------
@ -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

Wyświetl plik

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

Wyświetl plik

@ -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
@ -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

Wyświetl plik

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

Wyświetl plik

@ -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
@ -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

Wyświetl plik

@ -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

Wyświetl plik

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

Wyświetl plik

@ -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