Quest 3 disconnects from classical Bluetooth with ESP32 after 3 seconds
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?
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.