@@ -80,6 +80,7 @@ extern "C" void setThingIdOutdated()
80
80
81
81
ArduinoIoTCloudTCP::ArduinoIoTCloudTCP ()
82
82
: _state{State::ConnectPhy}
83
+ , _next_state{State::Invalid}
83
84
, _next_connection_attempt_tick{0 }
84
85
, _last_connection_attempt_cnt{0 }
85
86
, _next_device_subscribe_attempt_tick{0 }
@@ -323,6 +324,13 @@ void ArduinoIoTCloudTCP::update()
323
324
watchdog_reset ();
324
325
#endif
325
326
327
+ /* Check if the state has changed in message handler */
328
+ if (_next_state != State::Invalid)
329
+ {
330
+ DEBUG_VERBOSE (" ArduinoIoTCloudTCP::%s state changed in message handler" , __FUNCTION__);
331
+ _state = _next_state;
332
+ _next_state = State::Invalid;
333
+ }
326
334
327
335
/* Run through the state machine. */
328
336
State next_state = _state;
@@ -694,7 +702,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
694
702
CBORDecoder::decode (_device_property_container, (uint8_t *)bytes, length);
695
703
_last_device_subscribe_cnt = 0 ;
696
704
_next_device_subscribe_attempt_tick = 0 ;
697
- _state = State::CheckDeviceConfig;
705
+ _next_state = State::CheckDeviceConfig;
698
706
}
699
707
700
708
/* Topic for user input data */
@@ -712,7 +720,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
712
720
execCloudEventCallback (ArduinoIoTCloudEvent::SYNC);
713
721
_last_sync_request_cnt = 0 ;
714
722
_last_sync_request_tick = 0 ;
715
- _state = State::Connected;
723
+ _next_state = State::Connected;
716
724
}
717
725
}
718
726
0 commit comments