Ok since rebooting is annoying, I have tried two approaches.
- Create another device and bind the bluetooth to it. Then use the new one in your program.
Open /etc/bluetooth/rfcomm.conf and add another device.
rfcomm0 { # Automatically bind the device at startup bind no; #
Bluetooth address of the device device 00:06:66:68:20:61; # RFCOMM
channel for the connection channel 1; # Description of the
connection comment "This is Device 1's serial port."; }
rfcomm2 { # Automatically bind the device at startup bind no; #
Bluetooth address of the device device 20:15:12:08:62:95; # RFCOMM
channel for the connection channel 1; # Description of the
connection comment "This is Device 1's serial port."; }
rfcomm3 { # Automatically bind the device at startup bind no; #
Bluetooth address of the device device 20:15:12:08:62:95; # RFCOMM
channel for the connection channel 1; # Description of the
connection comment "This is Device 1's serial port."; }
Restart the bluetooth service then :
userk@dopamine:~$ sudo rfcomm bind 2 DEV_ADDR CHANNEL
Rfcomm can't release the device because of some other process in Ubuntu. Check which one with
userk@dopamine:~$ sudo lsof | grep /dev/rfcomm2
MATLAB 5554 6868 userk 514u CHR 216,2 0t0 603 /dev/rfcomm2
Kill it!!
userk@dopamine:~$ ps -ax | grep MATLAB
7684 pts/5 Sl 0:39 /usr/local/MATLAB/R2015b/bin/glnxa64/MATLAB
7873 pts/5 S+ 0:00 grep --color=auto MATLAB
userk@dopamine:~$ kill -9 7684
Voilà no ore forced reboot! Hope it helps