I have a question and I hope you can help me with that. I´m working with an Adafruit nRF52 Feather.
I´m developing a small Bluetooth Low Energy application and as basic I use the following code for Arduino:
I would like to know the connection state of my device. If a smartphone is connected to it via BLE or not. For this, in the linked code are two functions (I hope this is for that):
And of course, this function must exist in your sketch as it exits in the example:
// callback invoked when central connects
void connect_callback(uint16_t conn_handle)
{ // Get the reference to current connection
BLEConnection* connection = Bluefruit.Connection(conn_handle);
char central_name[32] = { 0 };
connection->getPeerName(central_name, sizeof(central_name));
Serial.print("Connected to ");
Serial.println(central_name);
}
If you want to know if you are connected set a flag in this function.
connect_callback is a function pointer, it contains the address of the function therefore it is always not 0 if the function exits in your sketch.
Best Regards,
Johi.