Skip to content

Commit 5db06b8

Browse files
committed
Use specific macros to define device topic subscription delays
1 parent 1b79e5e commit 5db06b8

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/AIoTC_Config.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,12 @@
140140
* CONSTANTS
141141
******************************************************************************/
142142

143-
#define AIOT_CONFIG_RECONNECTION_RETRY_DELAY_ms (1000UL)
144-
#define AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms (32000UL)
145-
#define AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms (30000UL)
146-
#define AIOT_CONFIG_LASTVALUES_SYNC_MAX_RETRY_CNT (10UL)
143+
#define AIOT_CONFIG_RECONNECTION_RETRY_DELAY_ms (1000UL)
144+
#define AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms (32000UL)
145+
#define AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms (5*1000UL)
146+
#define AIOT_CONFIG_MAX_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms (32000UL)
147+
#define AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms (30000UL)
148+
#define AIOT_CONFIG_LASTVALUES_SYNC_MAX_RETRY_CNT (10UL)
147149

148150
#define AIOT_CONFIG_RP2040_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms (10*1000UL)
149151
#define AIOT_CONFIG_RP2040_OTA_HTTP_DATA_RECEIVE_TIMEOUT_ms (4*60*1000UL)

src/ArduinoIoTCloudTCP.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,10 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeDeviceTopic()
450450
return State::ConnectPhy;
451451
}
452452

453-
unsigned long reconnection_retry_delay = (1 << _last_device_subscribe_cnt) * AIOT_CONFIG_RECONNECTION_RETRY_DELAY_ms;
454-
reconnection_retry_delay = min(reconnection_retry_delay, static_cast<unsigned long>(AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms));
455-
_next_device_subscribe_attempt_tick = millis() + reconnection_retry_delay;
453+
/* No device configuration reply. Wait: 5s -> 10s -> 20s -> 30s */
454+
unsigned long subscribe_retry_delay = (1 << _last_device_subscribe_cnt) * AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms;
455+
subscribe_retry_delay = min(subscribe_retry_delay, static_cast<unsigned long>(AIOT_CONFIG_MAX_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms));
456+
_next_device_subscribe_attempt_tick = millis() + subscribe_retry_delay;
456457
_last_device_subscribe_cnt++;
457458

458459
return State::WaitDeviceConfig;
@@ -490,7 +491,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
490491

491492
if(_deviceSubscribedToThing == true)
492493
{
493-
/* Unsubscribe from old things topics and go oi with a new subsctiption */
494+
/* Unsubscribe from old things topics and go on with a new subsctiption */
494495
_mqttClient.unsubscribe(_shadowTopicIn);
495496
_mqttClient.unsubscribe(_dataTopicIn);
496497

@@ -501,14 +502,10 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
501502

502503
if (deviceNotAttached())
503504
{
504-
/* start long timeout counter
505-
* return return State::SubscribeThingTopics
506-
* if long timeout expired unsubscribe and
507-
* return State::SubscribeDeviceTopic
508-
*/
509-
unsigned long reconnection_retry_delay = (1 << _last_device_subscribe_cnt) * AIOT_CONFIG_RECONNECTION_RETRY_DELAY_ms * 10000;
510-
reconnection_retry_delay = min(reconnection_retry_delay, static_cast<unsigned long>(AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms));
511-
_next_device_subscribe_attempt_tick = millis() + reconnection_retry_delay;
505+
/* Configuration received but device not attached. Wait: 40s */
506+
unsigned long subscribe_retry_delay = (1 << _last_device_subscribe_cnt) * AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms * 10;
507+
subscribe_retry_delay = min(subscribe_retry_delay, static_cast<unsigned long>(AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms * 10));
508+
_next_device_subscribe_attempt_tick = millis() + subscribe_retry_delay;
512509
_last_device_subscribe_cnt++;
513510
return State::WaitDeviceConfig;
514511
}

0 commit comments

Comments
 (0)