Blynk App Connected Event in NodeJS

Hello everyone,

I am working on a project using Raspberry Pi and the [blynk-library-js]. I noticed in the [documentation] there is a function BLYNK_APP_CONNECTED() in the Blynk C++ library, and I want to have that function in my program, too. I have been searching in the JS library, but seems like that function is not there. I also tried to replicate the function in C++ library, but I couldn’t due to missing definition of “InternalPinACON” and “InternalPinADIS”. Specifically:
In C++ library:
image

I tried to search through the whole library but I couldn’t find the definition of these 2 variables.
So I would like to ask you guys:

  1. Where are these variables defined ?
  2. How can I implement such a function in JS library ?

Thanks.

1 Like

I have also tried using the BLYNK_APP_CONNECTED() and BLYNK_APP_DISCONNECTED() functions in a setup where:
Hardware: Arduino + ESP8266 using AT commands

Sketch:

#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  This example shows how to use ESP8266 Shield (with AT commands)
  to connect your project to Blynk.

  WARNING!
    It's very tricky to get it working. Please read this article:
    http://help.blynk.cc/hardware-and-libraries/arduino/esp8266-with-at-firmware

  Change WiFi ssid, pass, and Blynk auth token to run :)
  Feel free to apply it to any other example. It's simple!
 *************************************************************/




#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

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

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

// Hardware Serial on Mega, Leonardo, Micro...
//#define EspSerial Serial1

// or Software Serial on Uno, Nano...
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(10, 11); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);

// LED
#define LED 13
//
BLYNK_APP_CONNECTED(){
  digitalWrite(LED,HIGH);
  Serial.println("App connected");
}

BLYNK_APP_DISCONNECTED(){
  digitalWrite(LED,LOW);
  Serial.println("App disconnected");
}

BLYNK_CONNECTED(){
  Blynk.syncAll();
}
void setup()
{
  // Debug console
  Serial.begin(9600);

  delay(10);
  pinMode(LED,OUTPUT);
  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
}

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

I am sure that I have turned on the settings " Notify devices when app connected" in my Blynk project. But these functions don’t work at all when I open/close the app.
Could anyone please help me on this issue ?

I suspect the NodeJS library just simply doesn’t have support for those commands. It seems more like a semi-official library by one of the developers that gets worked on in spare time.

Hello Gunner,

It’s ok if it doesn’t work on NodeJS. However, have you ever tried it on Arduino ? I tried it on the Arduino + ESP8266 setup I stated earlier, but it didn’t work.

These DO work with C++ code.

But you must have the switch turned on in the App.

And remember, they are activated when the APP is on (as in running on the phone or not) not the individual project.

It certainly works on a Wemos D1 Mini programmed in C++, provided you enable the “Notify devices when app connected” switch for your project (if you have multiple projects then it needs to be enabled for the project that contains a device with the Auth code that you’re using in your sketch).

Tested using:
iOS 2.25.0 (3) and 2.26.0 (7) - Beta
Blynk Cloud server
Blynk library 0.6.1

If you have multiple devices signed-in to your account then you get a notification when the app is closed on any device.
So if you have two devices and close the app on device 1 then device 2, you’ll get two “App Disconnected” notifications one after another. Re-launching the app on one device will give you an “App Connected” message, but you aren’t able to distinguish which device has connected.

Pete.

I am also looking for such a function in the blynk node.js library to return the status of the blynk connection to the cloud. How can we have the functionality of the Arduino’s “Blynk.connected()” function in the node.js library?

Will we ever get an “official” version of the library for node.js, especially the inclusion of the “Blynk.connected()” function?

Although it’s not exactly the same, you could use blynk.on(‘connect’…) and ‘disconnect’ to set a Boolean variable that works in the same way as Blynk.connected

blynk.on('connect', function() {
  // set your variable to true in here
});

Pete.

Pete, you are right and I’ve done that as well. However, from my tests, it seems that the system (blynk?) takes some time, ~10 minutes before the disconnect function was called i.e. it was not triggered immediately when there was a break in the connection to the blynk cloud server.