I am implementing a BLE device which stores some log data based on sensor data and a iOS app which acts a Central to access the data.
I know how to read GATT characteristics data, but I wonder how to read a bunch of from the device. Is there standardized way to do this?
My naive approach would be the following:
To get the log data I would have to read the number of records (A), then do a loop and write an index to (B) and read the data (C).
Is this the way to go or is there a better approach?
My log data records would contain a timestamp and a 8 bit value with sensor data.
This is a good way and it would work, but if you will always read all the records, then it is inefficient to be doing multiple writes from the central (in a loop). Instead, you can just do a one time write from the central, then the code on the peripheral would go in a loop and send all the data to the central. In this scenario, your solution would have the following on the GATT server:-
And that's it, that is all you need. When you want to read the log data, you can use the following sequence:-
Finally, you can set your characteristic to be indicatable instead of notifiable. The only difference is that there will be acknowledgements when it is indicatable therefore the transfer is more reliable. However, the transfer will also be slower as a result of the extra acknowledgement packets.
I hope this helps.