Skip to content

Can registerForNotify() fail? #1032

@CLDiego

Description

@CLDiego

Hi I'm trying to develop a BLE + WiFi (MQTT) application, and I'm having a bit of trouble with notifications/indications at the moment.

What my code does is to scan for my BLE servers (RN4871 modules), create a list of the available servers, send such list to an MQTT broker and then the user sends back a command to connect to a specific BLE server. Once connected the esp32 client looks at the services, gets a specific server, gets its characteristics, gets its descriptor, registers for indications from the BLE server, gathers the data and sends it back to the MQTT broker. This process is repeated every 2 minutes.

My idea is to let these devices connected at all times, the problem comes when at some point the esp32 will find the device, the service, the characteristic and register for indications but then the callback is never called.... I've been only able to run the whole thing for 1-2 hours non-stop until this error happens.

I'm using platformio at the moment with the arduino-esp32 framework (I'm assuming it's pulling the latest stable release of this package), and I've looked at most of the similar issues in this repo and in the https://github.com/espressif/arduino-esp32 repo.

I learned a lot on how to enhance my code to avoid some memory leaks that I had, but I've trying to solve this issue without stopping for at least two weeks, and still haven't got anywhere. At the moment is hard for me to debug as for some reason the verbose mode crashes the esp32.

I've noticed that the sometimes depending on my setInterval and setWindow values for the scan, the program can work without stopping for 3 hours (but it might be my imagination).

I've also got to the point of restarting all of my devices once I gather the data just to be sure that they always start fresh. In the esp32 I unregister from the notifications using registerForNotify(nullptr), then I disconnect, I call BLEDevice::deinit() and kill my BLE task, and then force the watchdog timer to restart the esp32. I've also tried deleting the pClient but it often causes a heap error.

Does anyone can give me an idea of what to try next? Is there a reason for the registerForNotify() method to fail?

I'm happy to share some code (I just need to tidy it up).

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