sputnikdev / eclipse-smarthome-bluetooth-binding

Eclipse SmartHome Bluetooth Binding
46 stars 10 forks source link

problems in setting up bluetooth manager #61

Closed 1Joe1 closed 5 years ago

1Joe1 commented 5 years ago

Hello,

I am having trouble in getting my usb bluetooth dongle (ORICO USB Bluetooth Adapter 4.0 (BTA-402)) working with openHAB. I am running openHAB 2.3 on my raspberry pi 2.

I followed the installation procedure described here: https://github.com/sputnikdev/eclipse-smarthome-bluetooth-binding As part of this I tried both building bluez from sources and the other method mentioned. (https://github.com/sputnikdev/bluetooth-manager-tinyb#prerequisites)

However there seems to be something going wrong, as "sudo systemctl restart bluetooth" leads to this error:

Job for bluetooth.service failed because the control process exited with error code. See "systemctl status bluetooth.service" and "journalctl -xe" for details.

openhabian@openHABianPi:~$ systemctl status bluetooth.service ● bluetooth.service - Bluetooth service Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sun 2018-09-09 23:39:26 CEST; 3min 3s ago Docs: man:bluetoothd(8) Process: 20461 ExecStart=/usr/libexec/bluetooth/bluetoothd (code=exited, status=1/FAILURE) Main PID: 20461 (code=exited, status=1/FAILURE)

Status: "Starting up" Sep 09 23:39:26 openHABianPi systemd[1]: Starting Bluetooth service... Sep 09 23:39:26 openHABianPi bluetoothd[20461]: Bluetooth daemon 5.47 Sep 09 23:39:26 openHABianPi bluetoothd[20461]: D-Bus setup failed: Connection ":1.42" is not allowed to own the service "org.bluez" due to security policies in the configuration file Sep 09 23:39:26 openHABianPi systemd[1]: bluetooth.service: Main process exited, code=exited, status=1/FAILURE Sep 09 23:39:26 openHABianPi systemd[1]: Failed to start Bluetooth service. Sep 09 23:39:26 openHABianPi systemd[1]: bluetooth.service: Unit entered failed state. Sep 09 23:39:26 openHABianPi systemd[1]: bluetooth.service: Failed with result 'exit-code'.

The adapter itself seems to be recognised:

openhabian@openHABianPi:~$ lsusb ... Bus 001 Device 005: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HCI mode) ...

openhabian@openHABianPi:~$ udevadm info -a -p $(udevadm info -q path -n /dev/bus/usb/001/005) ... ATTR{product}=="CSR8510 A10" ...

the command "bluetoothctl" freezes my command line.

Any ideas on what I am missing? Anything I could try?

vkolotov commented 5 years ago

Yes, it looks like DBus permissions are not set up properly to allow OH user to access Bluez stuff.

Are you sure you've done point 8 from here https://github.com/sputnikdev/bluetooth-manager-tinyb#building-bluez-from-sources?

vkolotov commented 5 years ago

Sorry, it is probably nothing to do with OH user, but still the error log indicate that your Bluez daemon can't talk to DBus because permissions are not set up properly.

1Joe1 commented 5 years ago

Thanks a lot for your fast reply.

yes, I am sure I performed step 8 and added

</policy>
  <policy group="bluetooth">
    <allow send_destination="org.bluez"/>
  </policy>

So my buetooth.conf file looks like this

 ...
<policy user="root">
    <allow own="org.bluez"/>
    <allow send_destination="org.bluez"/>
    <allow send_interface="org.bluez.Agent1"/>
    <allow send_interface="org.bluez.MediaEndpoint1"/>
    <allow send_interface="org.bluez.MediaPlayer1"/>
    <allow send_interface="org.bluez.ThermometerWatcher1"/>
    <allow send_interface="org.bluez.AlertAgent1"/>
    <allow send_interface="org.bluez.Profile1"/>
    <allow send_interface="org.bluez.HeartRateWatcher1"/>
    <allow send_interface="org.bluez.CyclingSpeedWatcher1"/>
    <allow send_interface="org.bluez.GattCharacteristic1"/>
    <allow send_interface="org.bluez.GattDescriptor1"/>
    <allow send_interface="org.freedesktop.DBus.ObjectManager"/>
    <allow send_interface="org.freedesktop.DBus.Properties"/>
  </policy>

 </policy>
  <policy group="bluetooth">
    <allow send_destination="org.bluez"/>
  </policy>

  <policy at_console="true">
    <allow send_destination="org.bluez"/>
  </policy>
...

I noticed step 9 sudo usermod -a -G bluetooth openhab does not give me any reply. Is this normal?

As I am already trying to get this working for several days, I double, tripple... preformed the process. As mentioned I also tried the second method for setting up Bluez. When browsing the openhabian folder it seems that both buez-5.43 and bluez-5.47 are installed. When searching for "bluetooth.conf" I also get multiple findings. Could this be a problem?

vkolotov commented 5 years ago

Hi @1Joe1,

does not give me any reply. Is this normal?

Yes, that's fine.

Sorry to hear that you put a lot of effort in it, but BT was never easy in linux unfortunately.

Yes, it is definitely wrong that you have several Bluez installed. Could you try to remove it first and then instal it from sources? This would eliminate some possible errors.

1Joe1 commented 5 years ago

Sorry, I am quite new to openHAB and linux.

I tried removing Bluez with sudo apt-get autoremove bluez

however I still have both a \OPENHABIANPI\openhabian\bluez-5.47 and a \OPENHABIANPI\openhabian\bluez-5.43 folder full with a bunch of files. And bluetoothd -v tells me I have 5.43 installed. How do I remove bluez properly?

vkolotov commented 5 years ago

No worries, try

sudo apt-get purge bluez
1Joe1 commented 5 years ago

More or less the same result

[00:00:04] openhabian@openHABianPi:~$ sudo apt-get purge bluez [sudo] password for openhabian: Reading package lists... Done Building dependency tree Reading state information... Done You might want to run 'apt --fix-broken install' to correct these. The following packages have unmet dependencies: bluetooth : Depends: bluez but it is not going to be installed bluez-cups : Depends: cups but it is not going to be installed bluez-dbg : Depends: bluez (= 5.43-0ubuntu1~lorenzen1) but it is not going to be installed pi-bluetooth : Depends: bluez but it is not going to be installed E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution). [00:00:21] openhabian@openHABianPi:~$ bluetoothd -v 5.43

vkolotov commented 5 years ago

Did you try to run apt --fix-broken install?

This is something wrong with your package manager... We definitely need to remove the older version before installing the newer.

1Joe1 commented 5 years ago

Bad news. apt --fix-broken install have me this error:

Setting up bluez-cups (5.43-0ubuntu1~lorenzen1) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
Processing triggers for systemd (232-25+deb9u4) ...
Processing triggers for dbus (1.10.26-0+deb9u1) ...
Errors were encountered while processing:
 bluez
 bluez-dbg
 bluetooth
Updating FireMotD available updates count ... 2018-09-11 07:12:30,543: FireMotD: Error: Template basic does not exist. Try \'basic\' or \'all\'.jq: error: Could not open file /usr/share/firemotd/data/FireMotD.json: No such file or directory

E: Sub-process /usr/bin/dpkg returned an error code (1)

I get the feeling there is no way around setting my raspberry completely new. Learning for the next time: regular backups! Even if not everything is up and running yet :-). Or are there any other things I could try first?

vkolotov commented 5 years ago

Yeah, not sure. We could try to remove the old BLuez manually, then install new one, and them manually set proper soft links... I would try it first. But then, looks like your apt-get manager is badly broken, what if next time you will need to install something else?

Run this:

whereis bluetoothd
bluetoothd: /usr/sbin/bluetoothd /usr/share/man/man8/bluetoothd.8.gz /usr/share/man/man8/bluetoothd.8

to identify where your bluez is/are

Then see what is /usr/sbin/bluetoothd:

ls /usr/sbin -la | grep bluetoothd
lrwxrwxrwx  1 root root     27 May 27  2016 bluetoothd -> ../lib/bluetooth/bluetoothd

Here you will need to delete that soft link (/usr/sbin/bluetoothd), and create new one that points to the new Bluez. It is doable, just may not give you 100% of the result, as some other tools/utilities would still be used from the old Bluez unless you do it for all. Still worth trying I think.

1Joe1 commented 5 years ago

Sorry for the delayed answer. I get until:

Here you will need to delete that soft link (/usr/sbin/bluetoothd), and create new one that points to the new Bluez.

So far I get the same responses as you do. I feel dumb to ask, but how do I remove the link? And by "here", do you mean " /lib/bluetooth/bluetoothd " ? Because when trying this I get

openhabian@openHABianPi:~$ /lib/bluetooth/bluetoothd
-bash: /lib/bluetooth/bluetoothd: No such file or directory
xrucka commented 5 years ago

Hi, to join the discussion - as Ivan suggested, which tells you where your bluetoothd resides. In Ivan's case, this is /usr/sbin/bluetoothd; further ls -al shows that it points to ../lib/bluetooth/bluetoothd relative to /usr/sbin/bluetoothd - which is /usr/lib/bluetooth/bluetoothd and not /lib/bluetooth/bluetoothd.

So if your ls shows the same relative path, you've ommited /usr from the absolute path.

P.S. Symbolic link is just a special file, if you want to remove it (not the target), just run rm as for normal file (rm /usr/sbin/bluetoothd).

Btw, what is your distribution?

1Joe1 commented 5 years ago

Thanks a lot for your support! I have no idea what got my bluez installation messed up I in the first place, but I couldn't get it right even with you tips. Probably due to my very limited Linux skills. Therefore I choose a clean reinstall (openhabian) and now the binding works just fine.