@@ -53,22 +53,16 @@ unsigned long getTime()
5353 return ArduinoCloud.getInternalTime ();
5454}
5555
56- void updateTimezoneInfo ()
57- {
58- ArduinoCloud.updateInternalTimezoneInfo ();
59- }
60-
61- void setThingIdOutdated ()
62- {
63- ArduinoCloud.setThingIdOutdatedFlag ();
64- }
65-
6656/* *****************************************************************************
6757 CTOR/DTOR
6858 ******************************************************************************/
6959
7060ArduinoIoTCloudTCP::ArduinoIoTCloudTCP ()
7161: _state{State::ConnectPhy}
62+ , _tz_offset{0 }
63+ , _tz_offset_property{nullptr }
64+ , _tz_dst_until{0 }
65+ , _tz_dst_until_property{nullptr }
7266, _next_connection_attempt_tick{0 }
7367, _last_connection_attempt_cnt{0 }
7468, _next_device_subscribe_attempt_tick{0 }
@@ -218,10 +212,11 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
218212 addPropertyToContainer (_device_property_container, *p, " OTA_REQ" , Permission::ReadWrite, -1 );
219213#endif /* OTA_ENABLED */
220214 p = new CloudWrapperString (_thing_id);
221- addPropertyToContainer (_device_property_container, *p, " thing_id" , Permission::ReadWrite, -1 ).onUpdate (setThingIdOutdated);
222-
223- addPropertyReal (_tz_offset, " tz_offset" , Permission::ReadWrite).onSync (CLOUD_WINS).onUpdate (updateTimezoneInfo);
224- addPropertyReal (_tz_dst_until, " tz_dst_until" , Permission::ReadWrite).onSync (CLOUD_WINS).onUpdate (updateTimezoneInfo);
215+ _thing_id_property = &addPropertyToContainer (_device_property_container, *p, " thing_id" , Permission::ReadWrite, -1 ).writeOnDemand ();
216+ p = new CloudWrapperInt (_tz_offset);
217+ _tz_offset_property = &addPropertyToContainer (_thing_property_container, *p, " tz_offset" , Permission::ReadWrite, -1 ).writeOnDemand ();
218+ p = new CloudWrapperUnsignedInt (_tz_dst_until);
219+ _tz_dst_until_property = &addPropertyToContainer (_thing_property_container, *p, " tz_dst_until" , Permission::ReadWrite, -1 ).writeOnDemand ();
225220
226221#if OTA_ENABLED
227222 _ota_cap = OTA::isCapable ();
@@ -409,7 +404,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
409404 return State::Disconnect;
410405 }
411406
412- if (getThingIdOutdatedFlag ())
407+ if (_thing_id_property-> isDifferentFromCloud ())
413408 {
414409 return State::CheckDeviceConfig;
415410 }
@@ -445,7 +440,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
445440
446441 updateThingTopics ();
447442
448- if (deviceNotAttached () )
443+ if (_thing_id. length () == 0 )
449444 {
450445 /* Configuration received but device not attached. Wait: 40s */
451446 unsigned long attach_retry_delay = (1 << _last_device_attach_cnt) * AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms;
@@ -468,7 +463,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeThingTopics()
468463 return State::Disconnect;
469464 }
470465
471- if (getThingIdOutdatedFlag ())
466+ if (_thing_id_property-> isDifferentFromCloud ())
472467 {
473468 return State::CheckDeviceConfig;
474469 }
@@ -524,7 +519,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()
524519 return State::Disconnect;
525520 }
526521
527- if (getThingIdOutdatedFlag ())
522+ if (_thing_id_property-> isDifferentFromCloud ())
528523 {
529524 return State::CheckDeviceConfig;
530525 }
@@ -567,7 +562,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
567562 /* We are connected so let's to our stuff here. */
568563 else
569564 {
570- if (getThingIdOutdatedFlag ())
565+ if (_thing_id_property-> isDifferentFromCloud ())
571566 {
572567 return State::CheckDeviceConfig;
573568 }
@@ -589,13 +584,23 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
589584 _mqtt_data_request_retransmit = false ;
590585 }
591586
587+ /* Configure Time service with timezone data:
588+ * _tz_offset [offset + dst]
589+ * _tz_dst_until [posix timestamp until _tz_offset is valid]
590+ */
591+ if (_tz_offset_property->isDifferentFromCloud () || _tz_dst_until_property->isDifferentFromCloud ()) {
592+ _tz_offset_property->fromCloudToLocal ();
593+ _tz_dst_until_property->fromCloudToLocal ();
594+ _time_service.setTimeZoneData (_tz_offset, _tz_dst_until);
595+ }
596+
592597 /* Check if any properties need encoding and send them to
593598 * the cloud if necessary.
594599 */
595600 sendThingPropertiesToCloud ();
596601
597602 unsigned long const internal_posix_time = _time_service.getTime ();
598- if (internal_posix_time < _tz_dst_until) {
603+ if (internal_posix_time < _tz_dst_until) {
599604 return State::Connected;
600605 } else {
601606 return State::RequestLastValues;
@@ -762,12 +767,12 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l
762767
763768void ArduinoIoTCloudTCP::updateThingTopics ()
764769{
770+ _thing_id_property->fromCloudToLocal ();
771+
765772 _shadowTopicOut = getTopic_shadowout ();
766773 _shadowTopicIn = getTopic_shadowin ();
767774 _dataTopicOut = getTopic_dataout ();
768775 _dataTopicIn = getTopic_datain ();
769-
770- clrThingIdOutdatedFlag ();
771776}
772777
773778/* *****************************************************************************
0 commit comments