06-11-2024 03:07 AM
I am trying to link a Quest 3 and an ESP32-WROOM devkit via Bluetooth Classic.
The ESP32 is running the following code:
#include "BluetoothSerial.h"
String device_name = "ESP32-BT-follower";
BluetoothSerial SerialBT;
// Bt_Status callback function
void Bt_Status(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
{
if( event == ESP_SPP_SRV_OPEN_EVT )
{
Serial.println ("Client Connected");
}
else if( event == ESP_SPP_CLOSE_EVT )
{
Serial.println ("Client Disconnected");
}
}
void setup()
{
Serial.begin(115200);
SerialBT.begin(device_name, isMaster = false, disableBLE = true); //Bluetooth device name
SerialBT.register_callback(Bt_Status);
Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str());
}
#define BT_BUF_LEN 255
char BT_buffer[BT_BUF_LEN];
int BT_data_index = 0; // Used in loop to keep track of how many elements have been read into buffer already
void loop()
{
if( SerialBT.available() )
{
int available_chars = SerialBT.available();
// SerialBT.available() helpfully tells us the number of transmissions in the buffer. We don't want to read more than that.
// Sometimes data is sent over multiple packages. In that scenario we keep pushing characters until we see a newline, at which point we start processing data.
for(int i = 0; i < available_chars; i++)
{
BT_buffer[BT_data_index] = (char) SerialBT.read();
if(BT_buffer[BT_data_index] == '\n')
{
BT_buffer[BT_data_index] = '\0';
BT_data_index = 0;
Serial.println(BT_buffer);
break;
}
BT_data_index++;
}
}
}
I am able to connect to this ESP32 with the SerialBluetooth app using my Android phone. Upon connecting with my phone the console prints "Client Connected" and I can send a string across that gets printed in the console as well.
However, when I try pairing the ESP32 with the Quest 3 the pairing is initially successful, but then 3 seconds later the Quest 3 unpairs itself. Further attempts at pairing the two are not acknowledged until the connection is "Forgotten" at which point it will again pair for only 3 seconds. The ESP32 never writes "Client Connected", even during the brief 3 second pairing.
Given that the pairing is successful from my phone I suspect that the issue is on the Quest 3's side rather than the ESP32's side. I have tried setting the ESP32 as either a leader or a follower via a flag on SeriaBT.begin but no change in behavior.
Anyone have any thoughts?
Solved! Go to Solution.
06-16-2024 12:21 AM
The ESP32 moving from the "Connected" to the "Not Connected" device list after pairing is normal for a SPP type connection.
My problem was that I was running the program via Meta Quest Link and had paired the EPS32 with the Quest 3 when I should have paired it with my PC.
06-13-2024 02:51 AM - edited 06-13-2024 07:03 AM
I wondered if it was perhaps the type of connection I was trying to instantiate. BluetoothSerial uses the Serial Port Profile. So I used the ESP32-A2DP library and lo-and-behold the Quest 3 no longer drops the connection after 3 seconds.
Is this intended behavior? Does the Quest 3 not support the Serial Port Profile? Is there a special trick to making the connection stick?
06-13-2024 07:43 AM
Another update: Experiments with the ESP-IDF (Espressif's IDE) and its bt_spp_acceptor example shows that
I (530247) SPP_ACCEPTOR_DEMO: ESP_BT_GAP_CFM_REQ_EVT Please compare the numeric value: 348874
I (532367) SPP_ACCEPTOR_DEMO: authentication success: Meta Quest 3 bda:[c0:dd:8a:82:a6:c7]
W (536407) BT_HCI: hci cmd send: disconnect: hdl 0x81, rsn:0x13
W (536497) BT_HCI: hcif disc complete: hdl 0x81, rsn 0x16
The Quest 3 is successfully authenticated, but then the connection is terminated with "rsn:0x13" which, according to the Bluetooth Core Spec means: "REMOTE USER TERMINATED CONNECTION" i.e. the Quest 3 is terminating the connection.
The Quest and the ESP32 are located right next to each other so signal integrity cannot be the issue. Anyone have any thoughts what might be causing this behavior?
06-16-2024 12:21 AM
The ESP32 moving from the "Connected" to the "Not Connected" device list after pairing is normal for a SPP type connection.
My problem was that I was running the program via Meta Quest Link and had paired the EPS32 with the Quest 3 when I should have paired it with my PC.