Blynk.syncAll() with Blynk.sendInternal() Lagging Issues - Found work-around

I found a work around to an issue I was having with using the Blynk.sendInternal("utc", "time") command to receive the local time and timezone information.

Issue:
Most times it would take a few minutes to receive the time response from the cloud and sometimes the timezone would be incorrect.

Resolution:
After some troubleshooting I’ve determined that the issue was within the BLYNK_CONNECTED() {} function call. I was calling Blynk.syncAll() prior to Blynk.sendInternal(). After switching the sequence, everything seems to work as normal.

This should be documented somewhere or fixed.

Working Code:

BLYNK_CONNECTED() {
   // This has to be called before syncAll()
   Blynk.sendInternal("utc", "time");      // Unix timestamp (with msecs)
   Blynk.sendInternal("utc", "tz_rule");   // POSIX TZ rule
   // syncAll() has to come second or time syncing doesn't work correctly or lags.
   Blynk.syncAll();
}

Using Blynk.syncAll(); is not a good practice.

Its better to use Blynk.syncVirtual(define all the used V pins here ); this way you are just fetching data of the vpins used, else syncAll command world try to fetch data of all 255 pins, this will show down the process of syncing.

As @Madhukesh says, using Blynk.syncAll() isn’t good practice.
The command is a massive overkill for most situations, and it can also be confusing, because it’s name implies that it will synchronise all virtual datastreams but in reality it only works for the datastreams that have the “ Sync with latest server value every time device connects to the cloud” option enabled.

For most projects you only need your device to be updated with a handful of virtual datastream values on startup, so it’s far better (and quicker) to explicitly call a Blynk.syncVirtual(vPin) for each pin that is needed.

Pete.

Thanks for the advice. I will test using Blynk.syncVirtual() (for each of my vPins) before and after Blynk.sendInternal() to see if that also avoids the issue. I’ll report back when I get a chance to test.

After changing Blynk.syncAll() to Blynk.syncVirtual(), the order of the commands within BLYNK_CONNECTED() did not appear to matter.

Final Working Code:

BLYNK_CONNECTED() {
   Blynk.sendInternal("utc", "time");      // Unix timestamp (with msecs)
   Blynk.sendInternal("utc", "tz_rule");   // POSIX TZ rule
   // use syncVirtual() instead of syncAll() to avoid issues with lagging
   Blynk.syncVirtual(V0, V1, V2);
}