Blynk_(dis)connected()?

Hi all,

I’m trying to follow disconnections with Blynk-cloud
I’m happy to use BLYNK_CONNECTED() to see when I reconnect.
But is there a kind of BLYNK_DISCONNECTED() function ?

Regards
Laurent

Not a dedicated function per se… since if Blynk is disconnected it couldn’t really run anyhow…

But you can simply use the boolean check with the Blynk.connected() command (note the different case)

This is very commonly used to allow code to run as normal when connected, or to keep running even without Blynk server connection, while running timed reconnection routines… otherwise the code would keep trying to reconnect each time it hit the Blynk.run() command and effectively lock up your code if connection didn’t happen.

void loop() {
  if (Blynk.connected()) {  // If connected...
    Blynk.run();  //  ...  run as normal
  } else { // If NOT connected...
  // ... do something about it, etc.
  }
  timer.run();  // Run all the time to keep timers working (no server required for this)
}
1 Like