Skip to content

Commit 1339a1d

Browse files
committed
Execute handle_CheckDeviceConfig() only on thing_id changes ignoring other messages on device topic
1 parent 6ab8beb commit 1339a1d

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/ArduinoIoTCloudTCP.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,11 @@ void ArduinoIoTCloudTCP::update()
331331
_next_state = State::Invalid;
332332
}
333333

334+
if(getThingIdOutdatedFlag()) {
335+
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s Thing id outdated, reconfiguring...", __FUNCTION__);
336+
_state = State::CheckDeviceConfig;
337+
}
338+
334339
/* Run through the state machine. */
335340
State next_state = _state;
336341
switch (_state)
@@ -481,7 +486,6 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_WaitDeviceConfig()
481486
return State::SubscribeDeviceTopic;
482487
}
483488
}
484-
485489
return State::WaitDeviceConfig;
486490
}
487491

@@ -495,16 +499,13 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_CheckDeviceConfig()
495499
return State::ConnectPhy;
496500
}
497501

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

506-
_deviceSubscribedToThing = false;
507-
}
508+
_deviceSubscribedToThing = false;
508509
}
509510

510511
updateThingTopics();
@@ -700,7 +701,6 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
700701
CBORDecoder::decode(_device_property_container, (uint8_t*)bytes, length);
701702
_last_device_subscribe_cnt = 0;
702703
_next_device_subscribe_attempt_tick = 0;
703-
_next_state = State::CheckDeviceConfig;
704704
}
705705

706706
/* Topic for user input data */

0 commit comments

Comments
 (0)