BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

[SOLVED] Can ESP32 BT mode use "BLYNK_APP_CONNECTED ()"?

#1

Hi!
How can I receive a notification on hardware every time the bluetooth device connects to it?
Can ESP32 BT mode use “BLYNK_APP_CONNECTED ()” in preliminary tests did not work.
Thanks for all the help!

Ps:Sorry… I do not speak English … Write even more rsrsrs :smile:

edit1:

void BlynkTransportEsp32_BT::onConnect() {
  BLYNK_LOG1(BLYNK_F("BT connect"));
  Blynk.startSession();
};

void BlynkTransportEsp32_BT::onDisconnect() {
  BLYNK_LOG1(BLYNK_F("BT disconnect"));
  Blynk.disconnect();
}

These lines of code (218-226) inside the “BlynkSimpleEsp32_BT_h” library seem to work exactly as I need them. But I do not know how to extract functionally. :confused:

0 Likes

Requesting the state of a PB widget from code on the controller
#2

In Bluetooth mode, you can use BLYNK_CONNECTED for this

1 Like

#3

OK! This worked well.
Now how to detect when the App is closed?
Is there a way to do this?

0 Likes

#4

With a BT/BLE, the App IS the connection… no App, no connection and probably nothing running on the device… not sure if WiFi style “keeps running without server” routines count with BT/BLE… But even if the sketch is still running, without the App there is no way any “Is app connected” message from the Server to get through :stuck_out_tongue_winking_eye:

1 Like

#5

I understood partially
When I disconnect the bluetooth I receive the msg “BT disconnected” in the serial. In theory I need to identify if a BT connection is stable, I do not necessarily need to check if the app is connected. Example: I move away from the device and certain function checks if BT connection is present, otherwise it does something …

0 Likes

#6

That is what this meant… since the App is the connection between the device and the Server (via BT/BLE) if there is no BT/BLE connection, there is no Server connection.

1 Like

#7
#include <Arduino.h>
#define BLYNK_USE_DIRECT_CONNECT
#define BLYNK_NO_BUILTIN
#include <BlynkSimpleEsp32_BT.h>

char auth[] = "*****************************";

BLYNK_CONNECTED() {
digitalWrite(5, HIGH);
}

void setup() {
  Blynk.setDeviceName("GPA-v3.1BT");
  Blynk.begin(auth);
  pinMode(5, OUTPUT);
}

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

This is a piece of my code … it works. Now what do I need to do to get port 5 low when a BT connection is not available?

0 Likes

#8

It is all in the documentation… Try using the command of the same name (lower case), not the function (UPPER CASE).

1 Like

#9

In a first attempt I did not succeed. I must have done something wrong.
This time worked well.
I do not know if this is the best way to do it, but it works.
Thank you!

#include <Arduino.h>
#define BLYNK_USE_DIRECT_CONNECT
#define BLYNK_NO_BUILTIN
#include <BlynkSimpleEsp32_BT.h>
#include <Ticker.h>

char auth[] = "********************************";

Ticker ticker;

void setup() {
  Blynk.setDeviceName("GPA-v3.1BT");
  Blynk.begin(auth);
  pinMode(4, OUTPUT);
  ticker.attach(0.5, App_Detect);
}

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

void App_Detect() {
  digitalWrite(4, Blynk.connected());
}
1 Like