@@ -60,11 +60,6 @@ unsigned long getTime()
60
60
return ArduinoCloud.getInternalTime ();
61
61
}
62
62
63
- void updateTimezoneInfo ()
64
- {
65
- ArduinoCloud.updateInternalTimezoneInfo ();
66
- }
67
-
68
63
/* *****************************************************************************
69
64
CTOR/DTOR
70
65
******************************************************************************/
@@ -199,8 +194,8 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
199
194
200
195
addPropertyToContainer (_device_property_container, _thing_id, " thing_id" , Permission::Read, -1 );
201
196
202
- addPropertyReal ( _tz_offset, " tz_offset" , Permission::ReadWrite). onSync (CLOUD_WINS). onUpdate (updateTimezoneInfo );
203
- addPropertyReal ( _tz_dst_until, " tz_dst_until" , Permission::ReadWrite). onSync (CLOUD_WINS). onUpdate (updateTimezoneInfo );
197
+ addPropertyToContainer (_thing_property_container, _tz_offset, " tz_offset" , Permission::Read, - 1 );
198
+ addPropertyToContainer (_thing_property_container, _tz_dst_until, " tz_dst_until" , Permission::Read, - 1 );
204
199
205
200
#if OTA_ENABLED
206
201
_ota_cap = OTA::isCapable ();
@@ -591,13 +586,26 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
591
586
592
587
#endif /* OTA_ENABLED */
593
588
589
+ /* Configure Time service with timezone data:
590
+ * _tz_offset [offset + dst]
591
+ * _tz_dst_until [posix timestamp until _tz_offset is valid]
592
+ */
593
+ if (_tz_offset.isDifferentFromCloud () || _tz_dst_until.isDifferentFromCloud ()) {
594
+ _tz_offset.fromCloudToLocal ();
595
+ _tz_dst_until.fromCloudToLocal ();
596
+ _time_service.setTimeZoneData (_tz_offset, _tz_dst_until);
597
+ }
598
+
594
599
/* Check if any properties need encoding and send them to
595
600
* the cloud if necessary.
596
601
*/
597
602
sendThingPropertiesToCloud ();
598
603
604
+ /* Check if stored timezone data needs to be updated and
605
+ * if data is expired issue a LastValue request to the cloud.
606
+ */
599
607
unsigned long const internal_posix_time = _time_service.getTime ();
600
- if (internal_posix_time < _tz_dst_until) {
608
+ if (internal_posix_time < _tz_dst_until) {
601
609
return State::Connected;
602
610
} else {
603
611
return State::RequestLastValues;
@@ -645,7 +653,6 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
645
653
{
646
654
DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s [%d] last values received" , __FUNCTION__, millis ());
647
655
CBORDecoder::decode (_thing_property_container, (uint8_t *)bytes, length, true );
648
- _time_service.setTimeZoneData (_tz_offset, _tz_dst_until);
649
656
execCloudEventCallback (ArduinoIoTCloudEvent::SYNC);
650
657
_last_sync_request_cnt = 0 ;
651
658
_last_sync_request_tick = 0 ;
0 commit comments