Issue with receiving BLE notifications in Matlab

4 visualizzazioni (ultimi 30 giorni)
Anton
Anton il 9 Dic 2024
Modificato: praguna manvi il 31 Dic 2024
Hi!
I`m implementing the Matlab class to obtain signal streaming data via BLE from the Nordic MCU.
The signal comes as a Samples with timestamp via notifications to a custom BLE characteristic.
The issue is that Matlab is not reliable when receiving this data (looks like its procesing takes too much time), yet I found that when the notification callback is set as:
obj.mDataChar.DataAvailableFcn = (@(src,event)processNewStreamData(obj,src,event));
the Matlab subsribes to notifications automatically. So, the subsequent call to
subscribe(obj.mDataChar, "notification");
doubles the number of calls to the callback (i.e. if Nordic MCU transmits 10 notifications, Matlab gets around 20 with duplicate data).
In order to make sure I subscribed to this characteristic once, I added a function to check for the active subscription via reading CCCD:
function subscribed = isSubscribedToChar(obj, bleChar)
% Checks if we are subscribed to the specified BLE
% characteristic
subscribed = false;
% We need to check Client Characteristic Configuration
% descriptor to check if we are subscribed to the
% characteristic
try
cccd = descriptor(bleChar, "Client Characteristic Configuration");
attributes = read(cccd);
subscribed = logical((attributes(1) == 1));
catch
warning("Can't check if we are subscribed to char notifications");
end
end
Yet this reports active subscription only after
subscribe(obj.mDataChar, "notification");
is called.
So, it leads to the issue of correct data receiving.
I tried with different data rates, but the issue persist.
Normally, Nordic board transmits a single notification with 240 bytes (MTU is 244) with 24ms period.
Can you please suggest if anything is wrong here?
And if there is a way to increase the Matlab callback performance, since the "NRF Connect" app receives the data perfecrly.
Matlab version: R2024a.
Thanks,
Anton

Risposte (1)

praguna manvi
praguna manvi il 31 Dic 2024
Modificato: praguna manvi il 31 Dic 2024
Hi @Anton,
As I see, you are looking to optimize the latency of the callback "processNewStreamData" which processes "ble" notifications. To verify the correctness of your implementation, you can follow the example on using a callback function on "characteristic" object:
openExample('matlab/LogCharDataBLEDeviceCallbackFuncExample')
To fine-tune the performance of your callback function, you can refer to the following link, which details various techniques for improving function performance:
Hope this helps!

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by