How to use a Bluetooth remote control to send commands to an ESP32

Hello,

I am looking to build a foil assist to take off earlier when wingfoiling. Something similar to the ‘Stoke Foil Boost’ but cheaper.

I would like to order an ESP32 with a QXS-001 Bluetooth remote control purchased on Amazon.

I created code.

What this code does:

  • Bluetooth scan (ignores all devices except QXS-001)

  • Connection (uses SPP (Serial Port Profile))

  • Data reception (everything sent by QXS-001 is displayed on the serial monitor)

My problem is that when I press the buttons, no data is displayed on the serial monitor.

#include <BluetoothSerial.h>

BluetoothSerial SerialBT;

#define TARGET_NAME "QXS-001"
#define BT_DISCOVER_TIME 10000

BTAddress targetAddress;
int targetChannel = -1;
bool deviceFound = false;

void setup() {
  Serial.begin(115200);

  if (!SerialBT.begin("ESP32_Client", true)) {
    Serial.println("Bluetooth init failed");
    abort();
  }

  Serial.println("Scanning for Bluetooth devices...");

  BTScanResults *results = SerialBT.getScanResults();

  SerialBT.discoverAsync([](BTAdvertisedDevice *device) {
    Serial.printf(
      "Found device: %s\n",
      device->toString().c_str()
    );

    if (device->getName() == TARGET_NAME) {
      Serial.println(">>> TARGET DEVICE FOUND!");
      targetAddress = device->getAddress();
      deviceFound = true;
    }
  });

  delay(BT_DISCOVER_TIME);
  SerialBT.discoverAsyncStop();

  if (!deviceFound) {
    Serial.println("Target device not found");
    return;
  }

  Serial.println("Scanning for SPP channels...");
  auto channels = SerialBT.getChannels(targetAddress);

  if (channels.empty()) {
    Serial.println("No SPP channel found");
    return;
  }

  targetChannel = channels.begin()->first;

  Serial.printf(
    "Connecting to %s on channel %d...\n",
    targetAddress.toString().c_str(),
    targetChannel
  );

  if (!SerialBT.connect(
        targetAddress,
        targetChannel,
        ESP_SPP_SEC_NONE,
        ESP_SPP_ROLE_MASTER)) {
    Serial.println("Connection failed");
    return;
  }

  Serial.println("Connected successfully!");
}

void loop() {
  if (SerialBT.connected()) {
    while (SerialBT.available()) {
      char c = SerialBT.read();
      Serial.print(c);   
    }
  } else {
    Serial.println("Disconnected");
    delay(1000);
  }
}

Serial Monitor

Scanning for Bluetooth devices...
Found device: Name: QXS-001, Address: 10:fa:c2:67:0b:a9, cod: 0x002540, rssi: -59
>>> TARGET DEVICE FOUND!
Scanning for SPP channels...
Connecting to 10:fa:c2:67:0b:a9 on channel 1...
Connected successfully!

This is likely a BLE 5.x device, not using an SPP profile with classical Bluetooth. On your ESP32, you would need to use the BLE APIs to connect as a GATT client and subscribe to the appropriate characteristics to detect button presses and control events. BluetoothSerial and SPP will not capture these inputs.

I tested BLE mode. But in this mode, the ESP32 does not detect the QXS-001.

When I use this programme, the QXS-001 is detected.

Exactly which ESP32 board do you have ?

What code did you use for BLE?

Do you have a link to the doc of this product ? what I've seen (an amazon listing) is that it's a 5.3 BLE device. So you won't get anything through classic BT and an SPP profile.

it's more likely an BLE HID with Consumer Control reports

If you use Kai Morich's App Serial Bluetooth Terminal App on an Android phone does it see the device as Bluetooth Classic or Bluetooth LE? Can it connect to what it finds?

https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=en_US

Yes, I read the instructions. It is indeed Bluetooth 5.3.

Why, when I run the programme: file/example/BLE/Scan,

does the programme not detect any BLE products?

I download this app.
QXS-001 isn't detected.

The QXS-001 device is detected by my iPhone and my computer.

However, the device is not detected by my Honor 9 (Android).

Try using nRF Connect app from Nordic Semiconductor.

This app lets you inspect the exact BLE services and characteristics exposed by the device and monitor its response to button presses.
As @J-M-L suggested, I also believe this is a BLE HID (Human Interface Device), which means your ESP32 must act as a BLE HID host.

You should be able to see the HID Service with UUID 0x1812.

Hello

  • I have already tested this application, as well as many others: ‘Light Blue’, ‘BLE Scanner’, ‘Find Devices’.

Nrf connect, like the other applications, does not detect my product.

  • I reread the instructions; it is Bluetooth 5.3.

  • What is strange about your HID hypothesis is that with the ESP32, I was able to connect using standard Bluetooth.

With the code from my first message, I have this in the serial monitor.

"Scanning for Bluetooth devices...

Found device: Name: QXS-001, Address: 10:fa:c2:67:0b:a9, cod: 0x002540, rssi: -56

TARGET DEVICE FOUND!

Scanning for SPP channels...

Connecting to 10:fa:c2:67:0b:a9 on channel 1...

Connected successfully!"

I think the problem comes from these lines of code:

while (SerialBT.available()) {
      char c = SerialBT.read();
      Serial.print(c); 

This following line work

if (SerialBT.connected()) {

Classic Bluetooth inquiry and BLE advertising are handled at the controller level. It’s possible that some devices respond to inquiry indirectly or expose a generic or legacy Class of Device that makes them visible during Classic scans even though they do not implement any Classic services. Visibility does not imply protocol compatibility.

SerialBT.getChannels returning channel 1 and connect succeeding only means that an RFCOMM channel was accepted at the link layer. It does not guarantee that the remote implements an SPP data service behind that channel. Many HID remotes accept an RFCOMM connection but never send payload data on it.

The decisive test is data flow. If pressing buttons produces no bytes on SerialBT.available(), then SPP is effectively nonfunctional for input, even though the connection reports success.

Okay, thank you.

It's clearer in my mind now.

What could be causing the apps to not detect my product?

Nrf Connect detects another BLE device (AB Shutter 3).

When i test the code File/Example/BLE/Scan, Serial monitor send back :

Scanning...
Advertised Device: Name: , Address: 6e:96:5c:06:46:af, serviceUUID: 0000180a-0000-1000-8000-00805f9b34fb, serviceUUID: 00006cfc-0000-1000-8000-00805f9b34fb, serviceUUID: 0000a703-0000-1000-8000-00805f9b34fb, serviceUUID: 005eb7ca-86c5-4383-84bc-2cf875b73dbf, rssi: -44 
Advertised Device: Name: AB Shutter3, Address: 11:22:33:44:55:d3, appearance: 961, serviceUUID: 00001812-0000-1000-8000-00805f9b34fb, rssi: -71 
Advertised Device: Name: , Address: 0f:f3:00:d6:ec:47, manufacturer data: 0600010f2022ae495a6cd194d407a9846da54901f51db2793ddd034be3, rssi: -73 
Advertised Device: Name: , Address: 76:31:b8:5a:11:f6, manufacturer data: 4c001005371c3838a8, txPower: 12, rssi: -83 
Devices found: 4
Scan done!

ESP32 detect AB Shuter3 but don't detect QXS-001 like Nrf Connect

What’s that ?

It's another BLE button. However, it doesn't work for my project. It's not waterproof.

If the unit is not detected then it’s not a good sign…

(post deleted by author)

I think I'll return the device and buy another one.