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