Auto Connect Bluetooth Headset

  • Hi there,

    I have a bluetooth adapter on Rasp pi 2 with Nokia bluetooth headset working fine. Very happy that finally we have bluetooth audio on kodi 16.1. The issue is when I turn off bluetooth and switch back on, it does not auto connect. I have to drill down all the menu and select -> connect to make it work. I have tried using both Connect and Trust & Connect option without luck. Using Libreelec 7.0.1.

    Am I missing something here or it is by design and not suppose to auto connect. If later, what are others doing? Any suggestions on shortcuts?

    I have added 2 shortcut buttons to switch between bluetooth audio & hdmi in kodi remote ios app. How do I add this toggle in cec remote?

    Cheers

    • Official Post

    Honestly to me it just seems like it depends on the device. I have a bluetooth speaker that auto connects fine when I turn the speaker on yet my iPhone does not auto connect.

    Perhaps it is something in bluez that I can look into.

  • Thanks. Sorry, but by bluez do you mean debug log? If auto connect does not work, is there a way to create some shortcut to select the headset so that I don't have to drill down to settings to select it?

    Cheers.

  • lrusak, thanks again for pointing out audioProfiles on the thread i started.

    my headphones wont auto-reconnect either. i tried forgetting & trusting. no change.

    please let us know if anything would help ya, like a bluetoothd debug or contents of my ~/.cache/bluetooth ?

    in the meantime can we force a reconnect from the command line ? that would allow me to map a remote button to 'reconnect & switch audio profiles'

    i've tried google for a few hours but im not succeeding. any advice would be appreciated.

    Edited once, last by zosky (June 15, 2016 at 4:11 AM).

  • after some sleep, i gave google another chance ...

    Code
    echo -e "connect <MY-HEADPHONES-MAC>\nexit" | bluetoothctl

    then i made a wrapper around audioProfiles so if its switching to BT ... connect to the headPhones

    its pretty dirty, but more importantly the wife is happy.

  • got a PM on how to do the wrapper. figured i'd post here just so anyone else looking doesn't have to ask too.

    rather then pointing a button to "RunScript(script.audio.profiles,0)" like the audioProfiles addon says.

    do something like this

    Code
    <key id="0x07">RunScript(/storage/autoConnect.py)</key>

    then create /storage/autoConnect.py
    and replace ##YOUR-BT-MAC## on the 2nd last line

  • Thanks for posting the code and your fix I've reused the code you posted. Thanks!

    I have a device that pairs via bluetooth and the BT connection survives a reboot. Though if a another device connects to the BT audio adaptor the adaptor will reconnect to that.
    After some testing the BT Audio adaptor seems to remember the last 2 connected BT devices and searches for these in order of last connection.
    If a third device connects then the BT address used that was not used for the longest time is forgotten.

    I looked at your script and the connect can be run without checking if the Audio Profile is in mode 1 or 2 you can unconditionally invoke the BT connect as if the device is already connected the command has no effect: All you need is the line call('echo -e "connect ##YOUR-BT-MAC##\nexit" | bluetoothctl', shell=True)

    The code you have to switch audio profiles uses the zero parameter this toggles the audio profile (so if its 1 it becomes 2 and if its 2 it becomes 1) not sure why you want to flip the status on boot?

    I have a set up where 1 is the TV speakers and 2 is the BT so on boot I use the parameter 1 to force the sound out of the TV when the device boots: xbmc.executebuiltin('XBMC.RunScript(script.audio.profiles,1)')

    My thinking for keeping the pair and the connect in the start up is that should the pairing be lost I can press the pair button on the BT Audio adaptor and then reboot the RasPi the start script will repair and reconnect.

    Code
    import xbmc
    import os
    xbmc.executebuiltin('XBMC.RunScript(script.audio.profiles,1)')
    call('echo -e "pair xx:xx:xx:xx:xx:xx\nexit" | bluetoothctl', shell=True)
    call('echo -e "connect xx:xx:xx:xx:xx:xx\nexit" | bluetoothctl', shell=True)