@@ -475,7 +475,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
475
475
476
476
if (millis () > _next_device_subscribe_attempt_tick)
477
477
{
478
- /* Configuration not received try to resubscribe */
478
+ /* Configuration not received or device not attached to a valid thing. Try to resubscribe */
479
479
if (_mqttClient.unsubscribe (_deviceTopicIn))
480
480
{
481
481
return State::SubscribeDeviceTopic;
@@ -496,7 +496,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
496
496
/* Unsubscribe from old things topics and go on with a new subsctiption */
497
497
_mqttClient.unsubscribe (_shadowTopicIn);
498
498
_mqttClient.unsubscribe (_dataTopicIn);
499
-
500
499
_deviceSubscribedToThing = false ;
501
500
}
502
501
@@ -505,13 +504,16 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
505
504
if (deviceNotAttached ())
506
505
{
507
506
/* 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 ;
511
- _last_device_subscribe_cnt ++;
507
+ unsigned long attach_retry_delay = (1 << _last_device_attach_cnt ) * AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms;
508
+ attach_retry_delay = min (attach_retry_delay , static_cast <unsigned long >(AIOT_CONFIG_MAX_DEVICE_TOPIC_ATTACH_RETRY_DELAY_ms ));
509
+ _next_device_subscribe_attempt_tick = millis () + attach_retry_delay ;
510
+ _last_device_attach_cnt ++;
512
511
return State::WaitDeviceConfig;
513
512
}
514
513
514
+ DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s Device attached to a new valid Thing %s" , __FUNCTION__, getThingId ().c_str ());
515
+ _last_device_attach_cnt = 0 ;
516
+
515
517
return State::SubscribeThingTopics;
516
518
}
517
519
@@ -570,6 +572,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeThingTopics()
570
572
execCloudEventCallback (ArduinoIoTCloudEvent::CONNECT);
571
573
_deviceSubscribedToThing = true ;
572
574
575
+ /* Add retry wait time otherwise we are trying to reconnect every 250ms...*/
573
576
return State::RequestLastValues;
574
577
}
575
578
0 commit comments