bluetooth command fails to open ubuntu laptop connection

2 views (last 30 days)
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)

Gayathri
Gayathri on 14 May 2025
Edited: Gayathri on 14 May 2025
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
Gayathri
Gayathri on 15 May 2025
Edited: Gayathri on 15 May 2025
@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.
Nigel
Nigel on 15 May 2025
Thanks Gayathri for confirming. I hope to review later today and comeback with a successful result!

Sign in to comment.

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!