@@ -118,96 +118,106 @@ class ArduinoIoTCloudClass {
118
118
119
119
static unsigned long const DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS = 500 ; /* Data rate throttled to 2 Hz */
120
120
121
- 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) {
122
- Permission permission = Permission::ReadWrite;
123
- if (permission_type == READ ) permission = Permission::Read;
124
- else if (permission_type == WRITE) permission = Permission::Write;
125
- else permission = Permission::ReadWrite;
126
-
127
- if (seconds == ON_CHANGE) {
128
- Thing.addPropertyReal (property, name, permission).publishOnChange (minDelta, DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS).onUpdate (fn).onSync (synFn);
129
- } else {
130
- Thing.addPropertyReal (property, name, permission).publishEvery (seconds).onUpdate (fn).onSync (synFn);
121
+ 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) {
122
+ Permission permission = Permission::ReadWrite;
123
+ if (permission_type == READ) {
124
+ permission = Permission::Read;
125
+ } else if (permission_type == WRITE) {
126
+ permission = Permission::Write;
127
+ } else {
128
+ permission = Permission::ReadWrite;
129
+ }
130
+
131
+ if (seconds == ON_CHANGE) {
132
+ Thing.addPropertyReal (property, name, permission).publishOnChange (minDelta, DEFAULT_MIN_TIME_BETWEEN_UPDATES_MILLIS).onUpdate (fn).onSync (synFn);
133
+ } else {
134
+ Thing.addPropertyReal (property, name, permission).publishEvery (seconds).onUpdate (fn).onSync (synFn);
135
+ }
131
136
}
132
- }
133
-
134
- ArduinoCloudProperty& addPropertyReal (ArduinoCloudProperty & property, String const & name, Permission const permission) {
135
- return Thing.addPropertyReal (property, name, permission);
136
- }
137
-
138
- 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) {
139
- ArduinoCloudProperty *p = new CloudWrapperBool (property);
140
- addPropertyReal (*p, name, permission_type, seconds, fn, minDelta, synFn);
141
- }
142
- 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) {
143
- ArduinoCloudProperty *p = new CloudWrapperFloat (property);
144
- addPropertyReal (*p, name, permission_type, seconds, fn, minDelta, synFn);
145
- }
146
- 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) {
147
- ArduinoCloudProperty *p = new CloudWrapperInt (property);
148
- addPropertyReal (*p, name, permission_type, seconds, fn, minDelta, synFn);
149
- }
150
- 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) {
151
- ArduinoCloudProperty *p = new CloudWrapperString (property);
152
- addPropertyReal (*p, name, permission_type, seconds, fn, minDelta, synFn);
153
- }
154
-
155
- void connectionCheck ();
156
- String getBrokerAddress (){ return _brokerAddress; }
157
- uint16_t getBrokerPort () { return _brokerPort; }
158
- void printDebugInfo ();
159
- void addCallback (ArduinoIoTCloudEvent const event, OnCloudEventCallback callback);
160
-
161
- protected:
162
- friend class CloudSerialClass ;
163
- int writeStdout (const byte data[], int length);
164
- int writeProperties (const byte data[], int length);
165
- int writeShadowOut (const byte data[], int length);
166
-
167
- // Used to initialize MQTTClient
168
- void mqttClientBegin ();
169
- // Function in charge of perform MQTT reconnection, basing on class parameters(retries,and timeout)
170
- bool mqttReconnect (int const maxRetries, int const timeout);
171
- // Used to retrieve last values from _shadowTopicIn
172
- void requestLastValue ();
173
-
174
- ArduinoIoTConnectionStatus getIoTStatus () { return iotStatus; }
175
- void setIoTConnectionState (ArduinoIoTConnectionStatus _newState);
176
- private:
177
- ArduinoIoTConnectionStatus iotStatus = ArduinoIoTConnectionStatus::IDLE;
178
- ConnectionManager *connection;
179
- static void onMessage (int length);
180
- void handleMessage (int length);
181
- ArduinoIoTSynchronizationStatus _syncStatus = ArduinoIoTSynchronizationStatus::SYNC_STATUS_SYNCHRONIZED;
182
-
183
- void sendPropertiesToCloud ();
184
-
185
-
186
- String _device_id,
187
- _thing_id,
188
- _brokerAddress;
189
- uint16_t _brokerPort;
190
- ArduinoCloudThing Thing;
191
- BearSSLClient* _bearSslClient;
192
- MqttClient* _mqttClient;
193
- int _lastSyncRequestTickTime;
194
-
195
-
196
- // Class attribute to define MTTQ topics 2 for stdIn/out and 2 for data, in order to avoid getting previous pupblished payload
197
- String _stdinTopic;
198
- String _stdoutTopic;
199
- String _shadowTopicOut;
200
- String _shadowTopicIn;
201
- String _dataTopicOut;
202
- String _dataTopicIn;
203
- String _otaTopic;
204
- Client *_net;
205
-
206
- OnCloudEventCallback _on_sync_event_callback,
207
- _on_connect_event_callback,
208
- _on_disconnect_event_callback;
209
-
210
- static void execCloudEventCallback (OnCloudEventCallback & callback, void * callback_arg);
137
+
138
+ ArduinoCloudProperty& addPropertyReal (ArduinoCloudProperty & property, String const & name, Permission const permission) {
139
+ return Thing.addPropertyReal (property, name, permission);
140
+ }
141
+
142
+ 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) {
143
+ ArduinoCloudProperty *p = new CloudWrapperBool (property);
144
+ addPropertyReal (*p, name, permission_type, seconds, fn, minDelta, synFn);
145
+ }
146
+ 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) {
147
+ ArduinoCloudProperty *p = new CloudWrapperFloat (property);
148
+ addPropertyReal (*p, name, permission_type, seconds, fn, minDelta, synFn);
149
+ }
150
+ 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) {
151
+ ArduinoCloudProperty *p = new CloudWrapperInt (property);
152
+ addPropertyReal (*p, name, permission_type, seconds, fn, minDelta, synFn);
153
+ }
154
+ 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) {
155
+ ArduinoCloudProperty *p = new CloudWrapperString (property);
156
+ addPropertyReal (*p, name, permission_type, seconds, fn, minDelta, synFn);
157
+ }
158
+
159
+ void connectionCheck ();
160
+ String getBrokerAddress () {
161
+ return _brokerAddress;
162
+ }
163
+ uint16_t getBrokerPort () {
164
+ return _brokerPort;
165
+ }
166
+ void printDebugInfo ();
167
+ void addCallback (ArduinoIoTCloudEvent const event, OnCloudEventCallback callback);
168
+
169
+ protected:
170
+ friend class CloudSerialClass ;
171
+ int writeStdout (const byte data[], int length);
172
+ int writeProperties (const byte data[], int length);
173
+ int writeShadowOut (const byte data[], int length);
174
+
175
+ // Used to initialize MQTTClient
176
+ void mqttClientBegin ();
177
+ // Function in charge of perform MQTT reconnection, basing on class parameters(retries,and timeout)
178
+ bool mqttReconnect (int const maxRetries, int const timeout);
179
+ // Used to retrieve last values from _shadowTopicIn
180
+ void requestLastValue ();
181
+
182
+ ArduinoIoTConnectionStatus getIoTStatus () {
183
+ return iotStatus;
184
+ }
185
+ void setIoTConnectionState (ArduinoIoTConnectionStatus _newState);
186
+ private:
187
+ ArduinoIoTConnectionStatus iotStatus = ArduinoIoTConnectionStatus::IDLE;
188
+ ConnectionManager *connection;
189
+ static void onMessage (int length);
190
+ void handleMessage (int length);
191
+ ArduinoIoTSynchronizationStatus _syncStatus = ArduinoIoTSynchronizationStatus::SYNC_STATUS_SYNCHRONIZED;
192
+
193
+ void sendPropertiesToCloud ();
194
+
195
+
196
+ String _device_id,
197
+ _thing_id,
198
+ _brokerAddress;
199
+ uint16_t _brokerPort;
200
+ ArduinoCloudThing Thing;
201
+ BearSSLClient* _bearSslClient;
202
+ MqttClient* _mqttClient;
203
+ int _lastSyncRequestTickTime;
204
+
205
+
206
+ // Class attribute to define MTTQ topics 2 for stdIn/out and 2 for data, in order to avoid getting previous pupblished payload
207
+ String _stdinTopic;
208
+ String _stdoutTopic;
209
+ String _shadowTopicOut;
210
+ String _shadowTopicIn;
211
+ String _dataTopicOut;
212
+ String _dataTopicIn;
213
+ String _otaTopic;
214
+ Client *_net;
215
+
216
+ OnCloudEventCallback _on_sync_event_callback,
217
+ _on_connect_event_callback,
218
+ _on_disconnect_event_callback;
219
+
220
+ static void execCloudEventCallback (OnCloudEventCallback & callback, void * callback_arg);
211
221
};
212
222
213
223
extern ArduinoIoTCloudClass ArduinoCloud;
0 commit comments