43
43
* CONSTANTS
44
44
******************************************************************************/
45
45
46
+ #ifdef BACKOFF
46
47
static size_t const BACKOFF_BASE_MS = 60000 ; // 1 minute
47
48
static uint32_t const BACKOFF_MAX_MS = 3600000 ; // 1 hour
49
+ #endif
48
50
static size_t const CBOR_NOTE_MSG_MAX_SIZE = 255 ;
49
51
static size_t const DEFAULT_READ_INTERVAL_MS = 1000 ; // 1 second
50
52
static size_t const FAILSAFE_READ_INTERVAL_MS = 10000 ; // 10 seconds
@@ -74,8 +76,10 @@ ArduinoIoTCloudNotecard::ArduinoIoTCloudNotecard()
74
76
,_message_stream(std::bind(&ArduinoIoTCloudNotecard::sendMessage, this , std::placeholders::_1))
75
77
,_thing(&_message_stream)
76
78
,_device(&_message_stream)
79
+ #ifdef BACKOFF
77
80
,_backoff_multiplier{1 }
78
81
,_last_failed_attach_request_ms{0 }
82
+ #endif
79
83
,_notecard_last_read_ms{static_cast <uint32_t >(-DEFAULT_READ_INTERVAL_MS)}
80
84
,_notecard_read_interval_ms{DEFAULT_READ_INTERVAL_MS}
81
85
,_interrupt_pin{-1 }
@@ -217,6 +221,7 @@ ArduinoIoTCloudNotecard::State ArduinoIoTCloudNotecard::handle_Connected()
217
221
/* Poll Notecard for new messages */
218
222
pollNotecard ();
219
223
224
+ #ifdef BACKOFF
220
225
/* Respect back-off */
221
226
if (_last_failed_attach_request_ms) {
222
227
const uint32_t backoff_ms = (BACKOFF_BASE_MS * _backoff_multiplier);
@@ -228,6 +233,7 @@ ArduinoIoTCloudNotecard::State ArduinoIoTCloudNotecard::handle_Connected()
228
233
_last_failed_attach_request_ms = 0 ;
229
234
}
230
235
}
236
+ #endif
231
237
232
238
/* Call CloudDevice process to get configuration */
233
239
_device.update ();
@@ -395,20 +401,23 @@ void ArduinoIoTCloudNotecard::processCommand(const uint8_t *buf, size_t len)
395
401
String new_thing_id = String (command.thingUpdateCmd .params .thing_id );
396
402
397
403
if (!new_thing_id.length ()) {
404
+ #ifdef BACKOFF
398
405
_last_failed_attach_request_ms = ::millis ();
399
406
DEBUG_DEBUG (" ArduinoIoTCloudNotecard::%s received null Thing ID (current back-off: %u minute%s)." , __FUNCTION__, _backoff_multiplier, ((_backoff_multiplier == 1 ) ? " " : " s" ));
407
+ #endif
400
408
_thing_id = " xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ;
401
409
402
410
/* Send message to device state machine to inform we have received a null thing-id */
403
411
Message message;
404
412
message = { DeviceRegisteredCmdId };
405
413
_device.handleMessage (&message);
406
414
} else {
415
+ #ifdef BACKOFF
407
416
DEBUG_VERBOSE (" ArduinoIoTCloudNotecard::%s resetting back-off variables" , __FUNCTION__);
408
417
/* Reset back-off variables */
409
418
_backoff_multiplier = 1 ;
410
419
_last_failed_attach_request_ms = 0 ;
411
-
420
+ # endif
412
421
if (_device.isAttached () && _thing_id != new_thing_id) {
413
422
DEBUG_DEBUG (" ArduinoIoTCloudNotecard::%s detaching Thing ID: %s" , __FUNCTION__, _thing_id.c_str ());
414
423
detachThing ();
0 commit comments