BLYNK_CONNECTED how works?

Hi, I was looking at the documentation, and I realized the BLYNK_CONNECTED () function, but I have not figured out if it is called only when you connect to the server, so once per connection, or if you continually call if you are connected to Blynk server, thanks for the help

Hello. The answer is

1 Like

Thank you, why in the example synch is a variable that runs the synch all at once if the function is performed only once?

Here the code
BLYNK_CONNECTED() {
if (isFirstConnect) {
Blynk.syncAll();
isFirstConnect = false;
}

  // Let's write your hardware uptime to Virtual Pin 2
  int value = millis() / 1000;
  Blynk.virtualWrite(V2, value);
}
1 Like

Because connection may be dropped. And establishing new connection will call BLYNK_CONNECTED again.

1 Like

I was wondering how to get a constanly updated uptime… I tried the code Thomas has written, outputting the value to V3, but it refreshes the uptime only if I reset my Wi-Fi…
Any suggestions? :slight_smile:

@Oliberserk your requirement is covered by Blynk’s standard push data example. The code extract you were looking at is specifically ONCE per connection using BLYNK_CONNECTED() function.

Available at https://github.com/blynkkk/blynk-library/blob/master/examples/GettingStarted/PushData/PushData.ino or from Examples if you are using the Arduino IDE.

Thanks! That did the trick!

Sir, I want if my ESP8266 is connected to blynk, it will follow Blenk server,s instraction. But if i disconnect the ESP8266, it wont give any output.

in real life, esc8266 continue giving last signal output that was received from Blynk server, although esp8266 is not connected to Blynk server or the WiFi.

BLYNK_CONNECTED() is a special callback function which is called once, each time the device connects or re-connects to the Blynk server.

If you wish to know if your device is currently connected to the Blynk server then you can use the Blynk.connected() command to test if your device is currently connected to the Blynk server, as I explained in your other topic here…

BLYNK_CONNECTED() and Blynk.connected() are different commands with different purposes.

As this is a 6 year old topic, and as you appear to want to have a discussion about the same subject in two different topics, I’m going to close this topic.

Pete.