Skip to content

Commit af472ca

Browse files
committed
Remove public functions to handle thing_id discovery protocol
1 parent 2c7ba81 commit af472ca

File tree

3 files changed

+10
-19
lines changed

3 files changed

+10
-19
lines changed

src/ArduinoIoTCloud.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ArduinoIoTCloudClass::ArduinoIoTCloudClass()
3232
, _tz_offset{0}
3333
, _tz_dst_until{0}
3434
, _thing_id{""}
35+
, _thing_id_property{nullptr}
3536
, _lib_version{AIOT_CONFIG_LIB_VERSION}
3637
, _device_id{""}
3738
, _cloud_event_callback{nullptr}

src/ArduinoIoTCloud.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ class ArduinoIoTCloudClass
9696
inline void setDeviceId(String const device_id) { _device_id = device_id; };
9797
inline String & getDeviceId() { return _device_id; };
9898

99-
inline void setThingIdOutdatedFlag() { _thing_id_outdated = true ; }
100-
inline void clrThingIdOutdatedFlag() { _thing_id_outdated = false ; }
101-
inline bool getThingIdOutdatedFlag() { return _thing_id_outdated; }
102-
103-
inline bool deviceNotAttached() { return _thing_id == ""; }
104-
10599
inline ConnectionHandler * getConnection() { return _connection; }
106100

107101
inline unsigned long getInternalTime() { return _time_service.getTime(); }
@@ -160,6 +154,7 @@ class ArduinoIoTCloudClass
160154
int _tz_offset;
161155
unsigned int _tz_dst_until;
162156
String _thing_id;
157+
Property * _thing_id_property;
163158
String _lib_version;
164159

165160
void execCloudEventCallback(ArduinoIoTCloudEvent const event);

src/ArduinoIoTCloudTCP.cpp

+8-13
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ void updateTimezoneInfo()
5858
ArduinoCloud.updateInternalTimezoneInfo();
5959
}
6060

61-
void setThingIdOutdated()
62-
{
63-
ArduinoCloud.setThingIdOutdatedFlag();
64-
}
65-
6661
/******************************************************************************
6762
CTOR/DTOR
6863
******************************************************************************/
@@ -218,7 +213,7 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
218213
addPropertyToContainer(_device_property_container, *p, "OTA_REQ", Permission::ReadWrite, -1);
219214
#endif /* OTA_ENABLED */
220215
p = new CloudWrapperString(_thing_id);
221-
addPropertyToContainer(_device_property_container, *p, "thing_id", Permission::ReadWrite, -1).onUpdate(setThingIdOutdated);
216+
_thing_id_property = &addPropertyToContainer(_device_property_container, *p, "thing_id", Permission::ReadWrite, -1).writeOnDemand();
222217

223218
addPropertyReal(_tz_offset, "tz_offset", Permission::ReadWrite).onSync(CLOUD_WINS).onUpdate(updateTimezoneInfo);
224219
addPropertyReal(_tz_dst_until, "tz_dst_until", Permission::ReadWrite).onSync(CLOUD_WINS).onUpdate(updateTimezoneInfo);
@@ -409,7 +404,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
409404
return State::Disconnect;
410405
}
411406

412-
if (getThingIdOutdatedFlag())
407+
if (_thing_id_property->isDifferentFromCloud())
413408
{
414409
return State::CheckDeviceConfig;
415410
}
@@ -445,7 +440,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
445440

446441
updateThingTopics();
447442

448-
if (deviceNotAttached())
443+
if (_thing_id.length() == 0)
449444
{
450445
/* Configuration received but device not attached. Wait: 40s */
451446
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()
468463
return State::Disconnect;
469464
}
470465

471-
if (getThingIdOutdatedFlag())
466+
if (_thing_id_property->isDifferentFromCloud())
472467
{
473468
return State::CheckDeviceConfig;
474469
}
@@ -524,7 +519,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()
524519
return State::Disconnect;
525520
}
526521

527-
if (getThingIdOutdatedFlag())
522+
if (_thing_id_property->isDifferentFromCloud())
528523
{
529524
return State::CheckDeviceConfig;
530525
}
@@ -567,7 +562,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
567562
/* We are connected so let's to our stuff here. */
568563
else
569564
{
570-
if (getThingIdOutdatedFlag())
565+
if (_thing_id_property->isDifferentFromCloud())
571566
{
572567
return State::CheckDeviceConfig;
573568
}
@@ -762,12 +757,12 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l
762757

763758
void ArduinoIoTCloudTCP::updateThingTopics()
764759
{
760+
_thing_id_property->fromCloudToLocal();
761+
765762
_shadowTopicOut = getTopic_shadowout();
766763
_shadowTopicIn = getTopic_shadowin();
767764
_dataTopicOut = getTopic_dataout();
768765
_dataTopicIn = getTopic_datain();
769-
770-
clrThingIdOutdatedFlag();
771766
}
772767

773768
/******************************************************************************

0 commit comments

Comments
 (0)