Skip to content

Commit c15c145

Browse files
committed
Remove public functions to handle timezone changes
1 parent 6de5655 commit c15c145

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/ArduinoIoTCloud.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ class ArduinoIoTCloudClass
151151
PropertyContainer _thing_property_container;
152152
unsigned int _last_checked_property_index;
153153
TimeServiceClass & _time_service;
154-
int _tz_offset;
155-
unsigned int _tz_dst_until;
154+
CloudInt _tz_offset;
155+
CloudUnsignedInt _tz_dst_until;
156156
CloudString _thing_id;
157157
String _lib_version;
158158

src/ArduinoIoTCloudTCP.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ unsigned long getTime()
6060
return ArduinoCloud.getInternalTime();
6161
}
6262

63-
void updateTimezoneInfo()
64-
{
65-
ArduinoCloud.updateInternalTimezoneInfo();
66-
}
67-
6863
/******************************************************************************
6964
CTOR/DTOR
7065
******************************************************************************/
@@ -199,8 +194,8 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
199194

200195
addPropertyToContainer(_device_property_container, _thing_id, "thing_id", Permission::Read, -1);
201196

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);
204199

205200
#if OTA_ENABLED
206201
_ota_cap = OTA::isCapable();
@@ -591,13 +586,26 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
591586

592587
#endif /* OTA_ENABLED */
593588

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+
594599
/* Check if any properties need encoding and send them to
595600
* the cloud if necessary.
596601
*/
597602
sendThingPropertiesToCloud();
598603

604+
/* Check if stored timezone data needs to be updated and
605+
* if data is expired issue a LastValue request to the cloud.
606+
*/
599607
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) {
601609
return State::Connected;
602610
} else {
603611
return State::RequestLastValues;
@@ -645,7 +653,6 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
645653
{
646654
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] last values received", __FUNCTION__, millis());
647655
CBORDecoder::decode(_thing_property_container, (uint8_t*)bytes, length, true);
648-
_time_service.setTimeZoneData(_tz_offset, _tz_dst_until);
649656
execCloudEventCallback(ArduinoIoTCloudEvent::SYNC);
650657
_last_sync_request_cnt = 0;
651658
_last_sync_request_tick = 0;

0 commit comments

Comments
 (0)