How to debug Blynk.syncVirtual()?

syncVirtual() returns void. There is no indication of what had gone wrong when no sync happens, how do we debug it?

I have 2 (switch) buttons on dashboard that control V0 and V1 (config1 config2). I thought I had in the past been able to change those from web dashboard and reflect on the hardware, but no longer.

I know my connection is good, because the hardware is successful in updating the time string (shown correctly on the dashboard) for every update, but “syncVirtual” seemingly did not happen: config1 remains unchanged on the hardware as reflected on Serial.println, BLYNK_WRITE(V1) (and V0) do not appeared to be called as those Serial.printf did not show up… all the while the Serial.println(“update successful”) shows just fine.

I have double checked my pin numbers (V0 V1) are mapped correctly. The hardware is in sleep (30 secs) when i flip the switch on the dashboard, but I do not think that will matter.

BLYNK_WRITE(V0) {
  config0 = param.asInt();
  Serial.printf("config 0 is now %d\n", config0);
}

BLYNK_WRITE(V1) {
  config1 = param.asInt();
  Serial.printf("config 1 is now %d\n", config1);
}

void update() {
  if (connect_to_blynk()) {
    Blynk.syncVirtual(V0, V1);
    Blynk.virtualWrite(V2, getTimeStr());
    Serial.println("update successful");
  } else {
    Serial.println("update failed");
  }
}

void loop() {
  lightsleep();
  update();
  Serial.printf("config1 is now %d\n", config1);
}

HW is esp8266, Blynk version 1.3.2

My advice would be not to run this sketch as it stands, and to post your full sketch - including the contents of your lightsleep and connect_to_blynk functions.

Light sleep turns off WiFi, so Blynk is disconnected during light sleep. When the device wakes-up again and re-connects to Blynk, a Blynk.connected() test may return true, but that doesn’t necessarily mean that the device is ready to perform a Blynk.syncVirtual(Vpin).
To be certain of that you need to put your code in the BLYNK_CONNECTED() callback function, as that will be executed when the Blynk connection is actually ready.

Also, Blynk.run() is required to force callback functions like BLYNK_CONNECTED() and BLYNK_WRITE(Vpin) to execute, and I don’t see that in the code you’ve posted. Even if it exists, it will need to be executed multiple times, so needs to be in your void loop() - but of course that means the call to your lightsleep() can’t be in there too - assuming that this function does what I expect it to.

TBH, there’s no real value in using light sleep with Blynk, you’d be better using deep sleep, and using a totally different program structure to the one you’d use with a regular Blynk sketch.

Pete.

Thanks so much, your explanation is very helpful in explaining things, but

Even if it exists, it will need to be executed multiple times, so needs to be in your void loop() - but of course that means the call to your lightsleep() can’t be in there too - assuming that this function does what I expect it to.

I can see how we can key off BLYNK_CONNECTED() as the connection being ready, but what would be a mechanism to know we’ve run enough .run()? Deepsleep is not quite what I can do from needing to keep pinstate to, to needing the reset pin for other purposes…

BLYNK_CONNECTED() will be called, and the code within it will be executed.

TBH, asking isolated questions and posting snippets of code isn’t the best way to proceed with this.

I’d suggest that you take a couple of steps back and describe your ‘big picture’ goal in detail, and when you’re posting code be sure to post your complete sketch.

Pete.