Get specific number of BLE notifications

6 views (last 30 days)
I'm writing a script trying to get 10 notifications from a BLE device. The value contiains a char-array which i then want to display (and later save to csv, not implemented).
I want to get the values as soon as they are available and dont want double readings so I thought using the notification feature of BLE might work. I dont know how to use the DataAvailableFcn though. I get this error:
Error using BLETest (line 10)
Invalid value for DataAvailableFcn. Specify [] or a function handle that accepts two inputs.
The MATLAB exaples only use delays and read the data periodicly.
My code looks like this:
clear esp
esp = ble("BLE");
Scanning and connecting to Bluetooth Low Energy peripheral devices are not supported on Linux.
c = esp.characteristic("41BD8A4C-4E52-11EC-81D3-0242AC130003","17789A04-4E54-11EC-81D3-0242AC130003");
measurements = 10;
for m = 1:measurements
c.DataAvailableFcn = @displayData;
function displayData()
data =;
text = char(data);
m + 1;

Answers (1)

Harikrishnan Balachandran Nair
Hi Lars,
The 'DataAvailableFcn' property should be assigned a Function Handle that accepts two inputs . In the code you have provided, the function 'displayData' does not have any input arguments, and hence the error occurs.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!