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

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:

In Bluetooth mode, you can use BLYNK_CONNECTED for this

1 Like

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

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

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 …

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
#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?

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

1 Like

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

Hi, I am very interested in this post
Have you managed to solve this problem? “Get port 5 low when a BT connection is not available”

Can you tell me how the best code is for that?

Thank🙏🏼