Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 6687  / 3 Years ago, tue, october 5, 2021, 3:07:20

Today I installed Ubuntu 18.04 x64 LTS on a Dell Latitude E6410i with Windows 7 pre-installed. I connected to my new JBL Flip4 speaker with Bluetooth 4.2 and with A2DP V1.3, AVRCP V1.6, HFP V1.6, and HSP V1.2, and paired it successfully.



I want to auto-connect to the speaker at login; it should connect every time I login to Ubuntu, but does not.



After study, I found suggestions on the web (like Autoconnect to a bluetooth speaker in Ubuntu 16.04), but I can't find rc.local in my system. Also, I installed bt-autoconnect which does not help.



How should I proceed to resolve this?


More From » 18.04

 Answers
4

Work Around



Note:

Below Procedure Tested with my JBL Xtreme

OS: Ubuntu 18.04



at your present Situation that is you have already paired your BT device and while booting your BT device is On,



after login try this..




  1. Open Terminal and run bluetoothctl


  2. The Output will be similar to this




Output:



pratap@i7-4770:~$ bluetoothctl
[NEW] Controller xx:xx:xx:xx:xx:xx i7-4770 [default]
[NEW] Device aa:bb:cc:dd:ee:ff JBL Xtreme
[NEW] Device xx:xx:xx:xx:xx:xx HUAWEI P smart
Agent registered
[bluetooth]#



  1. In above case "JBL Xtreme" Bluetooth Device is Paired but not yet connected.. So to connect to this device



run connect aa:bb:cc:dd:ee:ff at the prompt [bluetooth]#



Example:



[bluetooth]# connect aa:bb:cc:dd:ee:ff
Attempting to connect to aa:bb:cc:dd:ee:ff
[CHG] Device aa:bb:cc:dd:ee:ff Connected: yes
Connection successful
[CHG] Device aa:bb:cc:dd:ee:ff ServicesResolved: yes
[JBL Xtreme]#


This Means if you can run the command bluetoothctl and then at the [bluetooth]# prompt if you can input connect aa:bb:cc:dd:ee:ff The Bluetooth Device will connect.



So this can be done with a single command in terminal like this, after your first login open Terminal and run this command.



echo "connect aa:bb:cc:dd:ee:ff" | bluetoothctl



Example:



pratap@i7-4770:~$ echo "connect aa:bb:cc:dd:ee:ff" | bluetoothctl
[NEW] Controller xx:xx:xx:xx:xx:xx i7-4770 [default]
[NEW] Device aa:bb:cc:dd:ee:ff JBL Xtreme
[NEW] Device xx:xx:xx:xx:xx:xx HUAWEI P smart
Agent registered
[bluetooth]# connect aa:bb:cc:dd:ee:ff
Attempting to connect to aa:bb:cc:dd:ee:ff
Agent unregistered
[DEL] Controller xx:xx:xx:xx:xx:xx i7-4770 [default]
pratap@i7-4770:~$


so the command echo "connect aa:bb:cc:dd:ee:ff" | bluetoothctl is working..



This means if we can run this command at login without human interaction.. the Bluetooth Device which is Paired and already Turned on at the time of Boot will connect in the above manual way..







  1. mkdir ~/bin (Create this directory if you dont have already.. Otherwise Ignore this step)


  2. touch ~/bin/btautoconnect.sh


  3. gedit ~/bin/btautoconnect.sh




Paste the Below Content:



#!/bin/bash

bluetoothctl
sleep 10
echo "connect aa:bb:cc:dd:ee:ff" | bluetoothctl
sleep 12
echo "connect aa:bb:cc:dd:ee:ff" | bluetoothctl
exit



  1. Save & Close the File.


  2. chmod +x ~/bin/btautoconnect.sh




create a .desktop file named btautoconnect.desktop in ~/.config/autostart/




  1. touch ~/.config/autostart/btautoconnect.desktop



Open the fiel with gedit and copy paste the content below this command




  1. gedit ~/.config/autostart/btautoconnect.desktop



Content:



[Desktop Entry]
Type=Application
Exec=/bin/bash /home/pratap/bin/btautoconnect.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=BTAutoConnect
X-GNOME-Autostart-Delay=5
Comment=Starts Bluetooth speaker



  1. Reboot to see the BT Device Connected after login in 10 to 20seconds.. without any Human Interaction..



Credits: https://ubuntuforums.org/showthread.php?t=2365083


[#4951] Wednesday, October 6, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
irtuallyefu

Total Points: 429
Total Questions: 97
Total Answers: 119

Location: Hong Kong
Member since Tue, Oct 19, 2021
3 Years ago
irtuallyefu questions
;