@@ -53,22 +53,16 @@ unsigned long getTime()
53
53
return ArduinoCloud.getInternalTime ();
54
54
}
55
55
56
- void updateTimezoneInfo ()
57
- {
58
- ArduinoCloud.updateInternalTimezoneInfo ();
59
- }
60
-
61
- void setThingIdOutdated ()
62
- {
63
- ArduinoCloud.setThingIdOutdatedFlag ();
64
- }
65
-
66
56
/* *****************************************************************************
67
57
CTOR/DTOR
68
58
******************************************************************************/
69
59
70
60
ArduinoIoTCloudTCP::ArduinoIoTCloudTCP ()
71
61
: _state{State::ConnectPhy}
62
+ , _tz_offset{0 }
63
+ , _tz_offset_property{nullptr }
64
+ , _tz_dst_until{0 }
65
+ , _tz_dst_until_property{nullptr }
72
66
, _next_connection_attempt_tick{0 }
73
67
, _last_connection_attempt_cnt{0 }
74
68
, _next_device_subscribe_attempt_tick{0 }
@@ -218,10 +212,11 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
218
212
addPropertyToContainer (_device_property_container, *p, " OTA_REQ" , Permission::ReadWrite, -1 );
219
213
#endif /* OTA_ENABLED */
220
214
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 ();
225
220
226
221
#if OTA_ENABLED
227
222
_ota_cap = OTA::isCapable ();
@@ -409,7 +404,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
409
404
return State::Disconnect;
410
405
}
411
406
412
- if (getThingIdOutdatedFlag ())
407
+ if (_thing_id_property-> isDifferentFromCloud ())
413
408
{
414
409
return State::CheckDeviceConfig;
415
410
}
@@ -445,7 +440,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
445
440
446
441
updateThingTopics ();
447
442
448
- if (deviceNotAttached () )
443
+ if (_thing_id. length () == 0 )
449
444
{
450
445
/* Configuration received but device not attached. Wait: 40s */
451
446
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()
468
463
return State::Disconnect;
469
464
}
470
465
471
- if (getThingIdOutdatedFlag ())
466
+ if (_thing_id_property-> isDifferentFromCloud ())
472
467
{
473
468
return State::CheckDeviceConfig;
474
469
}
@@ -524,7 +519,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()
524
519
return State::Disconnect;
525
520
}
526
521
527
- if (getThingIdOutdatedFlag ())
522
+ if (_thing_id_property-> isDifferentFromCloud ())
528
523
{
529
524
return State::CheckDeviceConfig;
530
525
}
@@ -567,7 +562,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
567
562
/* We are connected so let's to our stuff here. */
568
563
else
569
564
{
570
- if (getThingIdOutdatedFlag ())
565
+ if (_thing_id_property-> isDifferentFromCloud ())
571
566
{
572
567
return State::CheckDeviceConfig;
573
568
}
@@ -589,13 +584,23 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
589
584
_mqtt_data_request_retransmit = false ;
590
585
}
591
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
+
592
597
/* Check if any properties need encoding and send them to
593
598
* the cloud if necessary.
594
599
*/
595
600
sendThingPropertiesToCloud ();
596
601
597
602
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) {
599
604
return State::Connected;
600
605
} else {
601
606
return State::RequestLastValues;
@@ -762,12 +767,12 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l
762
767
763
768
void ArduinoIoTCloudTCP::updateThingTopics ()
764
769
{
770
+ _thing_id_property->fromCloudToLocal ();
771
+
765
772
_shadowTopicOut = getTopic_shadowout ();
766
773
_shadowTopicIn = getTopic_shadowin ();
767
774
_dataTopicOut = getTopic_dataout ();
768
775
_dataTopicIn = getTopic_datain ();
769
-
770
- clrThingIdOutdatedFlag ();
771
776
}
772
777
773
778
/* *****************************************************************************
0 commit comments