Skip to content

BLE registerForNotify not working (with workaround) #628

@petereverett

Description

@petereverett

Hi

I'm using v0.4.16 of the ESP32 BLE Arduino Library.
I have created a BLE server on an ESP32 board with 2 characteristics based on the BLE_notify example. This works as expected with the nRF Connect app on my phone: I can read values and get notifications.

I have created a BLE client on a second ESP32 board based on the BLE_client example, to connect to the server, register for notifications and output the value (on LEDs). This connects to the server and reads the initial value correctly. However this line does not work:
pRemoteCharacteristic->registerForNotify(notifyCallback);
I don't get an error, it just doesn't receive any notifications.

If I do the following, everything works fine:

const uint8_t notifyOn[] = {0x1, 0x0};
pRemoteCharacteristic->getDescriptor(BLEUUID((uint16_t)0x2902))->writeValue((uint8_t*)notifyOn, 2, true);
pRemoteCharacteristic->registerForNotify(notifyCallback);

The following code does not work either:

const uint8_t notifyOn[] = {0x1, 0x0};
pRemoteCharacteristic->getDescriptor(BLEUUID((uint16_t)0x2902))->writeValue((uint8_t*)notifyOn, 2, true);

Is 'registerForNotify()' supposed to work when called without also writing to the descriptor manually?

If I first connect with the nRF Connect app, register for notifications, disconnect and reboot the client board, 'registerForNotify()' on its own works fine and receives the notifications. Simply connecting and disconnecting in nRF Connect didn't make it work, I had to register for the notifications.

I think there is something wrong with the server side of things, because I built a seperate project last week to display the output from a Speed/Cadence sensor, and only used 'registerForNotify()', and it works great.

I've attached the server code as a text file - can't upload an ino file.
BLE_server.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions