@@ -468,7 +468,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
468
468
469
469
if (millis () > _next_device_subscribe_attempt_tick)
470
470
{
471
- /* Configuration not received try to resubscribe */
471
+ /* Configuration not received or device not attached to a valid thing. Try to resubscribe */
472
472
if (_mqttClient.unsubscribe (_deviceTopicIn))
473
473
{
474
474
return State::SubscribeDeviceTopic;
@@ -489,7 +489,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
489
489
/* Unsubscribe from old things topics and go on with a new subsctiption */
490
490
_mqttClient.unsubscribe (_shadowTopicIn);
491
491
_mqttClient.unsubscribe (_dataTopicIn);
492
-
493
492
_deviceSubscribedToThing = false ;
494
493
}
495
494
@@ -498,13 +497,16 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
498
497
if (deviceNotAttached ())
499
498
{
500
499
/* 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 ;
504
- _last_device_subscribe_cnt ++;
500
+ unsigned long attach_retry_delay = (1 << _last_device_attach_cnt ) * AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms;
501
+ attach_retry_delay = min (attach_retry_delay , static_cast <unsigned long >(AIOT_CONFIG_MAX_DEVICE_TOPIC_ATTACH_RETRY_DELAY_ms ));
502
+ _next_device_subscribe_attempt_tick = millis () + attach_retry_delay ;
503
+ _last_device_attach_cnt ++;
505
504
return State::WaitDeviceConfig;
506
505
}
507
506
507
+ DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s Device attached to a new valid Thing %s" , __FUNCTION__, getThingId ().c_str ());
508
+ _last_device_attach_cnt = 0 ;
509
+
508
510
return State::SubscribeThingTopics;
509
511
}
510
512
@@ -563,6 +565,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeThingTopics()
563
565
execCloudEventCallback (ArduinoIoTCloudEvent::CONNECT);
564
566
_deviceSubscribedToThing = true ;
565
567
568
+ /* Add retry wait time otherwise we are trying to reconnect every 250ms...*/
566
569
return State::RequestLastValues;
567
570
}
568
571
0 commit comments