Skip to content

Commit 62dd486

Browse files
committed
identify backoff logic
1 parent f245a02 commit 62dd486

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/ArduinoIoTCloudNotecard.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
* CONSTANTS
4444
******************************************************************************/
4545

46+
#ifdef BACKOFF
4647
static size_t const BACKOFF_BASE_MS = 60000; // 1 minute
4748
static uint32_t const BACKOFF_MAX_MS = 3600000; // 1 hour
49+
#endif
4850
static size_t const CBOR_NOTE_MSG_MAX_SIZE = 255;
4951
static size_t const DEFAULT_READ_INTERVAL_MS = 1000; // 1 second
5052
static size_t const FAILSAFE_READ_INTERVAL_MS = 10000; // 10 seconds
@@ -74,8 +76,10 @@ ArduinoIoTCloudNotecard::ArduinoIoTCloudNotecard()
7476
,_message_stream(std::bind(&ArduinoIoTCloudNotecard::sendMessage, this, std::placeholders::_1))
7577
,_thing(&_message_stream)
7678
,_device(&_message_stream)
79+
#ifdef BACKOFF
7780
,_backoff_multiplier{1}
7881
,_last_failed_attach_request_ms{0}
82+
#endif
7983
,_notecard_last_read_ms{static_cast<uint32_t>(-DEFAULT_READ_INTERVAL_MS)}
8084
,_notecard_read_interval_ms{DEFAULT_READ_INTERVAL_MS}
8185
,_interrupt_pin{-1}
@@ -217,6 +221,7 @@ ArduinoIoTCloudNotecard::State ArduinoIoTCloudNotecard::handle_Connected()
217221
/* Poll Notecard for new messages */
218222
pollNotecard();
219223

224+
#ifdef BACKOFF
220225
/* Respect back-off */
221226
if (_last_failed_attach_request_ms) {
222227
const uint32_t backoff_ms = (BACKOFF_BASE_MS * _backoff_multiplier);
@@ -228,6 +233,7 @@ ArduinoIoTCloudNotecard::State ArduinoIoTCloudNotecard::handle_Connected()
228233
_last_failed_attach_request_ms = 0;
229234
}
230235
}
236+
#endif
231237

232238
/* Call CloudDevice process to get configuration */
233239
_device.update();
@@ -395,20 +401,23 @@ void ArduinoIoTCloudNotecard::processCommand(const uint8_t *buf, size_t len)
395401
String new_thing_id = String(command.thingUpdateCmd.params.thing_id);
396402

397403
if (!new_thing_id.length()) {
404+
#ifdef BACKOFF
398405
_last_failed_attach_request_ms = ::millis();
399406
DEBUG_DEBUG("ArduinoIoTCloudNotecard::%s received null Thing ID (current back-off: %u minute%s).", __FUNCTION__, _backoff_multiplier, ((_backoff_multiplier == 1) ? "" : "s"));
407+
#endif
400408
_thing_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
401409

402410
/* Send message to device state machine to inform we have received a null thing-id */
403411
Message message;
404412
message = { DeviceRegisteredCmdId };
405413
_device.handleMessage(&message);
406414
} else {
415+
#ifdef BACKOFF
407416
DEBUG_VERBOSE("ArduinoIoTCloudNotecard::%s resetting back-off variables", __FUNCTION__);
408417
/* Reset back-off variables */
409418
_backoff_multiplier = 1;
410419
_last_failed_attach_request_ms = 0;
411-
420+
#endif
412421
if (_device.isAttached() && _thing_id != new_thing_id) {
413422
DEBUG_DEBUG("ArduinoIoTCloudNotecard::%s detaching Thing ID: %s", __FUNCTION__, _thing_id.c_str());
414423
detachThing();

src/ArduinoIoTCloudNotecard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ class ArduinoIoTCloudNotecard : public ArduinoIoTCloudClass
107107
ArduinoCloudDevice _device;
108108

109109
// Notecard member variables
110+
#ifdef BACKOFF
110111
uint32_t _backoff_multiplier;
111112
uint32_t _last_failed_attach_request_ms;
113+
#endif // BACKOFF
112114
uint32_t _notecard_last_read_ms;
113115
uint32_t _notecard_read_interval_ms;
114116
int _interrupt_pin;

0 commit comments

Comments
 (0)