Skip to content

Remove internal global functions and unwanted public functions #387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/ArduinoIoTCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,10 @@ class ArduinoIoTCloudClass
bool setTimestamp(String const & prop_name, unsigned long const timestamp);

inline void setThingId (String const thing_id) { _thing_id = thing_id; };
inline String & getThingId () { return _thing_id; };
inline String & getThingId () { return _thing_id.getValue(); };
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 @@ -157,9 +151,9 @@ class ArduinoIoTCloudClass
PropertyContainer _thing_property_container;
unsigned int _last_checked_property_index;
TimeServiceClass & _time_service;
int _tz_offset;
unsigned int _tz_dst_until;
String _thing_id;
CloudInt _tz_offset;
CloudUnsignedInt _tz_dst_until;
CloudString _thing_id;
String _lib_version;

void execCloudEventCallback(ArduinoIoTCloudEvent const event);
Expand Down
48 changes: 25 additions & 23 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ unsigned long getTime()
return ArduinoCloud.getInternalTime();
}

void updateTimezoneInfo()
{
ArduinoCloud.updateInternalTimezoneInfo();
}

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

/******************************************************************************
CTOR/DTOR
******************************************************************************/
Expand Down Expand Up @@ -201,11 +191,11 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
p = new CloudWrapperBool(_ota_req);
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);

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);
addPropertyToContainer(_device_property_container, _thing_id, "thing_id", Permission::Read, -1);

addPropertyToContainer(_thing_property_container, _tz_offset, "tz_offset", Permission::Read, -1);
addPropertyToContainer(_thing_property_container, _tz_dst_until, "tz_dst_until", Permission::Read, -1);

#if OTA_ENABLED
_ota_cap = OTA::isCapable();
Expand Down Expand Up @@ -386,7 +376,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
return State::Disconnect;
}

if (getThingIdOutdatedFlag())
if(_thing_id.isDifferentFromCloud())
{
return State::CheckDeviceConfig;
}
Expand Down Expand Up @@ -422,7 +412,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()

updateThingTopics();

if (deviceNotAttached())
if (_thing_id.getValue().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 @@ -445,7 +435,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_SubscribeThingTopics()
return State::Disconnect;
}

if (getThingIdOutdatedFlag())
if (_thing_id.isDifferentFromCloud())
{
return State::CheckDeviceConfig;
}
Expand Down Expand Up @@ -501,7 +491,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()
return State::Disconnect;
}

if (getThingIdOutdatedFlag())
if (_thing_id.isDifferentFromCloud())
{
return State::CheckDeviceConfig;
}
Expand Down Expand Up @@ -544,7 +534,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()
/* We are connected so let's to our stuff here. */
else
{
if (getThingIdOutdatedFlag())
if (_thing_id.isDifferentFromCloud())
{
return State::CheckDeviceConfig;
}
Expand Down Expand Up @@ -596,13 +586,26 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_Connected()

#endif /* OTA_ENABLED */

/* Configure Time service with timezone data:
* _tz_offset [offset + dst]
* _tz_dst_until [posix timestamp until _tz_offset is valid]
*/
if (_tz_offset.isDifferentFromCloud() || _tz_dst_until.isDifferentFromCloud()) {
_tz_offset.fromCloudToLocal();
_tz_dst_until.fromCloudToLocal();
_time_service.setTimeZoneData(_tz_offset, _tz_dst_until);
}

/* Check if any properties need encoding and send them to
* the cloud if necessary.
*/
sendThingPropertiesToCloud();

/* Check if stored timezone data needs to be updated and
* if data is expired issue a LastValue request to the cloud.
*/
unsigned long const internal_posix_time = _time_service.getTime();
if(internal_posix_time < _tz_dst_until) {
if (internal_posix_time < _tz_dst_until) {
return State::Connected;
} else {
return State::RequestLastValues;
Expand Down Expand Up @@ -650,7 +653,6 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
{
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] last values received", __FUNCTION__, millis());
CBORDecoder::decode(_thing_property_container, (uint8_t*)bytes, length, true);
_time_service.setTimeZoneData(_tz_offset, _tz_dst_until);
execCloudEventCallback(ArduinoIoTCloudEvent::SYNC);
_last_sync_request_cnt = 0;
_last_sync_request_tick = 0;
Expand Down Expand Up @@ -738,12 +740,12 @@ int ArduinoIoTCloudTCP::write(String const topic, byte const data[], int const l

void ArduinoIoTCloudTCP::updateThingTopics()
{
_thing_id.fromCloudToLocal();

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

clrThingIdOutdatedFlag();
}

/******************************************************************************
Expand Down
20 changes: 13 additions & 7 deletions src/property/PropertyContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,22 @@ void updateProperty(PropertyContainer & prop_cont, String propertyName, unsigned
{
Property * property = getProperty(prop_cont, propertyName);

if (property && property->isWriteableByCloud())
if (property )
{
/* Update _cloud_value */
property->setLastCloudChangeTimestamp(cloudChangeEventTime);
property->setAttributesFromCloud(map_data_list);
if (is_sync_message) {
property->execCallbackOnSync();
} else {
property->fromCloudToLocal();
property->execCallbackOnChange();
property->provideEcho();

/* Update _value */
if (property->isWriteableByCloud())
{
if (is_sync_message) {
property->execCallbackOnSync();
} else {
property->fromCloudToLocal();
property->execCallbackOnChange();
property->provideEcho();
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/property/types/CloudString.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class CloudString : public Property {
virtual bool isDifferentFromCloud() {
return _value != _cloud_value;
}
virtual String & getValue() {
return _value;
}
virtual void fromCloudToLocal() {
_value = _cloud_value;
}
Expand Down