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:
esp = ble("BLE");
c = esp.characteristic("41BD8A4C-4E52-11EC-81D3-0242AC130003","17789A04-4E54-11EC-81D3-0242AC130003");
measurements = 10;
for m = 1:measurements
c.DataAvailableFcn = @displayData;
data = c.read();
text = char(data);
m + 1;
Harikrishnan Balachandran Nair on 1 Dec 2021
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.
You can refer to the example here to get a better idea on this : https://www.mathworks.com/help/matlab/ref/matlabshared.blelib.characteristic.read.html#mw_5cba06cb-595e-44b8-82cd-44a397a29c74