Rolling boot count

I am trying to retrieve my last number from the server. In this case it is for a boot count every deep sleep cycle. Why does > Blynk.sync(V9); not work? Or is the only way to do this write it to SPIFFS?

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

//You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "====";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "=====";
char pass[] = "=====";

BlynkTimer timer;
WidgetLCD lcd (V0);

int espCycles;

void goToSleep(){
  timer.setTimeout(5000L,[](){                                     //Lambda 
      espCycles ++;;
      Blynk.virtualWrite(V9, espCycles);
      ESP.deepSleep(3e+7); //sleep  NOTE THIS IS IN MICROSECONDS!!!!!!!!

void setup()
// Debug console
//Blynk.begin(auth, ssid, pass);
Blynk.begin(auth, ssid, pass, IPAddress(192,168,0,97), 8080);
timer.setInterval(10000L, goToSleep); //this one is millis
lcd.print(0,0, "Starting..");
Blynk.virtualWrite(V9, espCycles);

void loop()

I have been trying to wade through your connected beehive @christophebl @PeteKnight . It looks like you are doing a boot count to V0 but I can’t see a virtual sync??


You have this in your void setup() Which runs at boot and may dump somthing new to that vPin before it gets a chance to read what was previously there.

If you want to get last value, then remove the above issue and try the sync command in a Blynk.connected() function

The Blynk.syncVirtual(V9) command won’t actually retrieve the value from pin V9, it just causes the BLYNK_WRITE(V9) callback function to be ‘fired’. As you don’t have a BLYNK_WRITE(V9) function and corresponding espCycles = param.asInt() line of code then the sync process will never work.

Also, I firmly believe that timers should never be used with deep sleep, unless you need to repeat something x times before sleeping.
The timer simply takes away your control over when the sleep process begins. Far better to execute the code you want, then as soon as it’s done go to sleep.
BTW, you have the SimpleTimer library included, which isn’t being used.


Good catch, I wasn’t paying full attention.

It has been awhile since I used Blynk, so that’s my story and I am sticking to it :grin:

1 Like

Thanks for the pointers. The timer was for testing :rofl: no seriously, I thought maybe there wasn’t enough elapse time to complete the writes. I will try to remember that for the future.

So what you are saying is I need to make a function. Like below.

  espCycles = param.asInt();

Then any time I call


It will execute that function?

1 Like

You’ve got it!


Wow I sure did read that in the Docs… maybe there is more info on it elsewhere…

The description in the docs is somewhat cryptic…


This command updates individual Virtual Pin to the latest stored value on the server. When it’s used, a corresponding BLYNK_WRITE handler is called.

Basically the BLYNK_WRITE(Vpin) callback is triggered every time the value of the corresponding Vpin changes. What the Blynk.syncVpin command does is to force the server to push out the current value for that Vpin as if it had changed - but of course it hasn’t.
It’s usually used in connection with BLYNK_CONNECTED, so that every time the device connects, or re-connects to Blynk, the latest value for the Vpin is pulled back from the server and saved to your variable using the[variable type] command.