@@ -344,13 +344,15 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_ConnectMqttBroker()
344344 return State::SendDeviceProperties;
345345 }
346346
347+ /* Can't connect to the broker. Wait: 2s -> 4s -> 8s -> 16s -> 32s -> 32s ... */
347348 _last_connection_attempt_cnt++;
348349 unsigned long reconnection_retry_delay = (1 << _last_connection_attempt_cnt) * AIOT_CONFIG_RECONNECTION_RETRY_DELAY_ms;
349350 reconnection_retry_delay = min (reconnection_retry_delay, static_cast <unsigned long >(AIOT_CONFIG_MAX_RECONNECTION_RETRY_DELAY_ms));
350351 _next_connection_attempt_tick = millis () + reconnection_retry_delay;
351352
352353 DEBUG_ERROR (" ArduinoIoTCloudTCP::%s could not connect to %s:%d" , __FUNCTION__, _brokerAddress.c_str (), _brokerPort);
353- DEBUG_ERROR (" ArduinoIoTCloudTCP::%s %d connection attempt at tick time %d" , __FUNCTION__, _last_connection_attempt_cnt, _next_connection_attempt_tick);
354+ DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s %d next connection attempt in %d ms" , __FUNCTION__, _last_connection_attempt_cnt, reconnection_retry_delay);
355+ /* Go back to ConnectPhy and retry to get time from network (invalid time for SSL handshake?)*/
354356 return State::ConnectPhy;
355357}
356358
@@ -361,6 +363,8 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SendDeviceProperties()
361363 return State::Disconnect;
362364 }
363365
366+ DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s announce device to the Cloud %d" , __FUNCTION__, _time_service.getTime ());
367+ /* TODO check if write fails */
364368 sendDevicePropertiesToCloud ();
365369 return State::WaitDeviceConfig;
366370}
@@ -372,22 +376,30 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeDeviceTopic()
372376 return State::Disconnect;
373377 }
374378
379+ DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s request device configuration %d" , __FUNCTION__, _time_service.getTime ());
380+
375381 if (!_mqttClient.subscribe (_deviceTopicIn))
376382 {
383+ /* If device_id is wrong the board can't connect to the broker so this condition
384+ * should never happen.
385+ */
377386 DEBUG_ERROR (" ArduinoIoTCloudTCP::%s could not subscribe to %s" , __FUNCTION__, _deviceTopicIn.c_str ());
378387 }
379388
389+ /* Max retry than disconnect */
380390 if (_last_device_subscribe_cnt > AIOT_CONFIG_LASTVALUES_SYNC_MAX_RETRY_CNT)
381391 {
382392 _last_device_subscribe_cnt = 0 ;
383393 _next_device_subscribe_attempt_tick = 0 ;
384394 return State::Disconnect;
385395 }
386396
397+ /* No device configuration received. Wait: 4s -> 8s -> 16s -> 32s -> 32s ...*/
387398 _last_device_subscribe_cnt++;
388399 unsigned long subscribe_retry_delay = (1 << _last_device_subscribe_cnt) * AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms;
389400 subscribe_retry_delay = min (subscribe_retry_delay, static_cast <unsigned long >(AIOT_CONFIG_MAX_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms));
390401 _next_device_subscribe_attempt_tick = millis () + subscribe_retry_delay;
402+ DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s %d next configuration request in %d ms" , __FUNCTION__, _last_device_subscribe_cnt, subscribe_retry_delay);
391403
392404 return State::WaitDeviceConfig;
393405}
@@ -405,7 +417,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
405417 /* Configuration not received or device not attached to a valid thing. Try to resubscribe */
406418 if (_mqttClient.unsubscribe (_deviceTopicIn))
407419 {
408- DEBUG_ERROR (" ArduinoIoTCloudTCP::%s device waiting for valid thing_id" , __FUNCTION__);
420+ DEBUG_ERROR (" ArduinoIoTCloudTCP::%s device waiting for valid thing_id %d " , __FUNCTION__, _time_service. getTime () );
409421 }
410422 }
411423
@@ -432,10 +444,12 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
432444 unsigned long attach_retry_delay = (1 << _last_device_subscribe_cnt) * AIOT_CONFIG_DEVICE_TOPIC_ATTACH_RETRY_DELAY_ms;
433445 attach_retry_delay = min (attach_retry_delay, static_cast <unsigned long >(AIOT_CONFIG_MAX_DEVICE_TOPIC_ATTACH_RETRY_DELAY_ms));
434446 _next_device_subscribe_attempt_tick = millis () + attach_retry_delay;
447+
448+ DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s device not attached, next configuration request in %d ms" , __FUNCTION__, attach_retry_delay);
435449 return State::WaitDeviceConfig;
436450 }
437451
438- DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s Device attached to a new valid Thing %s" , __FUNCTION__, getThingId ().c_str ());
452+ DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s device attached to a new valid thing_id %s %d " , __FUNCTION__, getThingId ().c_str (), _time_service. getTime ());
439453
440454 /* Received valid thing_id reset counters and go on */
441455 _last_device_subscribe_cnt = 0 ;
0 commit comments