@@ -166,7 +166,7 @@ void ArduinoIoTCloudTCP::update() {
166
166
if (checkCloudConnection () != ArduinoIoTConnectionStatus::CONNECTED) return ;
167
167
168
168
if (_mqtt_data_request_retransmit && (_mqtt_data_len > 0 )) {
169
- writeProperties ( _mqtt_data_buf, _mqtt_data_len);
169
+ write (_dataTopicOut, _mqtt_data_buf, _mqtt_data_len);
170
170
_mqtt_data_request_retransmit = false ;
171
171
}
172
172
@@ -255,7 +255,7 @@ void ArduinoIoTCloudTCP::sendPropertiesToCloud() {
255
255
_mqtt_data_len = length;
256
256
memcpy (_mqtt_data_buf, data, _mqtt_data_len);
257
257
/* Transmit the properties to the MQTT broker */
258
- writeProperties ( _mqtt_data_buf, _mqtt_data_len);
258
+ write (_dataTopicOut, _mqtt_data_buf, _mqtt_data_len);
259
259
}
260
260
}
261
261
@@ -264,7 +264,7 @@ void ArduinoIoTCloudTCP::requestLastValue() {
264
264
// [{0: "r:m", 3: "getLastValues"}] = 81 A2 00 63 72 3A 6D 03 6D 67 65 74 4C 61 73 74 56 61 6C 75 65 73
265
265
// Use http://cbor.me to easily generate CBOR encoding
266
266
const uint8_t CBOR_REQUEST_LAST_VALUE_MSG[] = { 0x81 , 0xA2 , 0x00 , 0x63 , 0x72 , 0x3A , 0x6D , 0x03 , 0x6D , 0x67 , 0x65 , 0x74 , 0x4C , 0x61 , 0x73 , 0x74 , 0x56 , 0x61 , 0x6C , 0x75 , 0x65 , 0x73 };
267
- writeShadowOut ( CBOR_REQUEST_LAST_VALUE_MSG, sizeof (CBOR_REQUEST_LAST_VALUE_MSG));
267
+ write (_shadowTopicOut, CBOR_REQUEST_LAST_VALUE_MSG, sizeof (CBOR_REQUEST_LAST_VALUE_MSG));
268
268
}
269
269
270
270
NetworkConnectionState ArduinoIoTCloudTCP::checkPhyConnection ()
@@ -340,52 +340,16 @@ ArduinoIoTConnectionStatus ArduinoIoTCloudTCP::checkCloudConnection()
340
340
return _iotStatus;
341
341
}
342
342
343
- int ArduinoIoTCloudTCP::writeProperties (const byte data[], int length) {
344
- if (!_mqttClient->beginMessage (_dataTopicOut, length, false , 0 )) {
345
- return 0 ;
346
- }
347
-
348
- if (!_mqttClient->write (data, length)) {
349
- return 0 ;
350
- }
351
-
352
- if (!_mqttClient->endMessage ()) {
353
- return 0 ;
354
- }
355
-
356
- return 1 ;
357
- }
358
-
359
- int ArduinoIoTCloudTCP::writeStdout (const byte data[], int length) {
360
- if (!_mqttClient->beginMessage (_stdoutTopic, length, false , 0 )) {
361
- return 0 ;
362
- }
363
-
364
- if (!_mqttClient->write (data, length)) {
365
- return 0 ;
366
- }
367
-
368
- if (!_mqttClient->endMessage ()) {
369
- return 0 ;
370
- }
371
-
372
- return 1 ;
373
- }
374
-
375
- int ArduinoIoTCloudTCP::writeShadowOut (const byte data[], int length) {
376
- if (!_mqttClient->beginMessage (_shadowTopicOut, length, false , 0 )) {
377
- return 0 ;
378
- }
379
-
380
- if (!_mqttClient->write (data, length)) {
381
- return 0 ;
382
- }
383
-
384
- if (!_mqttClient->endMessage ()) {
385
- return 0 ;
343
+ int ArduinoIoTCloudTCP::write (String const topic, byte const data[], int const length)
344
+ {
345
+ if (_mqttClient->beginMessage (topic, length, false , 0 )) {
346
+ if (_mqttClient->write (data, length)) {
347
+ if (_mqttClient->endMessage ()) {
348
+ return 1 ;
349
+ }
350
+ }
386
351
}
387
-
388
- return 1 ;
352
+ return 0 ;
389
353
}
390
354
391
355
/* *****************************************************************************
0 commit comments