@@ -75,6 +75,12 @@ ArduinoIoTCloudTCP::ArduinoIoTCloudTCP()
75
75
, _password(" " )
76
76
#endif
77
77
, _mqttClient{nullptr }
78
+ , _deviceTopicOut(" " )
79
+ , _deviceTopicIn(" " )
80
+ , _shadowTopicOut(" " )
81
+ , _shadowTopicIn(" " )
82
+ , _dataTopicOut(" " )
83
+ , _dataTopicIn(" " )
78
84
#if OTA_ENABLED
79
85
, _ota_cap{false }
80
86
, _ota_error{static_cast <int >(OTAError::None)}
@@ -182,9 +188,8 @@ int ArduinoIoTCloudTCP::begin(bool const enable_watchdog, String brokerAddress,
182
188
_mqttClient.setConnectionTimeout (1500 );
183
189
_mqttClient.setId (getDeviceId ().c_str ());
184
190
185
- getTopic_devicein () = getTopic_devicein ();
186
-
187
- _messageTopicIn = getTopic_messagein ();
191
+ _deviceTopicOut = getTopic_deviceout ();
192
+ _deviceTopicIn = getTopic_devicein ();
188
193
189
194
_thing.begin ();
190
195
_device.begin ();
@@ -430,7 +435,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
430
435
}
431
436
432
437
/* Topic for OTA properties and device configuration */
433
- if (getTopic_devicein () == topic) {
438
+ if (_deviceTopicIn == topic) {
434
439
CBORDecoder::decode (_device.getPropertyContainer (), (uint8_t *)bytes, length);
435
440
436
441
/* Temporary check to avoid flooding device state machine with usless messages */
@@ -507,28 +512,6 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
507
512
508
513
void ArduinoIoTCloudTCP::sendMessage (Message * msg)
509
514
{
510
- switch (msg->id )
511
- {
512
- case DeviceBeginCmdId:
513
- sendDevicePropertiesToCloud ();
514
- break ;
515
-
516
- case ThingBeginCmdId:
517
- requestThingId ();
518
- break ;
519
-
520
- case LastValuesBeginCmdId:
521
- requestLastValue ();
522
- break ;
523
-
524
- case PropertiesUpdateCmdId:
525
- sendThingPropertiesToCloud ();
526
- break ;
527
-
528
- default :
529
- break ;
530
- }
531
-
532
515
uint8_t data[MQTT_TRANSMIT_BUFFER_SIZE];
533
516
size_t bytes_encoded = sizeof (data);
534
517
CBORMessageEncoder encoder;
@@ -566,24 +549,6 @@ void ArduinoIoTCloudTCP::sendThingPropertiesToCloud()
566
549
sendPropertyContainerToCloud (_dataTopicOut, _thing.getPropertyContainer (), _thing.getPropertyContainerIndex ());
567
550
}
568
551
569
- void ArduinoIoTCloudTCP::sendDevicePropertiesToCloud ()
570
- {
571
- PropertyContainer ro_device_property_container;
572
- unsigned int last_device_property_index = 0 ;
573
-
574
- std::list<String> ro_device_property_list {" LIB_VERSION" , " OTA_CAP" , " OTA_ERROR" , " OTA_SHA256" };
575
- std::for_each (ro_device_property_list.begin (),
576
- ro_device_property_list.end (),
577
- [this , &ro_device_property_container ] (String const & name)
578
- {
579
- Property* p = getProperty (this ->_device .getPropertyContainer (), name);
580
- if (p != nullptr )
581
- addPropertyToContainer (ro_device_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
582
- }
583
- );
584
- sendPropertyContainerToCloud (getTopic_deviceout (), ro_device_property_container, last_device_property_index);
585
- }
586
-
587
552
#if OTA_ENABLED
588
553
void ArduinoIoTCloudTCP::sendDevicePropertyToCloud (String const name)
589
554
{
@@ -594,31 +559,11 @@ void ArduinoIoTCloudTCP::sendDevicePropertyToCloud(String const name)
594
559
if (p != nullptr )
595
560
{
596
561
addPropertyToContainer (temp_device_property_container, *p, p->name (), p->isWriteableByCloud () ? Permission::ReadWrite : Permission::Read);
597
- sendPropertyContainerToCloud (getTopic_deviceout () , temp_device_property_container, last_device_property_index);
562
+ sendPropertyContainerToCloud (_deviceTopicOut , temp_device_property_container, last_device_property_index);
598
563
}
599
564
}
600
565
#endif
601
566
602
- void ArduinoIoTCloudTCP::requestLastValue ()
603
- {
604
- // Send the getLastValues CBOR message to the cloud
605
- // [{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
606
- // Use http://cbor.me to easily generate CBOR encoding
607
- 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 };
608
- write (_shadowTopicOut, CBOR_REQUEST_LAST_VALUE_MSG, sizeof (CBOR_REQUEST_LAST_VALUE_MSG));
609
- }
610
-
611
- void ArduinoIoTCloudTCP::requestThingId ()
612
- {
613
- if (!_mqttClient.subscribe (getTopic_devicein ()))
614
- {
615
- /* If device_id is wrong the board can't connect to the broker so this condition
616
- * should never happen.
617
- */
618
- DEBUG_ERROR (" ArduinoIoTCloudTCP::%s could not subscribe to %s" , __FUNCTION__, getTopic_devicein ().c_str ());
619
- }
620
- }
621
-
622
567
void ArduinoIoTCloudTCP::attachThing ()
623
568
{
624
569
0 commit comments