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:
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:
Where are these variables defined ?
How can I implement such a function in JS library ?
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.
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.
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.
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?
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, 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.