Skip to content

Fix: Immediately trigger a sync request on the first time this function is reached #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,9 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()

/* Check whether or not we need to send a new request. */
unsigned long const now = millis();
if ((now - _last_sync_request_tick) > AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms)
bool const is_sync_request_timeout = (now - _last_sync_request_tick) > AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms;
bool const is_first_sync_request = (_last_sync_request_cnt == 0);
if (is_first_sync_request || is_sync_request_timeout)
{
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] last values requested", __FUNCTION__, now);
requestLastValue();
Expand All @@ -433,6 +435,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()
if (_last_sync_request_cnt > AIOT_CONFIG_LASTVALUES_SYNC_MAX_RETRY_CNT)
{
_last_sync_request_cnt = 0;
_last_sync_request_tick = 0;
_mqttClient.stop();
execCloudEventCallback(ArduinoIoTCloudEvent::DISCONNECT);
return State::ConnectPhy;
Expand Down Expand Up @@ -531,6 +534,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
sendPropertiesToCloud();
execCloudEventCallback(ArduinoIoTCloudEvent::SYNC);
_last_sync_request_cnt = 0;
_last_sync_request_tick = 0;
_state = State::Connected;
}
}
Expand Down