Skip to content

Commit e9297c3

Browse files
ilcatoilcato
authored andcommitted
Refactoring sync status
1 parent 9bf4fca commit e9297c3

File tree

1 file changed

+10
-49
lines changed

1 file changed

+10
-49
lines changed

src/ArduinoIoTCloud.h

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,11 @@ enum ArduinoIoTConnectionStatus {
5151
IOT_STATUS_CLOUD_ERROR,
5252
};
5353

54-
#define AUTO_SYNC onAutoSync
55-
template<typename T>
56-
void onAutoSync(ArduinoCloudProperty<T> property) {
57-
Serial.print("Executing the AUTO sync on: ");
58-
Serial.println(property.getPropertyName());
59-
if( property.getLastCloudChangeTimestamp() > property.getLastLocalChangeTimestamp()){
60-
property.setPropertyValue(property.getCloudShadowValue());
61-
if( property.getLastCloudChangeTimestamp() > property.getLastCloudSyncTimestamp()){
62-
property.forceCallbackOnChange();
63-
}
64-
}
65-
}
66-
67-
#define FORCE_CLOUD_SYNC onForceCloudSync
68-
template<typename T>
69-
void onForceCloudSync(ArduinoCloudProperty<T> property) {
70-
Serial.print("Executing the FORCE_CLOUD sync on: ");
71-
Serial.println(property.getPropertyName());
72-
property.setPropertyValue(property.getCloudShadowValue());
73-
if( property.getLastCloudChangeTimestamp() > property.getLastCloudSyncTimestamp()){
74-
property.forceCallbackOnChange();
75-
}
76-
}
77-
78-
#define FORCE_DEVICE_SYNC onForceDeviceSync
79-
template<typename T>
80-
void onForceDeviceSync(ArduinoCloudProperty<T> property) {
81-
Serial.print("Executing the FORCE_DEVICE sync on: ");
82-
Serial.println(property.getPropertyName());
83-
}
54+
enum ArduinoIoTSynchronizationStatus {
55+
SYNC_STATUS_SYNCHRONIZED,
56+
SYNC_STATUS_WAIT_FOR_CLOUD_VALUES,
57+
SYNC_STATUS_VALUES_PROCESSED
58+
};
8459

8560
class ArduinoIoTCloudClass {
8661

@@ -100,15 +75,12 @@ class ArduinoIoTCloudClass {
10075

10176
int connect ();
10277
bool disconnect();
103-
void prova();
10478

10579
void poll() __attribute__((deprecated)); /* Attention: Function is deprecated - use 'update' instead */
10680
void update(void (*callback)(void) = NULL);
10781

10882
// defined for users who want to specify max reconnections reties and timeout between them
10983
void update(int const reconnectionMaxRetries, int const reconnectionTimeoutMs, void (*callback)(void) = NULL);
110-
// get the status of synchronization after getLastValues request
111-
bool getLastValuesSyncStatus();
11284

11385
int connected();
11486
// Clean up existing Mqtt connection, create a new one and initialize it
@@ -126,21 +98,11 @@ class ArduinoIoTCloudClass {
12698

12799

128100
template<typename T, typename N=T>
129-
void addPropertyReal(T & property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, N minDelta = N(0), void(*synFn)(ArduinoCloudProperty<T> property) = FORCE_CLOUD_SYNC) {
101+
void addPropertyReal(T & property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void(*fn)(void) = NULL, void(*synFn)(ArduinoCloudProperty<T> property) = FORCE_CLOUD_SYNC, N minDelta = N(0)) {
130102
Permission permission = Permission::ReadWrite;
131103
if (permission_type == READ ) permission = Permission::Read;
132104
else if(permission_type == WRITE) permission = Permission::Write;
133105
else permission = Permission::ReadWrite;
134-
135-
SyncMode syncMode = PROPERTIES_SYNC_FORCE_CLOUD;
136-
if (synFn == (void(*)(ArduinoCloudProperty<T> property))AUTO_SYNC)
137-
syncMode = PROPERTIES_SYNC_AUTO;
138-
else if (synFn == (void(*)(ArduinoCloudProperty<T> property))FORCE_CLOUD_SYNC)
139-
syncMode = PROPERTIES_SYNC_FORCE_CLOUD;
140-
else if (synFn == (void(*)(ArduinoCloudProperty<T> property))FORCE_DEVICE_SYNC)
141-
syncMode = PROPERTIES_SYNC_FORCE_DEVICE;
142-
else
143-
syncMode = PROPERTIES_SYNC_CUSTOM;
144106

145107
if(seconds == ON_CHANGE) {
146108
Thing.addPropertyReal(property, name, permission).publishOnChange((T)minDelta, DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS).onUpdate(fn).onSync(synFn);
@@ -179,6 +141,10 @@ class ArduinoIoTCloudClass {
179141
ConnectionManager *connection;
180142
static void onMessage(int length);
181143
void handleMessage(int length);
144+
ArduinoIoTSynchronizationStatus syncStatus = SYNC_STATUS_SYNCHRONIZED;
145+
146+
void sendPropertiesToCloud();
147+
182148

183149
String _id,
184150
_thing_id,
@@ -200,11 +166,6 @@ class ArduinoIoTCloudClass {
200166
String _dataTopicIn;
201167
String _otaTopic;
202168
Client *_net;
203-
204-
// Used to synchronize properties
205-
bool _firstReconnectionUpdate;
206-
bool _propertiesSynchronized;
207-
void (*_syncCallback)(void);
208169
};
209170

210171
extern ArduinoIoTCloudClass ArduinoCloud;

0 commit comments

Comments
 (0)