Skip to content

Commit 047540a

Browse files
committed
Use specific macros to define device topic subscription delays
1 parent 33c27b1 commit 047540a

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/AIoTC_Config.h

+6-4
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

+9-12
Original file line numberDiff line numberDiff line change
@@ -451,9 +451,10 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeDeviceTopic()
451451
return State::ConnectPhy;
452452
}
453453

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

459460
return State::WaitDeviceConfig;
@@ -491,7 +492,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
491492

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

@@ -502,14 +503,10 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
502503

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

0 commit comments

Comments
 (0)