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