Get bluetooth working

  • Home Assistant recently made an update that should make adding bluetooth support and devices to it easier. So I bought the "SUMEE BT501" bluetooth dongle as the documentation recommended it, also did " sudo apt-get install bluez ". The bluetooth device I want to add is a Xiaomi MiFlora sensor to get some nice graphs for my plant.

    I'm on OMV6 and have Home Assistant running in a docker container using Portainer, this is the stack, it's on host, has the volume and device hci0 added.


    Which should be correct, first had an error about dbus and after adding it to the volumes that went away, but then got an error: " Retrying setup: Failed to start Bluetooth: adapter 'hci0' not found " after some Googling and doing SSH "/etc/init.d/bluetooth status" it says the device is "active (running) however when doing "bluetoothctl devices" it says "No default controller available" and then after doing " hciconfig -a hci0" it says:

    Code
    root@server:~# hciconfig -a hci0
    hci0:   Type: Primary  Bus: USB
            BD Address: 00:00:00:00:00:00  ACL MTU: 0:0  SCO MTU: 0:0
            DOWN
            RX bytes:42 acl:0 sco:0 events:4 errors:0
            TX bytes:12 acl:0 sco:0 commands:4 errors:0
            Features: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
            Packet type: DM1 DH1 HV1
            Link policy:
            Link mode: SLAVE ACCEPT

    Doing " sudo hciconfig hci0 up" it says "Can't init device hci0: No such file or directory (2)" and I can't seem to find much about the last error using Google. Also rebooted multiple times between these steps. Also reset the permissions in the hope it would be able to access the hci0 directory but had no succes.

    The issue is definitely something with it not being able to find hci0 but I can't figure out how to create that directory as I can't find much about it.


    Don't know if this is the right place to ask this question but hopefully someone can help me, it would be greatly appreciated.

  • I'd first try to get bluetooth working on the host - which I didn't manage to do myself so far.

    So this is more of a sum up.


    Your adapter uses the RTL8761B chip.

    I bought the EDUP LOVE EP-B3536 [RTL8761BU] (Long Range) in the hope of an easy life with Home Assistant.


    I had the adapter show up in Home Assistant with these additions to the docker-compose:


    Code
    volumes:
      - /run/dbus:/run/dbus:ro
    
    
    devices:
       - /dev/ttyUSB0:/dev/ttyUSB0


    but that was all I got. Taken from: https://www.home-assistant.io/integrations/bluetooth/

    (install bluez et al of course)


    After that, I tested on my local machine with Linux mint 20.3.

    bluetoothctl list showed the adapter, blueman showed it, but scanning didn't find anything.

    With the help of much googling I found the solution: https://forums.linuxmint.com/v…ic.php?p=2205193#p2205193

    dmesg showed that the firmware rtl8761bu_fw was not found. The solution was, to


    Code
    cd /lib/firmware/rtl_bt
    sudo ln -s rtl8761b_fw.bin rtl8761bu_fw.bin


    So, for your adapter, the presence of rtl8761b_fw would be relevant.

    After that, I successfully scanned, paired and used a bluetooth speaker on mint.

    I thought, easy fix, lets try on OMV6 (which uses debian bullseye 11) ... and the chaos began.

    (here is a success story for debian 10 btw: https://debianforum.de/forum/viewtopic.php?t=178320 )


    - There is no rtl8761b_fw or rtl8761bu_fw in /lib/firmware/rtl_bt (gota use the files from realtek-firmware from debian 12 bookworm)

    - There is no dmesg error on missing firmware

    - bluetoothctl shows the stick but no scanning results


    Everything I tried and searched and tested didn't result in a scan result with any found devices. Before that, it makes no sense to forward it to docker.

    Even with the files from debian 12 I didn't get a scan result :( Did you get it working in the meantime or what was your solution?

  • After a wild ride, I think it works :D


    tl;dr: enable backports and update to the latest kernel (5.18.0-0.deb11.4-amd64 at time of writing)


    First, I removed BT integration from docker-compose.

    I came accross this thread: https://unix.stackexchange.com…/bluetooth-dongle-drivers

    which I followed and built a new btusb module using the mpow linux drivers with some detours:

    - had to find out, that OMV dosn't ship the linux-headers for the 5.0.16 kernel,

    - had to enable backports from the OMV GUI

    - updated to the latest kernel 5.18.0-0.deb11.4-amd64 with its headers.

    - then succeeded to make install, the module with make install INTERFACE=usb

    - to find out, that not even hciconfig would show the adapter anymore. :D

    - dmesg showed tainted kernel warning and one error for the bt adapter: usb 1-5.1: device descriptor read/64, error -32

    - So, return to the folder of the mpow drivers and use the makefile inside the 20201202_LINUX_BT_DRIVER/usb folder to make uninstall,

    - reboot



    Ok, lets check if the new kernel maybe has some changes already to make the adapter work?

    It does!

    I finally got the direct-loading firmware message in dmesg:


    lets try scanning:

    Code
    bluetoothctl
    Agent registered
    [CHG] Controller 00:E0:4C:25:55:23 Pairable: yes
    [bluetooth]# scan on
    Discovery started
    [CHG] Controller 00:E0:4C:25:55:23 Discovering: yes
    [NEW] Device ...


    The new device appeared instantly!

    I was also able to pair on the host. :D

    -----------


    After that, I added the relevant lines back to docker-compose... just to find out, that bluetooth speakers are a mess with HA. :(

    No further testing on integrating bt devices for me atm.


    hih


    PS: the EDUP LOVE EP-B3536 [RTL8761BU] (Long Range) detected my phone down from the basement which was sitting on my desk at the 1st floor :huh:

  • I resolved my bluetooth speaker issue with the DLNA renderer integration of Home Assistant.

    I added the HOST of the docker as a dlna renderer to HA. The host auto connects to the bluetooth speaker at boot.


    The sound travels like this: <any device> -> OMVhost with upmpdcli -> mpd -> pulseaudio -> bluetooth speaker


    (not a step by step guidance, but more of a brain dump with the important corners to touch.)To receive dlna sound from external devices, the host got upmpdcli installed https://www.lesbonscomptes.com/upmpdcli/

    • configure in: etc/upmpdcli.conf like
    Code
    # "Friendly Name" for the Media Renderer.
    friendlyname = OmvHost
    # Specific friendly name for the UPnP/AV Media Renderer.
    avfriendlyname = OmvHost Player
    # Enable UPnP AV services (0/1).
    upnpav = 1
    # Enable OpenHome services (0/1).
    openhome = 1
    • for convenience one can use bubbleUpnp Server to manage all your dlna devices. my docker-compose:
    • Unfortunately OMV ships with nothing to play sound, so I had to install pulseaudio by hand.
      I installed pulseaudio in system mode https://www.freedesktop.org/wi…entation/User/SystemWide/ because no user is logged in on the omv host.
    • to get the host to connect and play on the bluetooth speaker you have to allow it:
      First let pulseaudio listen on localhost for sound streams.
      • in etc/pulse/system.pa append:
    Code
    # listen on localhost for incoming streams
    load-module module-native-protocol-tcp auth-ip-acl=127.0.0.0/8;10.0.0.0/8;172.16.0.0/12;192.168.0.0/16;fe80::/10
    load-module module-zeroconf-publish
    load-module module-zeroconf-discover
    
    ### Bluetooth Support
    .ifexists module-bluetooth-discover.so
    load-module module-bluetooth-discover
    .endif


    • configure mpd to play to pulseaudio localhost: In etc/mpd.conf I added:
    Code
    audio_output {
            type    "pulse"
            name    "MPD to PA localhost"
            server  "127.0.0.1"   
            ##port    "4713"
            #sink    "alsa_output" # optional. automatic
            #sink     "<bluez_sink.6C_47_60_9B_D6_03.a2dp_sink>"
    }



    and in /etc/dbus-1/system.d/pulseaudio-system.conf


    to autoconnect the speaker at reboot I added in /etc/crontab

    @reboot root /root/connectBtSpeaker.sh

    with this content:

    Bash
    #!/bin/sh
    sleep 5 && /bin/echo -e 'connect 6C:....:03\n quit\n' | bluetoothctl


    for general testing of pulseaudio, I used speaker-test to make some noise.

    To see if puleaudio can play to the bluetooth speaker you can use pacmd list-sinks

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!