Blynk_app_connected() / blynk_app_disconnected()

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,
Mark

Does this use Wi-Fi or Bluetooth?

Pete.

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.
  NOTE:
    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
BLYNK_APP_CONNECTED() {
  Serial.println("App Connected.");
}

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


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

void loop()
{
  Blynk.run();
}

@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:
```

Pete.

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.

Pete.

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!

Mark

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.
Mark

You can try this setting and see if it works…

Hello,
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 ?
Thanks

@gacaron That still works.

1 Like