@@ -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 }
@@ -325,6 +326,12 @@ void ArduinoIoTCloudTCP::update()
325
326
watchdog_reset ();
326
327
#endif
327
328
329
+ /* Check if the state has changed in message handler */
330
+ if (_next_state != State::Invalid)
331
+ {
332
+ _state = _next_state;
333
+ _next_state = State::Invalid;
334
+ }
328
335
329
336
/* Run through the state machine. */
330
337
State next_state = _state;
@@ -716,7 +723,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
716
723
CBORDecoder::decode (_device_property_container, (uint8_t *)bytes, length);
717
724
_last_device_subscribe_cnt = 0 ;
718
725
_next_device_subscribe_attempt_tick = 0 ;
719
- _state = State::CheckDeviceConfig;
726
+ _next_state = State::CheckDeviceConfig;
720
727
}
721
728
722
729
/* Topic for user input data */
@@ -734,7 +741,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
734
741
execCloudEventCallback (ArduinoIoTCloudEvent::SYNC);
735
742
_last_sync_request_cnt = 0 ;
736
743
_last_sync_request_tick = 0 ;
737
- _state = State::Connected;
744
+ _next_state = State::Connected;
738
745
}
739
746
}
740
747
0 commit comments