@@ -122,29 +122,6 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) {
122
122
return 1 ;
123
123
}
124
124
125
- // private class method used to initialize mqttClient class member. (called in the begin class method)
126
- void ArduinoIoTCloudTCP::mqttClientBegin () {
127
- // MQTT topics definition
128
- _stdoutTopic = " /a/d/" + _device_id + " /s/o" ;
129
- _stdinTopic = " /a/d/" + _device_id + " /s/i" ;
130
- if (_thing_id == " " ) {
131
- _dataTopicIn = " /a/d/" + _device_id + " /e/i" ;
132
- _dataTopicOut = " /a/d/" + _device_id + " /e/o" ;
133
- } else {
134
- _dataTopicIn = " /a/t/" + _thing_id + " /e/i" ;
135
- _dataTopicOut = " /a/t/" + _thing_id + " /e/o" ;
136
- _shadowTopicIn = " /a/t/" + _thing_id + " /shadow/i" ;
137
- _shadowTopicOut = " /a/t/" + _thing_id + " /shadow/o" ;
138
- }
139
-
140
- // use onMessage as callback for received mqtt messages
141
- _mqttClient->onMessage (ArduinoIoTCloudTCP::onMessage);
142
- _mqttClient->setKeepAliveInterval (30 * 1000 );
143
- _mqttClient->setConnectionTimeout (1500 );
144
- _mqttClient->setId (_device_id.c_str ());
145
- }
146
-
147
-
148
125
int ArduinoIoTCloudTCP::connect () {
149
126
150
127
if (!_mqttClient->connect (_brokerAddress.c_str (), _brokerPort)) {
@@ -230,54 +207,6 @@ int ArduinoIoTCloudTCP::connected() {
230
207
return _mqttClient->connected ();
231
208
}
232
209
233
- int ArduinoIoTCloudTCP::writeProperties (const byte data[], int length) {
234
- if (!_mqttClient->beginMessage (_dataTopicOut, length, false , 0 )) {
235
- return 0 ;
236
- }
237
-
238
- if (!_mqttClient->write (data, length)) {
239
- return 0 ;
240
- }
241
-
242
- if (!_mqttClient->endMessage ()) {
243
- return 0 ;
244
- }
245
-
246
- return 1 ;
247
- }
248
-
249
- int ArduinoIoTCloudTCP::writeStdout (const byte data[], int length) {
250
- if (!_mqttClient->beginMessage (_stdoutTopic, length, false , 0 )) {
251
- return 0 ;
252
- }
253
-
254
- if (!_mqttClient->write (data, length)) {
255
- return 0 ;
256
- }
257
-
258
- if (!_mqttClient->endMessage ()) {
259
- return 0 ;
260
- }
261
-
262
- return 1 ;
263
- }
264
-
265
- int ArduinoIoTCloudTCP::writeShadowOut (const byte data[], int length) {
266
- if (!_mqttClient->beginMessage (_shadowTopicOut, length, false , 0 )) {
267
- return 0 ;
268
- }
269
-
270
- if (!_mqttClient->write (data, length)) {
271
- return 0 ;
272
- }
273
-
274
- if (!_mqttClient->endMessage ()) {
275
- return 0 ;
276
- }
277
-
278
- return 1 ;
279
- }
280
-
281
210
/* *****************************************************************************
282
211
* PRIVATE MEMBER FUNCTIONS
283
212
******************************************************************************/
@@ -404,6 +333,75 @@ ArduinoIoTConnectionStatus ArduinoIoTCloudTCP::checkCloudConnection()
404
333
return _iotStatus;
405
334
}
406
335
336
+ void ArduinoIoTCloudTCP::mqttClientBegin () {
337
+ // MQTT topics definition
338
+ _stdoutTopic = " /a/d/" + _device_id + " /s/o" ;
339
+ _stdinTopic = " /a/d/" + _device_id + " /s/i" ;
340
+ if (_thing_id == " " ) {
341
+ _dataTopicIn = " /a/d/" + _device_id + " /e/i" ;
342
+ _dataTopicOut = " /a/d/" + _device_id + " /e/o" ;
343
+ } else {
344
+ _dataTopicIn = " /a/t/" + _thing_id + " /e/i" ;
345
+ _dataTopicOut = " /a/t/" + _thing_id + " /e/o" ;
346
+ _shadowTopicIn = " /a/t/" + _thing_id + " /shadow/i" ;
347
+ _shadowTopicOut = " /a/t/" + _thing_id + " /shadow/o" ;
348
+ }
349
+
350
+ // use onMessage as callback for received mqtt messages
351
+ _mqttClient->onMessage (ArduinoIoTCloudTCP::onMessage);
352
+ _mqttClient->setKeepAliveInterval (30 * 1000 );
353
+ _mqttClient->setConnectionTimeout (1500 );
354
+ _mqttClient->setId (_device_id.c_str ());
355
+ }
356
+
357
+ int ArduinoIoTCloudTCP::writeProperties (const byte data[], int length) {
358
+ if (!_mqttClient->beginMessage (_dataTopicOut, length, false , 0 )) {
359
+ return 0 ;
360
+ }
361
+
362
+ if (!_mqttClient->write (data, length)) {
363
+ return 0 ;
364
+ }
365
+
366
+ if (!_mqttClient->endMessage ()) {
367
+ return 0 ;
368
+ }
369
+
370
+ return 1 ;
371
+ }
372
+
373
+ int ArduinoIoTCloudTCP::writeStdout (const byte data[], int length) {
374
+ if (!_mqttClient->beginMessage (_stdoutTopic, length, false , 0 )) {
375
+ return 0 ;
376
+ }
377
+
378
+ if (!_mqttClient->write (data, length)) {
379
+ return 0 ;
380
+ }
381
+
382
+ if (!_mqttClient->endMessage ()) {
383
+ return 0 ;
384
+ }
385
+
386
+ return 1 ;
387
+ }
388
+
389
+ int ArduinoIoTCloudTCP::writeShadowOut (const byte data[], int length) {
390
+ if (!_mqttClient->beginMessage (_shadowTopicOut, length, false , 0 )) {
391
+ return 0 ;
392
+ }
393
+
394
+ if (!_mqttClient->write (data, length)) {
395
+ return 0 ;
396
+ }
397
+
398
+ if (!_mqttClient->endMessage ()) {
399
+ return 0 ;
400
+ }
401
+
402
+ return 1 ;
403
+ }
404
+
407
405
/* *****************************************************************************
408
406
* EXTERN DEFINITION
409
407
******************************************************************************/
0 commit comments