Some questions on BLE custom service example

Context: RAK-4631/RUI3 BLE Custom Service example

I’m trying to run @beegee 's example code and have hit a few questions.

1/ Is there no way to set the Device UUID? How is it generated? The reason I ask is that I’d like to be able to filter the list of advertised devices (to contain just my RAK 4631 devices) prior to making the connection, but if they are randomly assigned then I can’t filter on device UUID.

2/ The BLE_CONNECT and BLE_DISCONNECT event callbacks don’t appear to work. I’ve used them in previous BLE UART serial tests successfully. All I do is turn the BLUE_LED on or off so they’re not complicated handlers. I added the Serial text just in case.

void cbConnected( void ) {
    Serial.println("BLE Connected");
    digitalWrite(BLUE_LED, 1);
}

void cbDisconnected( void ) {
    Serial.println("BLE Disconnected");
    digitalWrite(BLUE_LED, 0);
}

...
    pinMode(BLUE_LED, OUTPUT);
...
    api.ble.registerCallback (BLE_CONNECTED, cbConnected );
    api.ble.registerCallback (BLE_DISCONNECTED, cbDisconnected );

3/ When I connect to the RAK 4631 device and then click to enable notify for the Heart Rate Measurement (HRM) Service, the serial terminal shows the println output expected from cccd_callback, and then it crashes.

The “still going yeah” line is generated in the main loop:

void loop()
{
    Serial.println("still going yeah");
    delay(1000);
}

Notice that it manages just one more output after the cccd_callback generated text.


The “central” that I’m using is my iPhone. I have tried several Apps and they all produce this same behavior.

nRF Toolbox looking for the heart rate service (HRS) successfully filters to show only the 4631 service. (If, for example, I look for blood pressure monitoring, it doesn’t list any service, but it finds the HRS just fine). However, as soon as I click connect, nRF Toolbox reports that it can’t parse the data. While this is a problem, it’s not as big a problem as the peripheral side (ie the 4631) crashing, with follow up downloads locked out until a hard reset.

The other two Apps I have used are Renasys’s GATT Browser and BluetoothDemo by Itsuki. All three Apps generate the same peripheral behaviour. These last two allow more control over the connection. The crash happens when Notify is enabled.

ie Both Renesys and Itsuki apps can issue a read of the sensor location (ID:2A38) that triggers the “send_callback” text and data (0x02). Most importantly, the read action does not crash the BLE demo code.


It’s always possible that I’m missing something, but I’ve tried to isolate the issues as best I can.

BLE_Custom_UART_Service.ino (7.2 KB)

I’ve created a sketch that mashes together the BLE_UART example and the BLE_Custom_Services example, in an effort to play the “salami game” between something that works and something that doesn’t.

There is something wrong with the way that callbacks are triggered under the ble.custom framework. The connect and disconnect callbacks are not triggered at all and cccd_callback is triggered but crashes the overall program on exiting the handler.

I’ve started to dig deeper down into the RUI3 code, but for the BLE functionality it seems to be a thin wrapper of the Nordic services. I could keep digging, but might just end up in a deeper hole! Has anyone managed to get the BLE custom service callbacks working properly?

(I’m looking at you @beegee)

I will be not much of help here. I barely use BLE and if, then just BLE UART.

Thanks @beegee for chiming in.

My intended data packet is quaternion attitudes - setpoints one way and measurements the other. This should be a good use case for custom BLE, but I’m at the point now where I think I’ll just layer the data over the top of the UART stream and then move on to the next problem.