Skip to content

Commit a9c96b9

Browse files
authored
Fix: Immediately trigger a sync request on the first time this function is reached. (#250)
It does not make sense to let the user wait until the timeout has passed (which is now even 30 seconds) long. Therefore the logic should trigger an immediate sync the first time this function is reached.
1 parent b7be705 commit a9c96b9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/ArduinoIoTCloudTCP.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()
420420

421421
/* Check whether or not we need to send a new request. */
422422
unsigned long const now = millis();
423-
if ((now - _last_sync_request_tick) > AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms)
423+
bool const is_sync_request_timeout = (now - _last_sync_request_tick) > AIOT_CONFIG_TIMEOUT_FOR_LASTVALUES_SYNC_ms;
424+
bool const is_first_sync_request = (_last_sync_request_cnt == 0);
425+
if (is_first_sync_request || is_sync_request_timeout)
424426
{
425427
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] last values requested", __FUNCTION__, now);
426428
requestLastValue();
@@ -433,6 +435,7 @@ ArduinoIoTCloudTCP::State ArduinoIoTCloudTCP::handle_RequestLastValues()
433435
if (_last_sync_request_cnt > AIOT_CONFIG_LASTVALUES_SYNC_MAX_RETRY_CNT)
434436
{
435437
_last_sync_request_cnt = 0;
438+
_last_sync_request_tick = 0;
436439
_mqttClient.stop();
437440
execCloudEventCallback(ArduinoIoTCloudEvent::DISCONNECT);
438441
return State::ConnectPhy;
@@ -531,6 +534,7 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
531534
sendPropertiesToCloud();
532535
execCloudEventCallback(ArduinoIoTCloudEvent::SYNC);
533536
_last_sync_request_cnt = 0;
537+
_last_sync_request_tick = 0;
534538
_state = State::Connected;
535539
}
536540
}

0 commit comments

Comments
 (0)