Hi all. I’m returning to Blynk after a few years, this time with ESP32. I have an Android and an iPad running the updated Blynk apps, using Arduino IDE.
I am finding that neither BLYNK_APP_CONNECTED(), BLYNK_APP_DISCONNECTED() are working.
I can freely read and write to the Blynk mobile app widgets - no problem.
I cannot detect if the mobile Blynk apps are connected or not using the BLYNK_APP_CONNECTED(), BLYNK_APP_DISCONNECTED() code.
I did see the similar post and resolution from a while back, but I’m still stuck, even with updated apps.
Is this my bad ? A returning newbie error?
Thanks all.
#ifndef ESP32
#error This code is intended to run on the ESP32 platform! Please check your Tools->Board setting.
#endif
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
char auth[] = "myAuthCode";
char ssid[] = "mySSID";
char pass[] = "myKeyCode";
int pushToPhoneTimerID; //for changing the interval for the Push-To-Phone timer
const long int slowTimer = 5000L; // 5 seconds when no app connected
// Ambient Brightness from phone or device on V7
int phoneBrightness;
// insideBrightness controlled by app sliders
int insideBrightness;
bool appConnected = false;
BlynkTimer pushToPhoneTimer;
void setup()
{
Serial.begin ( 115200 );
Serial.println ( "STARTING Blynk_Working_Test_ESP32 ANDROID.\n\n" );
Blynk.begin ( auth, ssid, pass );
Serial.println ( "Blynk begin completed.\n" );
// Setup a function to be called every second
pushToPhoneTimerID = pushToPhoneTimer.setInterval ( slowTimer, myUptimeCounter );
Serial.println ( "Setup complete.\n" );
}
void loop()
{
Blynk.run();
pushToPhoneTimer.run(); // Keeps uptime timer up to date
}
// Inside Brightness 0-1023 on V10
BLYNK_WRITE(V10) // Called when APP makes a change
{
insideBrightness = param.asInt(); // assigning incoming value from pin V1 to a variable
Serial.print ( F ( "V10 Slider changed to: " ) );
Serial.println ( insideBrightness );
}
// Ambient Brightness from phone or device on V7
/* (seen as high at 4000+ from Android); not implemented on iPad */
BLYNK_WRITE(V7) // Called when APP makes a change
{
phoneBrightness = param.asInt(); // assigning incoming value from pin V1 to a variable
Serial.print ("V7 Phone Lux value is: ");
Serial.println ( phoneBrightness );
}
// This is called when Smartphone App is opened
BLYNK_APP_CONNECTED()
{
Serial.println ( F ( "\n\nApp connected..." ) );
appConnected = true;
}
// This is called when Smartphone App is closed
BLYNK_APP_DISCONNECTED()
{
Serial.println ( F ( "\nApp Disconnecting.... " ) );
appConnected = false;
}
/* myUptimeCounter() */
void myUptimeCounter()
{
long int countup = millis() / 1000;
Blynk.virtualWrite ( V5, countup );
Serial.print ( F ( " " ) );
Serial.print ( F ( "V5 timer... " ) ); Serial.print ( countup );
if ( appConnected ) Serial.println ( "... connected." );
else Serial.println ( "... DISconnected." );
}