bluetooth command fails to open ubuntu laptop connection

I'm trying to perform file transfers using bluetooth between a laptop running Ubuntu and my Windows laptop.
If I directly use the Windows and Ubuntu GUI functions, then files are transferred. I want to use the Matlab functions so that the data transfer is part of the data processing scripts.
I've enabled the SSP on the linux laptop (the command 'sudo sdptool add SP' returns 'Serial Port service registered'.
With the device showing disconnected in the Windows Settings -> Bluetooth & devices -> Devices page, I run the bluetoothlist command in Matlab and the device is listed as 'ready to connect' with a channel of 1
If I then run the bluetooth command using the device name or mac address and the channel number, the connection fails with an exception and the object isn't returned, but the linux machine shows it's now connected.
>> bluetoothlist
Name Address Channel Status
_______ ______________ _______ __________________
"xxxxxx" "nnnnnnnnnnnn" 1 "Ready to connect"
>> bt = bluetooth("nnnnnnnnnnnn", 1);
Unable to connect to device. Run bluetoothlist to check device status and channel number.
Running bluetoothlist again shows the channel and status as unknown.
I've stepped through the process and find the exception is raised in channel.m line 308
% Gain exclusive access of the device.
obj.ChannelImpl.open(options);
I can't step into this function to isolate the problem further.
I'm running Matlab 2024B (with latest updates) on Windows 11.
Any suggestions are gratefully appreciated.

Answers (1)

Hi @Nigel,
To resolve the issue, please look into the following points:
  • Please confirm that the two PC's are paired the machines with each other over bluetooth.
  • I see that you have already enabled SSP on the linux laptop. On the "SPP server" computer, open MATLAB and open a connection to the incoming COM port using serialport. After this, the computer will be ready to listen to incoming Bluetooth connection requests. Please refer to the below command as an example to the function usage, and you can find more information on: https://www.mathworks.com/help/matlab/ref/serialport.html
s=serialport('COM4',9600)
  • On the "SPP client" computer, open MATLAB and open a connection to the other computer using MATLAB bluetooth
bluetoothlist
b = bluetooth(<name>,<channel>)
At this point you should be able to use "writeline/readline", "write/read" to exchange data between the two PC's.
Hope this helps!

3 Comments

Thank you for responding. The machines are paired (as I noted, the file transfers work when using the native applications both in Windows and Linux(Ubuntu)).
I'm running Matlab only on the Windows machine, the Linux machine doesn't have Matlab. I note that the Matlab documentation (Bluetooth Communication Overview - MATLAB & Simulink) is advising that Windows 10 is supported but doesn't reference Windows 11; I've also noted others have had issue with Windows 11 and BLE.
With both computers paired and disconnected, and with bluetoothlist setting the status of the Linux machine to 'ready to connect', running the bluetooth command should return a bluetooth object for subsequent processing (e.g. performing the data transfers) - it does not, this is the issue.
I'll review the use of the serialport command as you suggest.
Best regards
Nigel
@Nigel, I was able to perform successful file transfers with a Windows 11 machine. I am hopeful that the "serialport command" would help resolve the issue.
Thanks Gayathri for confirming. I hope to review later today and comeback with a successful result!

Sign in to comment.

Products

Release

R2024b

Asked:

on 11 May 2025

Commented:

on 15 May 2025

Community Treasure Hunt

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

Start Hunting!