Blynk Diconnection Counter

@Dmitriy @Costas @vshymanskyy
Dear Sirs,
I am looking for the best way to implement at my ESP8266, a software counter that can count all Blynk disconnections. I will name this counter BDC ( BlynkDiconnectionCounter ) and I will type it as unsigned long ( or unsigned int ).
Where I need the help is: how can detect these possible Blynk disconnections ( from my hardware side ) ? What is the most clever / efficient way to do?

Come on, Blynk wizards, offer me your help.

Thanks amd Best Regards,
Mike Kranidis

Not sure the purpose of such a project, except for the sake of counting :wink:

use http://docs.blynk.cc/#blynk-firmware-connection-management-blynkconnected and build a counter routine around it. Perhaps saving the count to a history widget for later viewing.

Thanks a lot Dear @Gunner
I will study it and I will let you know about the solution implemented when ready…

Best Regards,
Mike Kranidis

P.S. by the way, this is not a project but a small part of a project. I need that implemented, to see howw much my hardware diconnecet from the Public Blynk Server…

1 Like

The easiest way is to count the number of connections rather than disconnections. They are effectively the same thing but with a connection you have the Blynk power. Sync variable from server, increment by 1 and virtualWrite back to server. Use display widget or even email / Push message the value to yourself.

Thanks @Costas
I saw already the “case” to use as you suggested and now I am testing something like:

/// Blynk Diconnection Counter ///
unsigned long BDC = 0; 

terminal.printf("\nDisconnections = %d\n",BDC); terminal.flush();

BLYNK_CONNECTED() {
  /// PUT HERE THE LOGIC OF CALENDAR NOTE ///
  BDC++;
  Blynk.run(); /// is it helpfull ??? ///
  Blynk.syncAll();
}

Isn’t blynk.run in the BLYNK_CONNECTED redundant? The loop will anyway have Blynk.run.

I also found Blynk.syncAll going though its own sequencing of sync from the lowest to the highest number of the virtual pins. Explicitly giving the pin numbers controls the sequence if it does matter to you. It did for me.