ArdduinoBLE Event Call Back Functions

I had posted a different thread with a slightly different question regarding the setEventhandler functions.

I have seen example code for the setEventHandler function for events in the BLE Class ( usage is BLE.setEventHandler(eventType, callback) ) for the event types of BLEConnected & BLEDisconnected that call a routine for each of these event types.

There is another setEventHandler function for the Characteristic Class ( usage is bleCharacteristic.setEventHandler(eventType, callback) ) for the event types of BLESubscribed, BLEUnsubscribed, BLERead, & BLEWritten that again call a routine for each of these events when a characteristic is intreated on.

I have, with success, used the BLEWritten event type. Has anyone used any of the remaining event types successfully as I seem to be having trouble with the BLERead event type?

Could you please provide a complete example that shows what works and what does not? Preferably something that does not need any external sensors and works with a bare Arduino.

Klaus

I have not had the time to trim down my large chunk of code to the basic example required. My Server also requires a FTMS Client to interact with.

This is what I have found out so far

Characteristics can be configured with many attributes but I am dealing with an attribute that I used to notify changes to the Peripheral as well as being Written to by the Peripheral. The FTMS Specification indicates that there is a Handle Value Verification used which I figured out uses the Indicate attribute on the Characteristic rather than the Notify attribute. Indicate steps up the Notify protocol to include a final Read Verification for the Peripheral back to the Server (Server Notifies the Peripheral of a change in the value and Peripheral acknowledges that the Change was received).

There are four main event handlers for Characteristics (BLERead, BLEWritten, BLESubscribed, BLEUnsubscribed) and I have confirmed all of them functioning EXCEPT BLERead.
The Unsubscribed and Subscribed execute a subroutine (using the setEventHandler function) when the Peripheral Subscribes to or Unsubscribes from the Characteristic - These I have confirmed working.
The BLEWritten executes a subroutine when the Peripheral changes the value of a Characteristic in the Server - This has always worked.
BLERead - this is an assumption - should tell me when the Peripheral actually reads a value from a Characteristic. I am also assuming in the case of Indicate that this would provide confirmation that the Peripheral did receive the Notification of the the change of value and that it Acknowledged this back to the Server - I have not been able to get this working.

I have also found that to get Notification and Indications working on a Characteristic one should add a Description to the Characteristic using UUID 2902. This is different than the UUID 2901 Description that simply adds a text descriptor to the Characteristic.
When you see the 2902 parameter (under a Characteristic) on a mobile device it indicates (i am using nRF Nordic) that Notifications and Indications are Disabled. There seems to be no way to enable this in the Arduino code but I have noticed that when the Peripheral Subscribes to the Characteristic that this does then Change to the state of Notification and Indications are Enabled.

Having done all of this I still have not been able to see the BLERead subroutine called when the Indication is Acknowledged (I do not actually know that this Acknowledge is happening).

For now I have simply resorted to the status of the writeValue of the characteristic to assume that if this is good then the Peripheral has received the Write that I have done (via Indicate) and that it has Acknowledged this). I do not like to make this assumption but I see know other way at the moment.

This code is in a routine that is called in Loop when a value has changed and needs to be updated and this little snippet is clearing the value changed flag if the write was successful.

bool goodwrite = trngStatusChar.writeValue(trngStatusCharsData, trainStatusLength);
if(goodwrite) {
trainStatusChanged = false;
}

The FTMP document says the following (below)- I believe I have done this but would like to confirm this functionality - Is there a way?

4.4.14 Fitness Machine Control Point
Before it performs a Fitness Machine Control Point procedure, the Collector shall configure the Fitness Machine Control Point characteristic for indications (i.e., via the Client Characteristic Configuration descriptor).

If you look at the FTMS document or the UDS documents on the Bluetooth Website you will see charts in the last pages of these documents that show how the Control Point Characteristics are interacted with and the Handle Value Confirmation are required. In the case of the User Data Service and the UserDescription Characteristic the List All Users requires the Server to list all user names (chopped into small 22 byte chucks) with the only control being the Handle Value Verification that the Peripheral acknowledged the read of the last chunk I sent.

Thanks and Regards

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.