25
25
#include < ArduinoCloudThing.h>
26
26
27
27
#include < Arduino_DebugUtils.h>
28
- #include " types/CloudWrapperBool.h"
28
+ #include " types/CloudWrapperBool.h"
29
29
#include " types/CloudWrapperFloat.h"
30
30
#include " types/CloudWrapperInt.h"
31
31
#include " types/CloudWrapperString.h"
@@ -69,8 +69,8 @@ typedef void (*OnCloudEventCallback)(void * /* arg */);
69
69
class ArduinoIoTCloudClass {
70
70
71
71
public:
72
- static const int TIMEOUT_FOR_LASTVALUES_SYNC = 10000 ;
73
- /* Public Virtual Functions*/
72
+ static const int TIMEOUT_FOR_LASTVALUES_SYNC = 10000 ;
73
+ /* Public Virtual Functions*/
74
74
virtual int connect () = 0;
75
75
virtual bool disconnect () = 0;
76
76
@@ -79,32 +79,32 @@ class ArduinoIoTCloudClass {
79
79
virtual void update (CallbackFunc onSyncCompleteCallback) __attribute__((deprecated)) = 0; /* Attention: Function is deprecated - use 'addCallback(ArduinoIoTCloudConnectionEvent::SYNC, &onSync)' for adding a onSyncCallback instead */
80
80
81
81
virtual int connected () = 0;
82
-
83
- virtual void connectionCheck () = 0;
84
82
85
- virtual void printDebugInfo () = 0;
83
+ virtual void connectionCheck () = 0;
84
+
85
+ virtual void printDebugInfo () = 0;
86
86
87
87
inline void setThingId (String const thing_id) {
88
88
_thing_id = thing_id;
89
89
};
90
-
90
+
91
91
inline String getThingId () const {
92
92
return _thing_id;
93
93
};
94
94
95
- inline String getDeviceId () const {
96
- return _device_id;
97
- };
95
+ inline String getDeviceId () const {
96
+ return _device_id;
97
+ };
98
98
99
- #define addProperty ( v, ...) addPropertyReal(v, #v, __VA_ARGS__)
99
+ #define addProperty ( v, ...) addPropertyReal(v, #v, __VA_ARGS__)
100
100
101
101
static unsigned long const DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS = 500 ; /* Data rate throttled to 2 Hz */
102
102
103
- void addPropertyReal (ArduinoCloudProperty & property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
104
- addPropertyReal ( property, name, -1 , permission_type, seconds, fn, minDelta, synFn);
105
- }
103
+ void addPropertyReal (ArduinoCloudProperty & property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
104
+ addPropertyReal (property, name, -1 , permission_type, seconds, fn, minDelta, synFn);
105
+ }
106
106
107
- void addPropertyReal ( ArduinoCloudProperty& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty& property) = CLOUD_WINS ) {
107
+ void addPropertyReal (ArduinoCloudProperty& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty& property) = CLOUD_WINS) {
108
108
Permission permission = Permission::ReadWrite;
109
109
if (permission_type == READ) {
110
110
permission = Permission::Read;
@@ -121,139 +121,139 @@ class ArduinoIoTCloudClass {
121
121
}
122
122
}
123
123
124
- void addPropertyReal (bool & property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
125
- addPropertyReal ( property, name, -1 , permission_type, seconds, fn, minDelta, synFn);
126
- }
124
+ void addPropertyReal (bool & property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
125
+ addPropertyReal (property, name, -1 , permission_type, seconds, fn, minDelta, synFn);
126
+ }
127
127
128
- void addPropertyReal ( bool & property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
128
+ void addPropertyReal (bool & property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
129
129
ArduinoCloudProperty *p = new CloudWrapperBool (property);
130
130
addPropertyReal (*p, name, tag, permission_type, seconds, fn, minDelta, synFn);
131
131
}
132
- ArduinoCloudProperty& addPropertyReal (bool & property, String name, Permission const permission) {
133
- return addPropertyReal (property, name, -1 , permission);
134
- }
132
+ ArduinoCloudProperty& addPropertyReal (bool & property, String name, Permission const permission) {
133
+ return addPropertyReal (property, name, -1 , permission);
134
+ }
135
135
ArduinoCloudProperty& addPropertyReal (bool & property, String name, int tag, Permission const permission) {
136
136
ArduinoCloudProperty *p = new CloudWrapperBool (property);
137
137
return Thing.addPropertyReal (*p, name, permission, tag);
138
138
}
139
139
140
- void addPropertyReal (float & property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
141
- addPropertyReal (property, name, -1 , permission_type, seconds, fn, minDelta, synFn);
142
- }
140
+ void addPropertyReal (float & property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
141
+ addPropertyReal (property, name, -1 , permission_type, seconds, fn, minDelta, synFn);
142
+ }
143
143
144
- void addPropertyReal ( float & property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
144
+ void addPropertyReal (float & property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
145
145
ArduinoCloudProperty *p = new CloudWrapperFloat (property);
146
146
addPropertyReal (*p, name, tag, permission_type, seconds, fn, minDelta, synFn);
147
147
}
148
148
149
- ArduinoCloudProperty& addPropertyReal (float & property, String name, Permission const permission) {
150
- return addPropertyReal ( property, name, -1 , permission);
151
- }
149
+ ArduinoCloudProperty& addPropertyReal (float & property, String name, Permission const permission) {
150
+ return addPropertyReal (property, name, -1 , permission);
151
+ }
152
152
153
- ArduinoCloudProperty& addPropertyReal ( float & property, String name, int tag, Permission const permission ) {
153
+ ArduinoCloudProperty& addPropertyReal (float & property, String name, int tag, Permission const permission) {
154
154
ArduinoCloudProperty *p = new CloudWrapperFloat (property);
155
155
return Thing.addPropertyReal (*p, name, permission, tag);
156
156
}
157
157
158
- void addPropertyReal (int & property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
159
- addPropertyReal (property, name, -1 , permission_type, seconds,fn,minDelta,synFn);
160
- }
158
+ void addPropertyReal (int & property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
159
+ addPropertyReal (property, name, -1 , permission_type, seconds, fn, minDelta, synFn);
160
+ }
161
161
162
- void addPropertyReal ( int & property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
162
+ void addPropertyReal (int & property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
163
163
ArduinoCloudProperty *p = new CloudWrapperInt (property);
164
164
addPropertyReal (*p, name, tag, permission_type, seconds, fn, minDelta, synFn);
165
165
}
166
166
167
- ArduinoCloudProperty& addPropertyReal (int & property, String name, Permission const permission) {
168
- return addPropertyReal (property, name, -1 , permission);
169
- }
167
+ ArduinoCloudProperty& addPropertyReal (int & property, String name, Permission const permission) {
168
+ return addPropertyReal (property, name, -1 , permission);
169
+ }
170
170
171
- ArduinoCloudProperty& addPropertyReal ( int & property, String name, int tag, Permission const permission) {
171
+ ArduinoCloudProperty& addPropertyReal (int & property, String name, int tag, Permission const permission) {
172
172
ArduinoCloudProperty *p = new CloudWrapperInt (property);
173
- return Thing.addPropertyReal (*p, name, permission, tag);
173
+ return Thing.addPropertyReal (*p, name, permission, tag);
174
174
}
175
175
176
- void addPropertyReal (String& property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
177
- addPropertyReal ( property, name, -1 , permission_type, seconds, fn, minDelta, synFn);
178
- }
176
+ void addPropertyReal (String& property, String name, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
177
+ addPropertyReal (property, name, -1 , permission_type, seconds, fn, minDelta, synFn);
178
+ }
179
179
180
- void addPropertyReal ( String& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
180
+ void addPropertyReal (String& property, String name, int tag, permissionType permission_type = READWRITE, long seconds = ON_CHANGE, void (*fn)(void ) = NULL, float minDelta = 0.0f, void(*synFn)(ArduinoCloudProperty & property) = CLOUD_WINS) {
181
181
ArduinoCloudProperty *p = new CloudWrapperString (property);
182
182
addPropertyReal (*p, name, tag, permission_type, seconds, fn, minDelta, synFn);
183
183
}
184
184
185
- ArduinoCloudProperty& addPropertyReal (String& property, String name, Permission const permission) {
186
- return addPropertyReal (property, name, -1 , permission);
187
- }
185
+ ArduinoCloudProperty& addPropertyReal (String& property, String name, Permission const permission) {
186
+ return addPropertyReal (property, name, -1 , permission);
187
+ }
188
188
189
189
ArduinoCloudProperty& addPropertyReal (String& property, String name, int tag, Permission const permission) {
190
190
ArduinoCloudProperty *p = new CloudWrapperString (property);
191
191
return Thing.addPropertyReal (*p, name, permission, tag);
192
192
}
193
193
194
194
void addCallback (ArduinoIoTCloudEvent const event, OnCloudEventCallback callback) {
195
- switch (event) {
196
- case ArduinoIoTCloudEvent::SYNC: _on_sync_event_callback = callback; break ;
197
- case ArduinoIoTCloudEvent::CONNECT: _on_connect_event_callback = callback; break ;
198
- case ArduinoIoTCloudEvent::DISCONNECT: _on_disconnect_event_callback = callback; break ;
199
- }
200
- };
195
+ switch (event) {
196
+ case ArduinoIoTCloudEvent::SYNC: _on_sync_event_callback = callback; break ;
197
+ case ArduinoIoTCloudEvent::CONNECT: _on_connect_event_callback = callback; break ;
198
+ case ArduinoIoTCloudEvent::DISCONNECT: _on_disconnect_event_callback = callback; break ;
199
+ }
200
+ };
201
201
202
202
protected:
203
-
203
+
204
204
virtual int writeStdout (const byte data[], int length) = 0;
205
205
virtual int writeProperties (const byte data[], int length) = 0;
206
206
virtual int writeShadowOut (const byte data[], int length) = 0;
207
207
208
-
209
-
208
+
209
+
210
210
211
211
ArduinoIoTConnectionStatus getIoTStatus () {
212
212
return _iotStatus;
213
213
}
214
214
215
215
ArduinoIoTConnectionStatus _iotStatus = ArduinoIoTConnectionStatus::IDLE;
216
-
217
216
218
-
217
+
218
+
219
219
ArduinoIoTSynchronizationStatus _syncStatus = ArduinoIoTSynchronizationStatus::SYNC_STATUS_SYNCHRONIZED;
220
220
221
-
222
- String _device_id = " " ;
223
- String _thing_id = " " ;
224
-
221
+
222
+ String _device_id = " " ;
223
+ String _thing_id = " " ;
224
+
225
225
226
226
ArduinoCloudThing Thing;
227
-
227
+
228
228
int _lastSyncRequestTickTime = 0 ;
229
229
230
- OnCloudEventCallback _on_sync_event_callback = NULL ;
231
- OnCloudEventCallback _on_connect_event_callback = NULL ;
232
- OnCloudEventCallback _on_disconnect_event_callback = NULL ;
230
+ OnCloudEventCallback _on_sync_event_callback = NULL ;
231
+ OnCloudEventCallback _on_connect_event_callback = NULL ;
232
+ OnCloudEventCallback _on_disconnect_event_callback = NULL ;
233
233
234
234
static void execCloudEventCallback (OnCloudEventCallback & callback, void * callback_arg) {
235
- if (callback) {
236
- (*callback)(callback_arg);
237
- }
238
- }
235
+ if (callback) {
236
+ (*callback)(callback_arg);
237
+ }
238
+ }
239
239
static void printConnectionStatus (ArduinoIoTConnectionStatus status) {
240
- switch (status) {
241
- case ArduinoIoTConnectionStatus::IDLE: Debug.print (DBG_INFO, " Arduino IoT Cloud Connection status: IDLE" ); break ;
242
- case ArduinoIoTConnectionStatus::ERROR: Debug.print (DBG_ERROR, " Arduino IoT Cloud Connection status: ERROR" ); break ;
243
- case ArduinoIoTConnectionStatus::CONNECTING: Debug.print (DBG_INFO, " Arduino IoT Cloud Connection status: CONNECTING" ); break ;
244
- case ArduinoIoTConnectionStatus::RECONNECTING: Debug.print (DBG_INFO, " Arduino IoT Cloud Connection status: RECONNECTING" ); break ;
245
- case ArduinoIoTConnectionStatus::CONNECTED: Debug.print (DBG_INFO, " Arduino IoT Cloud Connection status: CONNECTED" ); break ;
246
- case ArduinoIoTConnectionStatus::DISCONNECTED: Debug.print (DBG_ERROR, " Arduino IoT Cloud Connection status: DISCONNECTED" ); break ;
247
- }
248
- }
240
+ switch (status) {
241
+ case ArduinoIoTConnectionStatus::IDLE: Debug.print (DBG_INFO, " Arduino IoT Cloud Connection status: IDLE" ); break ;
242
+ case ArduinoIoTConnectionStatus::ERROR: Debug.print (DBG_ERROR, " Arduino IoT Cloud Connection status: ERROR" ); break ;
243
+ case ArduinoIoTConnectionStatus::CONNECTING: Debug.print (DBG_INFO, " Arduino IoT Cloud Connection status: CONNECTING" ); break ;
244
+ case ArduinoIoTConnectionStatus::RECONNECTING: Debug.print (DBG_INFO, " Arduino IoT Cloud Connection status: RECONNECTING" ); break ;
245
+ case ArduinoIoTConnectionStatus::CONNECTED: Debug.print (DBG_INFO, " Arduino IoT Cloud Connection status: CONNECTED" ); break ;
246
+ case ArduinoIoTConnectionStatus::DISCONNECTED: Debug.print (DBG_ERROR, " Arduino IoT Cloud Connection status: DISCONNECTED" ); break ;
247
+ }
248
+ }
249
249
};
250
250
251
251
#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_SAMD_NANO_33_IOT)
252
252
#include " ArduinoIoTCloudTCP.h"
253
-
253
+
254
254
#elif defined(ARDUINO_SAMD_MKRWAN1300) || defined(ARDUINO_SAMD_MKRWAN1310)
255
255
#include " ArduinoIoTCloudLPWAN.h"
256
-
256
+
257
257
#endif
258
258
259
259
#endif
0 commit comments