Help with script to maintain bluetooth connection
-
I think I may have found a solution. If someone with a little more knowledge than me can take a look at this and let me know what they think. Adding this to my already existing startup script:
#!/bin/bash
address="XX:XX:XX:XX:XX:XX"
while (sleep 1)
do
connected=$(hidd --show) > /dev/null
if [[ ! $connected =~ .${address}. ]] ; then
hidd --connect ${address} > /dev/null 2>&1
fi
done -
I suffer with this problem as well.
-
@JasperSlade Did you create those files listed in the guide?
-
So far I've done the following:
Created: sudo nano /bin/connect-bluetooth.sh
Added the following text:
#!/bin/bash
sudo bluetoothctl << EOF
power on
connect [MAC Address]
exit
EOFMade the file executable: sudo chmod +x /bin/connect-bluetooth.sh
Created a service file: sudo nano /etc/systemd/system/connect-bluetooth.service
Added the following text:
[Unit]
Description=Connect Bluetooth
[Service]
Type=oneshot
ExecStart=/bin/connect-bluetooth.sh
[Install]
WantedBy=multi-user.targetEnabled the service file: sudo systemctl enable /etc/systemd/system/connect-bluetooth.service
At this point, my gamepad connects at startup flawlessly. When the gamepad powers down, it fails to reconnect.
I'm hoping that if I add the following text to my connect-bluetooth.sh, it will continually check for my gamepad, and reconnect when needed. Hopefully that is, it looks like the below code is for an older version of RetroPie, one that utilizes bluez, where as my build has bluetoothctl instead(#!/bin/bash
address="XX:XX:XX:XX:XX:XX"
while (sleep 1)
do
connected=$(hidd --show) > /dev/null
if [[ ! $connected =~ .${address}. ]] ; then
hidd --connect ${address} > /dev/null 2>&1
fi
done) -
In /bin/connect-bluetooth.sh, you did put the Mac Address where it says right?
-
Yes. 85:55:08:78:17:D1
-
I found my solution. I made the following changes (in bold) to my /bin/connect-bluetooth.sh file.
#!/bin/bash
while (sleep 30)
do
sudo bluetoothctl << EOF
power on
connect [MAC Address]
exit
EOF
doneYou can change the sleep value to whatever you'd prefer. 30 seconds seemed to work out fine for me. If i start to get impatient, I'll change it down to 15.
-
@JasperSlade said in Help with script to maintain bluetooth connection:
I found my solution. I made the following changes (in bold) to my /bin/connect-bluetooth.sh file.
#!/bin/bash
while (sleep 30)
do
sudo bluetoothctl << EOF
power on
connect [MAC Address]
exit
EOF
doneYou can change the sleep value to whatever you'd prefer. 30 seconds seemed to work out fine for me. If i start to get impatient, I'll change it down to 15.
Nice solution! Could you add this to the wiki page? Setting up a Bluetooth controller
-
@JasperSlade said in Help with script to maintain bluetooth connection:
You can change the sleep value to whatever you'd prefer. 30 seconds seemed to work out fine for me. If i start to get impatient, I'll change it down to 15.
It'll sleep for 30 seconds during the boot?
-
@Rion it's a wiki. Anyone can add to it provided the content is valid.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.