Skip to content

Commit

Permalink
Remove public functions to handle thing_id discovery protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Mar 28, 2024
1 parent 2c7ba81 commit af472ca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/ArduinoIoTCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ArduinoIoTCloudClass::ArduinoIoTCloudClass()
, _tz_offset{0}
, _tz_dst_until{0}
, _thing_id{""}
, _thing_id_property{nullptr}
, _lib_version{AIOT_CONFIG_LIB_VERSION}
, _device_id{""}
, _cloud_event_callback{nullptr}
Expand Down
7 changes: 1 addition & 6 deletions src/ArduinoIoTCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ class ArduinoIoTCloudClass
inline void setDeviceId(String const device_id) { _device_id = device_id; };
inline String & getDeviceId() { return _device_id; };

inline void setThingIdOutdatedFlag() { _thing_id_outdated = true ; }
inline void clrThingIdOutdatedFlag() { _thing_id_outdated = false ; }
inline bool getThingIdOutdatedFlag() { return _thing_id_outdated; }

inline bool deviceNotAttached() { return _thing_id == ""; }

inline ConnectionHandler * getConnection() { return _connection; }

inline unsigned long getInternalTime() { return _time_service.getTime(); }
Expand Down Expand Up @@ -160,6 +154,7 @@ class ArduinoIoTCloudClass
int _tz_offset;
unsigned int _tz_dst_until;
String _thing_id;
Property * _thing_id_property;
String _lib_version;

void execCloudEventCallback(ArduinoIoTCloudEvent const event);
Expand Down
21 changes: 8 additions & 13 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ void updateTimezoneInfo()
ArduinoCloud.updateInternalTimezoneInfo();
}

void setThingIdOutdated()
{
ArduinoCloud.setThingIdOutdatedFlag();
}

/******************************************************************************
CTOR/DTOR
******************************************************************************/
Expand Down Expand Up @@ -218,7 +213,7 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
addPropertyToContainer(_device_property_container, *p, "OTA_REQ", Permission::ReadWrite, -1);
#endif /* OTA_ENABLED */
p = new CloudWrapperString(_thing_id);
addPropertyToContainer(_device_property_container, *p, "thing_id", Permission::ReadWrite, -1).onUpdate(setThingIdOutdated);
_thing_id_property = &addPropertyToContainer(_device_property_container, *p, "thing_id", Permission::ReadWrite, -1).writeOnDemand();

addPropertyReal(_tz_offset, "tz_offset", Permission::ReadWrite).onSync(CLOUD_WINS).onUpdate(updateTimezoneInfo);
addPropertyReal(_tz_dst_until, "tz_dst_until", Permission::ReadWrite).onSync(CLOUD_WINS).onUpdate(updateTimezoneInfo);
Expand Down Expand Up @@ -409,7 +404,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
return State::Disconnect;
}

if (getThingIdOutdatedFlag())
if (_thing_id_property->isDifferentFromCloud())
{
return State::CheckDeviceConfig;
}
Expand Down Expand Up @@ -445,7 +440,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()

updateThingTopics();

if (deviceNotAttached())
if (_thing_id.length() == 0)
{
/* Configuration received but device not attached. Wait: 40s */
unsigned long attach_retry_delay = (1 << _last_device_attach_cnt) * AIOT_CONFIG_DEVICE_TOPIC_SUBSCRIBE_RETRY_DELAY_ms;
Expand All @@ -468,7 +463,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeThingTopics()
return State::Disconnect;
}

if (getThingIdOutdatedFlag())
if (_thing_id_property->isDifferentFromCloud())
{
return State::CheckDeviceConfig;
}
Expand Down Expand Up @@ -524,7 +519,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()
return State::Disconnect;
}

if (getThingIdOutdatedFlag())
if (_thing_id_property->isDifferentFromCloud())
{
return State::CheckDeviceConfig;
}
Expand Down Expand Up @@ -567,7 +562,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
/* We are connected so let's to our stuff here. */
else
{
if (getThingIdOutdatedFlag())
if (_thing_id_property->isDifferentFromCloud())
{
return State::CheckDeviceConfig;
}
Expand Down Expand Up @@ -762,12 +757,12 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l

void ArduinoIoTCloudTCP::updateThingTopics()
{
_thing_id_property->fromCloudToLocal();

_shadowTopicOut = getTopic_shadowout();
_shadowTopicIn = getTopic_shadowin();
_dataTopicOut = getTopic_dataout();
_dataTopicIn = getTopic_datain();

clrThingIdOutdatedFlag();
}

/******************************************************************************
Expand Down

0 comments on commit af472ca

Please sign in to comment.