Skip to content

Commit 1feb373

Browse files
committed
Execute handle_CheckDeviceConfig() only on thing_id changes ignoring other messages on device topic
1 parent 5b87b2b commit 1feb373

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,16 @@ void ArduinoIoTCloudTCP::update()
327327
/* Check if the state has changed in message handler */
328328
if(_next_state != State::Invalid)
329329
{
330-
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s state changed in message handler", __FUNCTION__);
330+
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s State changed in message handler...", __FUNCTION__);
331331
_state = _next_state;
332332
_next_state = State::Invalid;
333333
}
334334

335+
if(getThingIdOutdatedFlag()) {
336+
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s Thing id outdated, reconfiguring...", __FUNCTION__);
337+
_state = State::CheckDeviceConfig;
338+
}
339+
335340
/* Run through the state machine. */
336341
State next_state = _state;
337342
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();
@@ -702,7 +703,6 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
702703
CBORDecoder::decode(_device_property_container, (uint8_t*)bytes, length);
703704
_last_device_subscribe_cnt = 0;
704705
_next_device_subscribe_attempt_tick = 0;
705-
_next_state = State::CheckDeviceConfig;
706706
}
707707

708708
/* Topic for user input data */

0 commit comments

Comments
 (0)