Forum: Mikrocontroller und Digitale Elektronik ESP32-C3 BLE HID Device Not Visible on Mobile


von Martin L. (tempusertempuser)


Lesenswert?

Hello everyone,

I’m working on a BLE HID project with an ESP32-C3 using the 
NimBLE-Arduino library. The goal is to make the ESP32 act as a BLE media 
remote (sending Play/Pause commands).

The code compiles and runs without errors in PlatformIO, but here’s the 
problem:

On my Android phone (Samsung A32), I cannot see the ESP32 device in the 
Bluetooth list.

I am advertising the HID service properly:
1
pAdvertising->addServiceUUID(hid->getHidService()->getUUID());
2
pAdvertising->start();


I’m using a minimal HID report map for Play/Pause.

Here is my code
1
#include <NimBLEDevice.h>
2
#include <NimBLEHIDDevice.h>
3
#include <HIDTypes.h>
4
5
NimBLEHIDDevice* hid;
6
BLECharacteristic* input;
7
bool sent = false;
8
9
void setup() {
10
    Serial.begin(115200);
11
    NimBLEDevice::init("ESP32-C3 Media Remote");
12
13
    NimBLEServer* pServer = NimBLEDevice::createServer();
14
    hid = new NimBLEHIDDevice(pServer);
15
16
    input = hid->getInputReport(1);
17
18
    hid->setManufacturer("MyManufacturer");
19
    hid->setPnp(0x02, 0xe502, 0xa111, 0x0210);
20
    hid->setHidInfo(0x00, 0x01);
21
22
    hid->setReportMap((uint8_t*)reportMap, sizeof(reportMap));
23
    hid->startServices();
24
25
    NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising();
26
    pAdvertising->setAppearance(HID_KEYBOARD);
27
    pAdvertising->addServiceUUID(hid->getHidService()->getUUID());
28
    pAdvertising->start();
29
30
    Serial.println("BLE Media Remote ready!");
31
}
32
33
void loop() {
34
    if (!sent && NimBLEDevice::getServer()->getConnectedCount() > 0) {
35
        Serial.println("Sending Play/Pause...");
36
37
        uint8_t press[1] = {0x01};   // press Play/Pause
38
        input->setValue(press, sizeof(press));
39
        input->notify();
40
        delay(100);
41
42
        uint8_t release[1] = {0x00}; // release key
43
        input->setValue(release, sizeof(release));
44
        input->notify();
45
46
        sent = true;
47
    }
48
}


I’ve tried:

Restarting the phone and ESP32

Using different BLE scanning apps like nRF Connect

Checking that the ESP32 is powered and advertising

But my phone still doesn’t detect it.

Questions:

Are there any specific settings required to make an ESP32-C3 BLE HID 
visible to mobile devices?

Could this be a compatibility issue with certain phones?

Any tips for debugging BLE advertising issues on ESP32-C3?

Thanks in advance for any guidance!

von Alexander (alecxs)


Lesenswert?

Martin L. schrieb:
> Could this be a compatibility issue with certain phones?

Yes, but more likely with ancient phones. Samsung Galaxy A32 supports 
BLE 5.0

: Bearbeitet durch User
von Alexander (alecxs)


Lesenswert?

It's unclear what IDE you're using. The code looks like Arduino. Did you 
manage to run PlatformIO on Arduino Core, pioarduino?

Martin L. schrieb:
> The code compiles and runs without errors in PlatformIO, but

Martin L. schrieb:
> using the NimBLE-Arduino library.

https://github.com/platformio/platform-espressif32/issues/1225#issuecomment-3044662953

h2zero NimBLE-Arduino README.md states:
> Note for ESP-IDF users: This repo will not compile correctly in ESP-IDF.
> An ESP-IDF component version of this library can be found here.
>
> https://github.com/h2zero/esp-nimble-cpp

: Bearbeitet durch User
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.