Skip to content

Commit 4dddff0

Browse files
committed
Execute handle_CheckDeviceConfig() only on thing_id changes ignoring other messages on device topic
1 parent a752edc commit 4dddff0

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)
@@ -482,7 +487,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
482487
return State::SubscribeDeviceTopic;
483488
}
484489
}
485-
486490
return State::WaitDeviceConfig;
487491
}
488492

@@ -496,16 +500,13 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
496500
return State::ConnectPhy;
497501
}
498502

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

507-
_deviceSubscribedToThing = false;
508-
}
509+
_deviceSubscribedToThing = false;
509510
}
510511

511512
updateThingTopics();
@@ -701,7 +702,6 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
701702
CBORDecoder::decode(_device_property_container, (uint8_t*)bytes, length);
702703
_last_device_subscribe_cnt = 0;
703704
_next_device_subscribe_attempt_tick = 0;
704-
_next_state = State::CheckDeviceConfig;
705705
}
706706

707707
/* Topic for user input data */

0 commit comments

Comments
 (0)