@@ -53,17 +53,16 @@ unsigned long getTime()
53
53
return ArduinoCloud.getInternalTime ();
54
54
}
55
55
56
- void updateTimezoneInfo ()
57
- {
58
- ArduinoCloud.updateInternalTimezoneInfo ();
59
- }
60
-
61
56
/* *****************************************************************************
62
57
CTOR/DTOR
63
58
******************************************************************************/
64
59
65
60
ArduinoIoTCloudTCP::ArduinoIoTCloudTCP ()
66
61
: _state{State::ConnectPhy}
62
+ , _tz_offset{0 }
63
+ , _tz_offset_property{nullptr }
64
+ , _tz_dst_until{0 }
65
+ , _tz_dst_until_property{nullptr }
67
66
, _next_connection_attempt_tick{0 }
68
67
, _last_connection_attempt_cnt{0 }
69
68
, _next_device_subscribe_attempt_tick{0 }
@@ -214,9 +213,10 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
214
213
#endif /* OTA_ENABLED */
215
214
p = new CloudWrapperString (_thing_id);
216
215
_thing_id_property = &addPropertyToContainer (_device_property_container, *p, " thing_id" , Permission::ReadWrite, -1 ).writeOnDemand ();
217
-
218
- addPropertyReal (_tz_offset, " tz_offset" , Permission::ReadWrite).onSync (CLOUD_WINS).onUpdate (updateTimezoneInfo);
219
- addPropertyReal (_tz_dst_until, " tz_dst_until" , Permission::ReadWrite).onSync (CLOUD_WINS).onUpdate (updateTimezoneInfo);
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 ();
220
220
221
221
#if OTA_ENABLED
222
222
_ota_cap = OTA::isCapable ();
@@ -584,13 +584,23 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
584
584
_mqtt_data_request_retransmit = false ;
585
585
}
586
586
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
+
587
597
/* Check if any properties need encoding and send them to
588
598
* the cloud if necessary.
589
599
*/
590
600
sendThingPropertiesToCloud ();
591
601
592
602
unsigned long const internal_posix_time = _time_service.getTime ();
593
- if (internal_posix_time < _tz_dst_until) {
603
+ if (internal_posix_time < _tz_dst_until) {
594
604
return State::Connected;
595
605
} else {
596
606
return State::RequestLastValues;
0 commit comments