diff --git a/features/cellular/framework/device/CellularStateMachine.cpp b/features/cellular/framework/device/CellularStateMachine.cpp index f84d41fcdb..0e76f5406c 100644 --- a/features/cellular/framework/device/CellularStateMachine.cpp +++ b/features/cellular/framework/device/CellularStateMachine.cpp @@ -644,7 +644,7 @@ void CellularStateMachine::event() break; } - if ((_target_state == _state && _cb_data.error == NSAPI_ERROR_OK && !_is_retry) || _event_id == STM_STOPPED) { + if (check_is_target_reached()) { _event_id = -1; return; } @@ -687,6 +687,18 @@ void CellularStateMachine::set_cellular_callback(mbed::Callbackset_at_mode() == NSAPI_ERROR_OK) { tr_debug("State was STATE_DEVICE_READY and at mode ready, cancel state and move to next"); _queue.cancel(_event_id); + _event_id = -1; if (device_ready()) { - continue_from_state(STATE_SIM_PIN); + _is_retry = false; + if (!check_is_target_reached()) { + continue_from_state(STATE_SIM_PIN); + } } else { continue_from_state(STATE_DEVICE_READY); } diff --git a/features/cellular/framework/device/CellularStateMachine.h b/features/cellular/framework/device/CellularStateMachine.h index 386b39dcc4..eea4603c6e 100644 --- a/features/cellular/framework/device/CellularStateMachine.h +++ b/features/cellular/framework/device/CellularStateMachine.h @@ -157,6 +157,7 @@ private: void event(); void ready_urc_cb(); void pre_event(CellularState state); + bool check_is_target_reached(); CellularDevice &_cellularDevice; CellularState _state;