Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c9f3e98

Browse files
committedFeb 3, 2022
Use specific macros to define device topic subscription delays
1 parent 5308226 commit c9f3e98

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed
 

‎src/AIoTC_Config.h

Lines changed: 10 additions & 8 deletions
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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,10 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeDeviceTopic()
445445
return State::ConnectPhy;
446446
}
447447

448-
unsigned long reconnection_retry_delay = (1 << _last_device_subscribe_cnt) * AIOT_CONFIG_RECONNECTION_RETRY_DELAY_ms;
449-
reconnection_retry_delay = min(reconnection_retry_delay, static_cast<unsigned long>(AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms));
450-
_next_device_subscribe_attempt_tick = millis() + reconnection_retry_delay;
448+
/* No device configuration reply. Wait: 5s -> 10s -> 20s -> 30s */
449+
unsigned long subscribe_retry_delay = (1 << _last_device_subscribe_cnt) * AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms;
450+
subscribe_retry_delay = min(subscribe_retry_delay, static_cast<unsigned long>(AIOT_CONFIG_MAX_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms));
451+
_next_device_subscribe_attempt_tick = millis() + subscribe_retry_delay;
451452
_last_device_subscribe_cnt++;
452453

453454
return State::WaitDeviceConfig;
@@ -496,14 +497,10 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
496497

497498
if (deviceNotAttached())
498499
{
499-
/* start long timeout counter
500-
* return return State::SubscribeThingTopics
501-
* if long timeout expired unsubscribe and
502-
* return State::SubscribeDeviceTopic
503-
*/
504-
unsigned long reconnection_retry_delay = (1 << _last_device_subscribe_cnt) * AIOT_CONFIG_RECONNECTION_RETRY_DELAY_ms * 10000;
505-
reconnection_retry_delay = min(reconnection_retry_delay, static_cast<unsigned long>(AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms));
506-
_next_device_subscribe_attempt_tick = millis() + reconnection_retry_delay;
500+
/* Configuration received but device not attached. Wait: 40s */
501+
unsigned long subscribe_retry_delay = (1 << _last_device_subscribe_cnt) * AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms * 10;
502+
subscribe_retry_delay = min(subscribe_retry_delay, static_cast<unsigned long>(AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms * 10));
503+
_next_device_subscribe_attempt_tick = millis() + subscribe_retry_delay;
507504
_last_device_subscribe_cnt++;
508505
return State::WaitDeviceConfig;
509506
}

0 commit comments

Comments
 (0)
Please sign in to comment.