Issue with receiving BLE notifications in Matlab

6 ビュー (過去 30 日間)
Anton
Anton 2024 年 12 月 9 日
編集済み: praguna manvi 2024 年 12 月 31 日
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

回答 (1 件)

praguna manvi
praguna manvi 2024 年 12 月 31 日
編集済み: praguna manvi 2024 年 12 月 31 日
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!

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by