Skip to content

Commit 6de5655

Browse files
committed
Remove public functions to handle thing_id discovery protocol
1 parent 1917639 commit 6de5655

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

src/ArduinoIoTCloud.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,10 @@ class ArduinoIoTCloudClass
9292
bool setTimestamp(String const & prop_name, unsigned long const timestamp);
9393

9494
inline void setThingId (String const thing_id) { _thing_id = thing_id; };
95-
inline String & getThingId () { return _thing_id; };
95+
inline String & getThingId () { return _thing_id.getValue(); };
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(); }
@@ -159,7 +153,7 @@ class ArduinoIoTCloudClass
159153
TimeServiceClass & _time_service;
160154
int _tz_offset;
161155
unsigned int _tz_dst_until;
162-
String _thing_id;
156+
CloudString _thing_id;
163157
String _lib_version;
164158

165159
void execCloudEventCallback(ArduinoIoTCloudEvent const event);

src/ArduinoIoTCloudTCP.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ void updateTimezoneInfo()
6565
ArduinoCloud.updateInternalTimezoneInfo();
6666
}
6767

68-
void setThingIdOutdated()
69-
{
70-
ArduinoCloud.setThingIdOutdatedFlag();
71-
}
72-
7368
/******************************************************************************
7469
CTOR/DTOR
7570
******************************************************************************/
@@ -201,8 +196,8 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
201196
p = new CloudWrapperBool(_ota_req);
202197
addPropertyToContainer(_device_property_container, *p, "OTA_REQ", Permission::ReadWrite, -1);
203198
#endif /* OTA_ENABLED */
204-
p = new CloudWrapperString(_thing_id);
205-
addPropertyToContainer(_device_property_container, *p, "thing_id", Permission::ReadWrite, -1).onUpdate(setThingIdOutdated);
199+
200+
addPropertyToContainer(_device_property_container, _thing_id, "thing_id", Permission::Read, -1);
206201

207202
addPropertyReal(_tz_offset, "tz_offset", Permission::ReadWrite).onSync(CLOUD_WINS).onUpdate(updateTimezoneInfo);
208203
addPropertyReal(_tz_dst_until, "tz_dst_until", Permission::ReadWrite).onSync(CLOUD_WINS).onUpdate(updateTimezoneInfo);
@@ -386,7 +381,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
386381
return State::Disconnect;
387382
}
388383

389-
if (getThingIdOutdatedFlag())
384+
if(_thing_id.isDifferentFromCloud())
390385
{
391386
return State::CheckDeviceConfig;
392387
}
@@ -422,7 +417,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
422417

423418
updateThingTopics();
424419

425-
if (deviceNotAttached())
420+
if (_thing_id.getValue().length() == 0)
426421
{
427422
/* Configuration received but device not attached. Wait: 40s */
428423
unsigned long attach_retry_delay = (1 << _last_device_attach_cnt) * AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms;
@@ -445,7 +440,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeThingTopics()
445440
return State::Disconnect;
446441
}
447442

448-
if (getThingIdOutdatedFlag())
443+
if (_thing_id.isDifferentFromCloud())
449444
{
450445
return State::CheckDeviceConfig;
451446
}
@@ -501,7 +496,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()
501496
return State::Disconnect;
502497
}
503498

504-
if (getThingIdOutdatedFlag())
499+
if (_thing_id.isDifferentFromCloud())
505500
{
506501
return State::CheckDeviceConfig;
507502
}
@@ -544,7 +539,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
544539
/* We are connected so let's to our stuff here. */
545540
else
546541
{
547-
if (getThingIdOutdatedFlag())
542+
if (_thing_id.isDifferentFromCloud())
548543
{
549544
return State::CheckDeviceConfig;
550545
}
@@ -738,12 +733,12 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l
738733

739734
void ArduinoIoTCloudTCP::updateThingTopics()
740735
{
736+
_thing_id.fromCloudToLocal();
737+
741738
_shadowTopicOut = getTopic_shadowout();
742739
_shadowTopicIn = getTopic_shadowin();
743740
_dataTopicOut = getTopic_dataout();
744741
_dataTopicIn = getTopic_datain();
745-
746-
clrThingIdOutdatedFlag();
747742
}
748743

749744
/******************************************************************************

0 commit comments

Comments
 (0)