Skip to content

Commit 896249b

Browse files
committed
Remove public functions to handle timezone changes
1 parent af472ca commit 896249b

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

src/ArduinoIoTCloud.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ ArduinoIoTCloudClass::ArduinoIoTCloudClass()
2929
: _connection{nullptr}
3030
, _last_checked_property_index{0}
3131
, _time_service(TimeService)
32-
, _tz_offset{0}
33-
, _tz_dst_until{0}
3432
, _thing_id{""}
3533
, _thing_id_property{nullptr}
3634
, _lib_version{AIOT_CONFIG_LIB_VERSION}

src/ArduinoIoTCloud.h

-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ class ArduinoIoTCloudClass
100100

101101
inline unsigned long getInternalTime() { return _time_service.getTime(); }
102102
inline unsigned long getLocalTime() { return _time_service.getLocalTime(); }
103-
inline void updateInternalTimezoneInfo() { _time_service.setTimeZoneData(_tz_offset, _tz_dst_until); }
104103

105104
void addCallback(ArduinoIoTCloudEvent const event, OnCloudEventCallback callback);
106105

@@ -151,8 +150,6 @@ class ArduinoIoTCloudClass
151150
PropertyContainer _thing_property_container;
152151
unsigned int _last_checked_property_index;
153152
TimeServiceClass & _time_service;
154-
int _tz_offset;
155-
unsigned int _tz_dst_until;
156153
String _thing_id;
157154
Property * _thing_id_property;
158155
String _lib_version;

src/ArduinoIoTCloudTCP.cpp

+19-9
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,16 @@ unsigned long getTime()
5353
return ArduinoCloud.getInternalTime();
5454
}
5555

56-
void updateTimezoneInfo()
57-
{
58-
ArduinoCloud.updateInternalTimezoneInfo();
59-
}
60-
6156
/******************************************************************************
6257
CTOR/DTOR
6358
******************************************************************************/
6459

6560
ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
6661
: _state{State::ConnectPhy}
62+
, _tz_offset{0}
63+
, _tz_offset_property{nullptr}
64+
, _tz_dst_until{0}
65+
, _tz_dst_until_property{nullptr}
6766
, _next_connection_attempt_tick{0}
6867
, _last_connection_attempt_cnt{0}
6968
, _next_device_subscribe_attempt_tick{0}
@@ -214,9 +213,10 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
214213
#endif /* OTA_ENABLED */
215214
p = new CloudWrapperString(_thing_id);
216215
_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();
220220

221221
#if OTA_ENABLED
222222
_ota_cap = OTA::isCapable();
@@ -584,13 +584,23 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
584584
_mqtt_data_request_retransmit = false;
585585
}
586586

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+
587597
/* Check if any properties need encoding and send them to
588598
* the cloud if necessary.
589599
*/
590600
sendThingPropertiesToCloud();
591601

592602
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) {
594604
return State::Connected;
595605
} else {
596606
return State::RequestLastValues;

src/ArduinoIoTCloudTCP.h

+5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ class ArduinoIoTCloudTCP: public ArduinoIoTCloudClass
123123

124124
State _state;
125125

126+
int _tz_offset;
127+
Property * _tz_offset_property;
128+
unsigned int _tz_dst_until;
129+
Property * _tz_dst_until_property;
130+
126131
unsigned long _next_connection_attempt_tick;
127132
unsigned int _last_connection_attempt_cnt;
128133
unsigned long _next_device_subscribe_attempt_tick;

0 commit comments

Comments
 (0)