Skip to content

Commit defe4dd

Browse files
committed
Use specific macros to define device topic subscription delays
1 parent 1b4277e commit defe4dd

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

src/AIoTC_Config.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,16 @@
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_SUBSCRIBE_RETRY_DELAY_ms (1000UL)
146-
#define AIOT_CONFIG_SUBSCRIBE_MAX_RETRY_CNT (10UL)
147-
#define AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms (30000UL)
148-
#define AIOT_CONFIG_LASTVALUES_SYNC_MAX_RETRY_CNT (10UL)
149-
150-
#define AIOT_CONFIG_RP2040_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms (10*1000UL)
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_SUBSCRIBE_RETRY_DELAY_ms (1000UL)
148+
#define AIOT_CONFIG_SUBSCRIBE_MAX_RETRY_CNT (10UL)
149+
#define AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms (30000UL)
150+
#define AIOT_CONFIG_LASTVALUES_SYNC_MAX_RETRY_CNT (10UL)
151+
152+
#define AIOT_CONFIG_RP2040_OTA_HTTP_HEADER_RECEIVE_TIMEOUT_ms (10*1000UL)
151153
#define AIOT_CONFIG_RP2040_OTA_HTTP_DATA_RECEIVE_TIMEOUT_ms (4*60*1000UL)
152154

153155
#endif /* ARDUINO_AIOTC_CONFIG_H_ */

src/ArduinoIoTCloudTCP.cpp

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

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

460461
return State::WaitDeviceConfig;
@@ -492,7 +493,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
492493

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

@@ -503,14 +504,10 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
503504

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

0 commit comments

Comments
 (0)