Blynk_app_connected() / blynk_app_disconnected()

It may very well be that I don’t understand the purpose these two functions. I took them to mean that they would fire if the App on my phone connects / disconnects with the Blynk server. But, nothing I do makes them fire – even turning the phone off then on again. Am I misunderstanding the purpose of these functions?

Below is a simple code I tried to test this. All works as expected except for BLYNK_APP_CONNECTED() / BLYNK_APP_DISCONNECTED().

Thanks if advance for your help.

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

#define mySSID "MY_SSID"
#define WAIT_FOR_WIFI 10000

char auth[] = "MY_BLYNK_AUTH";
void initWiFi(void);

void setup()
  Serial.println(F("Back From Blynk.config"));

void loop()

BLYNK_WRITE(V0) //Button Widget is writing to pin V1
  if (param.asInt() == 1) {
    Serial.println("Button Pressed");
  } else {
    Serial.println("Button Released");

  Serial.println("Connected to Blynk Server");

  Serial.println("Blynk App Connected");

  Serial.println("Blynk App Disconnected");

void initWiFi() {
  uint32_t startTime;
  wl_status_t wifiStatus;
  do {
    startTime = millis();
    Serial.println(F("Starting WiFi Connection"));
    WiFi.begin(mySSID, PASS);
    while ((wifiStatus = WiFi.status()) != WL_CONNECTED) { // Wait for connection
      Serial.print(" ");
      if (millis() - startTime >= WAIT_FOR_WIFI) {
  } while (wifiStatus != WL_CONNECTED);
  Serial.print(F("WiFi Status = "));
  Serial.print(F("SSID: "));
  Serial.println(F("IP Address: "));

I can’t recall when this came out, but if your installed App version is older, then they will have no effect.

But if you are running current App version, then make sure you have activated the “NOTIFY DEVICES WHEN APP CONNECTED”… I think it is required.

1 Like

Hello. You need also to enable this feature within your project settings.

Got it, works now. Thanks!!!

I notice that the functions fire when starting / stopping app on my phone, but not when hitting the Stop (Square) and Run (Triangle) symbols in the app. Is that by design?

Stopping a Project is not stopping (disabling) the App, as the App is still running (as are any other running projects), just not that particular project that you stopped.

Now, when closing the App (as in having moved on to something else in your phone) it is still “running”, but in background, and might also be considered as still “enabled”, thus no notification to the MCU… but I haven’t tested that.

Understood. Thanks for the quick reply.

Hi, I cannot get the Blynk_app_connected nor disconnected function to fire.
I have a sketch on ESP8266 identical to the one in the user guide except the the wifi libs are added as the per the example at the top of this thread.

I enabled the Notify Devices When App Connected of course.
I have tried IOS and Android Blynk App - no difference.
My Token is correct - since I can connect from the Blynk app to the ESP.

I have stopped and started the blynk app in numerous ways including the play button and killing the app.

What is the trick to getting this to work??
It is critical to my Blynk usage since there is no other way for my Robot drive to know when the Blynk App Joystick has been disconnected and to stop using the velocity values - rather than take out the nearest obstacle.
Thanks again,

Does this use Wi-Fi or Bluetooth?


Hi Pete. Wifi.

Here is my test sketch…

  This example code is in public domain.
  This sketch shows how to handle App connected/disconnected events.
    Be sure to enable "send app connect command"
    in your Project Settings!

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#include <SPI.h>
//#include <BlynkSimpleEthernet.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxx";

// Your WiFi credentials.
char ssid[] = "xxxxxxx";
char pass[] = "xxxxxxx";

// This is called when Smartphone App is opened
  Serial.println("App Connected.");

// This is called when Smartphone App is closed
  Serial.println("App Disconnected.");

void setup()
  // Debug console
Blynk.begin(auth, ssid, pass);
  // Blynk.begin(auth);
//  Blynk.config(auth);
//  Blynk.connect();

void loop()

@Mark_Hamester please edit the post where you posted your sketch and use triple backticks at the beginning and end of your code rather than the characters that you have used.
Triple backticks look like this:


Ok done that thanks Pete

It’s been noted in the comments above that this does NOT cause the BLYNK_APP_DISCONNECTED() callback to fire.

How many devices do you have logged-in to your the Blynk account when you are doing these tests? If you have the app running on multiple devices, including your Wife’s phone and that old tablet that you only really use for facebook, then I think they ALL need to have the Blynk app stopped at the same time for the app to be in the disconnected state.


Hi Pete, I did what you suggested, logged out of all known devices. I still do not get a connected or disconnected event on the ESP - either using the test sketch or my Robot drive sketch.

Works well from the other end, ie the Blynk app reliably and quickly provides a “app-name connected” and “app-name disconnected” message - at least when using IOS.

Its a shame as we will not be able to use this platform for this application.
But thanks for your help!


Hey Pete, good news. I found my problem. I was running an old ES8266 core. Updated to the latest and its works well. Thanks again for helping me with this.

When I start or close the blynk App the esp gets a notification within secs.
If I disconnect the internet connection from the device running the blynk app I get a disconnected message about 30-40 secs later. Would be nice if this interval could be made shorter, but at least now I have way to track state end to end for my real time control.

You can try this setting and see if it works…

I am having issues with the BLYNK_APP_CONNECTED and DISCONNECTED events.
I know in legacy it used to be a setting to be enabled called “NOTIFY DEVICES WHEN APP CONNECTED” under project settings.
But my company is transitioning to Blynk 2.0, and I am trying to get this event to be invoked with the new app.
How do I enable this event callback with Blynk 2.0?
Please it’s kind of urgent, I need an answer A.S.A.P…

Regards Dominick.

@Dominick_Nicolosi Not supported in Blynk 2.0.

That’s unfortunately, on the legacy I was using the “READING RATE” to 1 second from the app widget to update the widget with fresh data. While redoing the app template, I noticed that option is not longer available, so I thought to use the app connected and disconnected events to start and kill a task that ticks every second to update the app when necessary.
Unfortunately I am learning that there is no longer a way for me to see in my firmware if a user needs the data or not to try and be as efficient as possible with the customer’s networks and metered connections.
As this API used HTTPS, I really hate to sent unnecessary POST/GET request to update datastreams that nobody is looking at, especially because we don’t care about historical logging on the server, it’s just to provide our customer with real time view the system state.

So please, I changing the firmware for periodically update as long as WiFi is connected for now, as it sound like I have no choice, but reconsider adding a way in firmware to know if a user is connected via mobile app. or web portal please, it was a very useful feature.

Thanks :slight_smile:

Regards Dominick

1 Like

And what about BLYNK_CONNECTED very useful at first connection ?