Enable Bluetooth after each reboot?

Hello folks,

My father came over from the other side of the planet to visit, and, liked the look of my OSMC/Pi install, so I gave it to him and can’t test the following, but…

Side note: I’ve been so impressed by the quality and work that has been put into OSMC I have decided that, to replace the Pi I gave away, I will buy a Vero 2 so the OSMC folks can at least make a little money from me :). I’m quite curious to have a play. I will probably grab another Pi or 2 before too long anyway :blush:

…you could do the following to try to make it work on boot. This is now down the rabbit hole of hackiness, but if you’re desperate here goes.

As root, edit a file called /usr/sbin/start_bluetooth_hack, with the following content:

#!/bin/bash

bluetoothctl << EOF
agent on
default-agent
scan on
pair xx:xx:xx:xx:xx:xx
trust xx:xx:xx:xx:xx:xx
exit
EOF

Some notes about the above script. I stress, I can’t test this right now, so while I can’t see why it wouldn’t work it is possible that bluetoothctl needs commands to wait to complete before the next one is sent, and, doesn’t buffer properly, or something like that, in which case it won’t work, and you’d be getting even hackier using an expect script :slight_smile:

Then run the command

chmod 700 /usr/sbin/start_bluetooth_hack

Finally, put it in /etc/rc.local like before

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# I'm not sure if you'll want the next line or not
# (sleep 10 ; connmanctl enable bluetooth)
(sleep 10 ; /usr/sbin/start_bluetooth_hack) &

exit 0

Edit on 2016-10-14, added an & to the end of the line that says (sleep 10 ; /usr/sbin/start_bluetooth_hack)

1 Like