Matlab BLE , live mode

14 次查看(过去 30 天)
도겸
도겸 2024-9-5
回答: Saurabh 2024-9-9
clc; clear; close all;
% Scanning for nearby BLE devices
disp('Scanning... Searching for nearby BLE devices.');
Scanning... Searching for nearby BLE devices.
devices = blelist; % BLE device scan
Scanning and connecting to Bluetooth Low Energy peripheral devices are not supported on Linux.
disp('List of nearby BLE devices:');
disp(devices);
% Connecting to BLE device (using MAC address or device name)
try
bleDevice = ble("c8:2e:18:de:50:ae"); % Change to the actual MAC address
disp("Successfully connected to the BLE device using MAC address.");
catch ME
disp("Unable to connect to the BLE device.");
disp(ME.message);
return; % Terminate program if connection fails
end
% Subscribing to BLE characteristic (using ServiceUUID and CharacteristicUUID)
try
% Setting Service and Characteristic UUID
serviceUUID = "AF4E9B0E-8D4E-4239-84EB-CB75D7BD8D9A";
characteristicUUID = "8F00C643-1021-4AC6-9325-6653AE773173";
% Creating characteristic object
characteristic = characteristic(bleDevice, serviceUUID, characteristicUUID);
% Displaying and verifying characteristic's attributes
disp('Attributes of the characteristic:');
disp(characteristic.Attributes); % Displaying the attributes of the characteristic
% Checking if Notify permission is available
if any(strcmp(characteristic.Attributes, 'Notify'))
disp("Notify permission confirmed. Attempting to subscribe...");
% Setting DataAvailableFcn instead of subscribe
characteristic.DataAvailableFcn = @processBLEData;
disp("BLE data subscription successfully set.");
else
error("Characteristic does not support Notify permission.");
end
catch ME
disp("Failed to set BLE data subscription.");
disp(ME.message); % Display error message for diagnosis
return;
end
% Callback function for data reception
function processBLEData(~, evt)
disp('Receiving BLE data...');
s1 = char(evt.Data'); % Convert uint8 array to string
disp('Converted data:');
disp(s1); % Displaying the received data
end
I'm trying to get the sensor in live mode from Matlab, but I get the following error.
Notify permission has been verified, attempt to subscribe...
Unable to set up BLE data subscription.
The operation failed because it was not allowed to read.
In this case, what part should be corrected?

回答(1 个)

Saurabh
Saurabh 2024-9-9
It seems like you are unable to set up a BLE data subscription. I browsed the official documentation website to see if there were any steps for troubleshooting.
There, I discover that Windows 10 and Windows 11 as well as macOS support the Bluetooth Low Energy interface. It appears that Linux is the operating system on your machine, which may be the root of the problem.
If not, you can attempt other troubleshooting procedures found at the following link:
I Hope this was helpful.

产品

Community Treasure Hunt

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

Start Hunting!

Translated by