Revival of Official Bluetooth Binding

its ok ,i did a reboot,now i can see controller and scaning for devices works

[bluetooth]# scan on
Discovery started
[CHG] Controller B8:27:EB:63:EF:FC Discovering: yes
[NEW] Device 62:2E:E9:70:61:2C [LG] webOS TV OLED55C7V
[NEW] Device 78:11:DC:C3:D8:24 MiKettle
[NEW] Device 58:D5:24:A6:4F:D7 58-D5-24-A6-4F-D7
[NEW] Device 42:E3:A3:E6:99:32 42-E3-A3-E6-99-32
[NEW] Device 00:04:4B:EB:59:30 SHIELD

still no adapter at paperUI

Then just go ahead and discover the adapter manually in paperUI. Just use your adapter address B8:27:EB:63:EF:FC to do it.

just did and i get

Status: UNINITIALIZED - HANDLER_INITIALIZING_ERROR BlueZ JNI connection cannot be established.

log error

2020-10-24 08:11:30.052 [hingStatusInfoChangedEvent] - 'bluetooth:bluez:27e2b1b0' changed from UNINITIALIZED to INITIALIZING

==> /var/log/openhab2/openhab.log <==

2020-10-24 08:11:30.078 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.initialize()' on 'org.openhab.binding.bluetooth.bluez.handler.BlueZBridgeHandler@16dbf15': BlueZ JNI connection cannot be established.

java.lang.IllegalStateException: BlueZ JNI connection cannot be established.

	at org.openhab.binding.bluetooth.bluez.handler.BlueZBridgeHandler.initialize(BlueZBridgeHandler.java:73) ~[?:?]

	at sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source) ~[?:?]

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_265]

	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_265]

	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [bundleFile:?]

	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]

	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_265]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_265]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_265]

	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_265]

Caused by: java.lang.UnsatisfiedLinkError: tinyb.BluetoothManager.getNativeAPIVersion()Ljava/lang/String;

	at tinyb.BluetoothManager.getNativeAPIVersion(Native Method) ~[?:?]

	at tinyb.BluetoothManager.getBluetoothManager(BluetoothManager.java:304) ~[?:?]

	at org.openhab.binding.bluetooth.bluez.handler.BlueZBridgeHandler.initialize(BlueZBridgeHandler.java:68) ~[?:?]

	... 9 more

==> /var/log/openhab2/events.log <==

2020-10-24 08:11:30.116 [hingStatusInfoChangedEvent] - 'bluetooth:bluez:27e2b1b0' changed from INITIALIZING to UNINITIALIZED (HANDLER_INITIALIZING_ERROR): BlueZ JNI connection cannot be established.

==> /var/log/openhab2/openhab.log <==

2020-10-24 08:11:30.107 [ERROR] [core.thing.internal.ThingManagerImpl] - Exception occurred while initializing handler of thing 'bluetooth:bluez:27e2b1b0': BlueZ JNI connection cannot be established.

java.lang.IllegalStateException: BlueZ JNI connection cannot be established.

	at org.openhab.binding.bluetooth.bluez.handler.BlueZBridgeHandler.initialize(BlueZBridgeHandler.java:73) ~[?:?]

	at sun.reflect.GeneratedMethodAccessor64.invoke(Unknown Source) ~[?:?]

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_265]

	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_265]

	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:152) [bundleFile:?]

	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:52) [bundleFile:?]

	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_265]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_265]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_265]

	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_265]

Caused by: java.lang.UnsatisfiedLinkError: tinyb.BluetoothManager.getNativeAPIVersion()Ljava/lang/String;

	at tinyb.BluetoothManager.getNativeAPIVersion(Native Method) ~[?:?]

	at tinyb.BluetoothManager.getBluetoothManager(BluetoothManager.java:304) ~[?:?]

	at org.openhab.binding.bluetooth.bluez.handler.BlueZBridgeHandler.initialize(BlueZBridgeHandler.java:68) ~[?:?]

	... 9 more


Looks like you havenā€™t setup the tinyb library properly yet. I donā€™t know if Iā€™ve posted a link for the new dbus-bluez jar yet. So give me a couple of minutes while I compile and upload it.

I decided to replace the tinyb version that I uploaded with the dbus version. Just download this new version and replace the one in your addons directory.

https://github.com/cpmeister/openhab-addons/raw/blind-engine-snapshots/org.openhab.binding.bluetooth.bluez-2.5.9.jar

Before you can run it you need to go into the openhab-cli and add the bluez-dbus-osgi bundle first:

bundle:install -s https://repo1.maven.org/maven2/com/github/hypfvieh/bluez-dbus-osgi/0.1.3/bluez-dbus-osgi-0.1.3.jar

After installing everything restart openhab.

restarted and finally i get Bluetooth Interface openhab at my inbox,add it as a thing and i get

2020-10-24 14:39:44.406 [hingStatusInfoChangedEvent] - 'bluetooth:bluez:hci0' changed from UNINITIALIZED to INITIALIZING

2020-10-24 14:39:44.444 [hingStatusInfoChangedEvent] - 'bluetooth:bluez:hci0' changed from INITIALIZING to UNKNOWN (CONFIGURATION_PENDING): Initializing

2020-10-24 14:39:49.068 [vent.ItemStateChangedEvent] - LGThinQDryer_LastSeen changed from 2020-10-24T14:38:48.491+0300 to 2020-10-24T14:39:49.033+0300

2020-10-24 14:39:49.536 [hingStatusInfoChangedEvent] - 'bluetooth:bluez:hci0' changed from UNKNOWN (CONFIGURATION_PENDING): Initializing to OFFLINE (COMMUNICATION_ERROR): Native adapter could not be found for address 'B8:27:EB:63:EF:FC'

huh, I donā€™t think I gave you the wrong address. It might be that the adapter wasnā€™t started yet.
If all else fails try running a manual bluetooth thing discovery from the inbox and see what adapter shows up. If no adapter shows up then confirm that the adapters are active through bluetoothctl.

my bluetooth and dbus services are active but no bluetooth adapter when i run sudo bluetoothctl.Then i saw that hciuart is down

[17:30:29] openhabian@openhab:~$ sudo systemctl start hciuart
Job for hciuart.service failed because the control process exited with error code.
See "systemctl status hciuart.service" and "journalctl -xe" for details.

clear cashe and reboot did the job,found adapter and several devices,thnx
Anyone manage to set up channels for miKettle?All i get is RSSI.

Can we use ESP32s to extend the scan range for this binding?

I do have plans in the works for adding support for a mqtt bluetooth adapter, which would allow the bluetooth binding to interact with remote bluetooth devices over mqtt. But as right now the binding doesnā€™t have that capability. That feature is likely a couple of months down the road.

I just finished adding basic support for unknown characteristics. Unknown characteristics display their data as raw binary in hexadecimal. You can write data to those characteristics with hexadecimal as well.
This feature still requires a bit of polish and I donā€™t have any of the safeguards that should normally be present (e.g. limiting input length). Iā€™ll continue work on this but at the very least users with unrecognized devices can begin play around a bit.

You can download these latest changes for the from the same links I posted prior:

1 Like

thanks testing!

OMG now I have problems with installing BLUEZ:

Error executing command: Error installing bundles:
Unable to start bundle https://github.com/cpmeister/openhab-addons/raw/blind-engine-snapshots/org.openhab.binding.bluetooth.bluez-2.5.9.jar: org.osgi.framework.BundleException: Could not resolve module: org.openhab.binding.bluetooth.bluez [343]
Unresolved requirement: Import-Package: com.github.hypfvieh.bluetooth; version="[0.1.0,1.0.0)"

UPDATE: installed from addons - OK

then uninstalled and reinstalled your bundle:
bundle:install -s https://repo1.maven.org/maven2/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar

still nothing but RSSI (connected device)

With the latest bluetooth jar you should definitely be seeing other channelsā€¦
Did you uninstall the official binding first?
If you are installing from the addons then you need to make sure that you also uninstall the official binding bundle in the openhab-cli.

Hi Connor, thanks for your work on the Bluetooth binding. When I install the Bluetooth binding from add-onā€™s on paperui I get the ā€œjni connection cannot be establishedā€ error for bluez.

This is resolved by using your bluetooth (https://github.com/cpmeister/openhab-addons/raw/blind-engine-snapshots/org.openhab.binding.bluetooth-2.5.9.jar) and bluetooth.bluez (https://github.com/cpmeister/openhab-addons/raw/blind-engine-snapshots/org.openhab.binding.bluetooth.bluez-2.5.9.jar) files.

With these installed however I didnā€™t see the extensions (like AM43, that I would like to use). Are these not included? I did get it to work eventually by installing the binding from paperui first. After uninstalling bluetooth and bluetooth.bluez in karaf I copied the jarā€™s into the addon dir and ended up with your binding including extensions. Would be great to have the ā€œrevivedā€ binding into openHAB stable including extensions and without dependency on tinyb.

Thx!

The new bluetooth.bluez extension has already been merged into the latest OH3 snapshot and will be available in the milestone 2 release. Iā€™m now in the process trying to get the ā€˜revivedā€™ binding merged as well. With luck it should get into M2 as well but Iā€™m still waiting on some changes in the core to add support for all of the units that bluetooth uses. That way the binding will use UoM like other bindings. Iā€™m going to put all my effort into developing the binding for OH3 so I donā€™t think Iā€™ll do any more binding updates for OH 2.5.

3 Likes

Thanks, that works for me, appreciate your work.

i followed all instructions and i discovered my Mikettle but it continuously altes between these states

and only RSSI channel is discovered ,am i doing something wrong or the binding is not ready for mi kettle yet?
thnx for ur hard work mate.

First of all THANKS FOR WORK AND EFFORT YOU PUT!!! butā€¦
It is bit of a mess with correct installation, why bluetooth binding canā€™t be uninstalled from paper ui and installed again with new work??? Why everything needs to be done through openhab-cli? Could you please write little note here on what and where needs to be done in order to get thing working.

P.S. I will try again to uninstall and install binding, but not sure it will work as already done this number of times.

Thanks for all the awesome work on this- Iā€™m very excited to try out the unknown characteristics functionality.

I downloaded the latest versions of the binding & bluez jars from your links and also ran the command further up the thread to install the bluez-dbus-osgi bundle and then restarted openHAB (actually, I restarted the pi/openhabian this is running on).

However, after the restart my Bluetooth BlueZ Adapter shows up in the PaperUI with ā€˜Offline- Communication Errorā€™ and I get a ā€˜Not Connectedā€™ stack trace in the openhab.log:

The error message indicates to check that bluetoothd is running. It does appear to be:
image

I then wondered if the bluez-dbus-osgi module wasnā€™t installed properly but it seems to show up:
image

I do notice this in daemon.log but this doesnā€™t appear to be a new error but maybe something about my bluetooth dbus setup has been broken for a while and because the old version of the binding used tinyb it didnā€™t impact me?

Any ideas what else might lead to the stack trace above or any ideas how I can debug further? Have I missed a step somewhere in the process? Am I missing some permissions?