Skip to content

Commit 718ddc7

Browse files
committed
Execute handle_CheckDeviceConfig() only on thing_id changes ignoring other messages on device topic
1 parent 1a02b83 commit 718ddc7

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/ArduinoIoTCloudTCP.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,11 @@ void ArduinoIoTCloudTCP::update()
333333
_next_state = State::Invalid;
334334
}
335335

336+
if(getThingIdOutdatedFlag()) {
337+
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s Thing id outdated, reconfiguring...", __FUNCTION__);
338+
_state = State::CheckDeviceConfig;
339+
}
340+
336341
/* Run through the state machine. */
337342
State next_state = _state;
338343
switch (_state)
@@ -483,7 +488,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
483488
return State::SubscribeDeviceTopic;
484489
}
485490
}
486-
487491
return State::WaitDeviceConfig;
488492
}
489493

@@ -497,16 +501,13 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
497501
return State::ConnectPhy;
498502
}
499503

500-
if(getThingIdOutdatedFlag())
504+
if(_deviceSubscribedToThing == true)
501505
{
502-
if(_deviceSubscribedToThing == true)
503-
{
504-
/* Unsubscribe from old things topics and go oi with a new subsctiption */
505-
_mqttClient.unsubscribe(_shadowTopicIn);
506-
_mqttClient.unsubscribe(_dataTopicIn);
506+
/* Unsubscribe from old things topics and go oi with a new subsctiption */
507+
_mqttClient.unsubscribe(_shadowTopicIn);
508+
_mqttClient.unsubscribe(_dataTopicIn);
507509

508-
_deviceSubscribedToThing = false;
509-
}
510+
_deviceSubscribedToThing = false;
510511
}
511512

512513
updateThingTopics();
@@ -723,7 +724,6 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
723724
CBORDecoder::decode(_device_property_container, (uint8_t*)bytes, length);
724725
_last_device_subscribe_cnt = 0;
725726
_next_device_subscribe_attempt_tick = 0;
726-
_next_state = State::CheckDeviceConfig;
727727
}
728728

729729
/* Topic for user input data */

0 commit comments

Comments
 (0)