I’m pleased to announce that a new binding for Bluetooth devices is available for betta testing. It was a long journey for me to build this binding - 1 year of hard work and 15k+ lines of code. Nevertheless this is just the beginning.
Here are the main use cases this binding supports:
Presence detection. Bluetooth devices can be monitored whether they are in range of a bluetooth adapter (or multiple bluetooth adapters). This feature makes it possible to detect if an object or a person enters or leaves a building or a room.
Indoor positioning. Location of a bluetooth device can be identified based on estimated distance between the device and adapters. This feature allows you to locate things (like your phone or keys) in your house or detect who exactly is in a room.
Comprehensive support for Bluetooth Low Energy (Bluetooth Smart) devices. If a bluetooth device supports the Bluetooth specification 4.0, then the standard GATT services and characteristics can be automatically recognized and corresponding thing channels be created for each GATT characteristic and its GATT fields. This feature allows you to connect Bluetooth Smart sensors and other bluetooth devices.
Custom built (non-standard) BLE bluetooth devices support. A custom built bluetooth device can be automatically recognized like a standard one by specifying a folder on the system disk with custom GATT service and characteristic definitions in XML files.
UPDATE #1:
When you start testing it, could you also please report success cases and your setup configuration (hardware, OS etc) just in two words, e.g. if everything goes ok so we know the success rate.
Also, you are welcome to suggest any improvements or even start your contribution. Any contribution would be greatly appreciated.
The ultimate goal: provide a comprehensive and integrated environment for building custom bluetooth devices (sensors) based on the Bluetooth binding, cheap $2 bluetooth board (nrf51822) and Mbed OS. This should bring an easy way to build your own wireless sensors for a very affordable price.
UPDATE #5:
Added the ultimate goal.
UPDATE #6:
I’m pleased to announce that v1.1 of the binding is available for testing. You will need to uninstall the binding via Eclipse MarketPlace and install it again (autoupdate is not working in MarketPlace). Current version is v1.1.
The following changes are included in the release:
The ultimate goal: provide a comprehensive and integrated environment for building custom bluetooth devices (sensors) based on the Bluetooth binding, cheap $2 bluetooth board (nrf51822) and Mbed OS. This should bring an easy way to build your own wireless sensors for a very affordable price.
UPDATE #7:
New release:
Adding support for Xiaomi MI Scales
General stability improvements
Bluegiga transport stability improvements
Performance improvements:
RSS and Estimated distance channels now are marked as “advanced” (they don’t get created automatically)
Adding a new configuration setting “RSS reporting rate” in the general binding configuration page to control how frequent RSS should be reported (this is needed to prevent excessive CPU load)
Versions:
Binding: 1.1.3
BlueGiga transport: 1.2.0
TinyB transport: 1.1.0
As per normal, you will have to uninstall (no need to uninstall TinyB as it has not been released) the binding and transports, restart OH and install them back again.
Please let me know how it goes. Any feedback will be appreciated.
UPDATE #8 (2018-05-18) :
New release:
Implemented authentication procedure
New configuration section in the device settings (Authentication)
Authentication via pin code
Automatic authentication via GATT specs
Some significant improvements for BluGiga transport
Performance improvements
Fixing memory leaks
General stability improvements
Added support for Minew Keyfinder - a new bluetooth tracker with button that can detect:
Updating documentation on how to use iphone and android devices for presence detection.
Creating a hybrid mobile app (iphone and android) to emulate BT beacon and keep BT advertisement always on
Implement a new transport binding that uses DBus directly without TinyB library to replace TinyB transport. This should improve stability for linux users.
bluez is already the newest version (5.43-2+rpt2+deb9u2).
[12:12:10] openhabian@openHABianPi:~$ sudo systemctl status bluetooth
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset
Active: active (running) since Tue 2018-01-09 01:22:26 MSK; 10h ago
Docs: man:bluetoothd(8)
Main PID: 494 (bluetoothd)
Status: "Running"
CGroup: /system.slice/bluetooth.service
└─494 /usr/lib/bluetooth/bluetoothd
Jan 09 01:22:26 openHABianPi systemd[1]: Starting Bluetooth service…
Jan 09 01:22:26 openHABianPi bluetoothd[494]: Bluetooth daemon 5.43
Jan 09 01:22:26 openHABianPi systemd[1]: Started Bluetooth service.
Jan 09 01:22:26 openHABianPi bluetoothd[494]: Starting SDP server
Jan 09 01:22:26 openHABianPi bluetoothd[494]: Bluetooth management interface 1.1
Jan 09 01:22:26 openHABianPi bluetoothd[494]: Failed to obtain handles for "Serv
Jan 09 01:22:26 openHABianPi bluetoothd[494]: Sap driver initialization failed.
Jan 09 01:22:26 openHABianPi bluetoothd[494]: sap-server: Operation not permitte
lines 1-17/17 (END)
● bluetooth.service - Bluetooth service
Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-01-09 01:22:26 MSK; 10h ago
Docs: man:bluetoothd(8)
Main PID: 494 (bluetoothd)
Status: "Running"
CGroup: /system.slice/bluetooth.service
└─494 /usr/lib/bluetooth/bluetoothd
Jan 09 01:22:26 openHABianPi systemd[1]: Starting Bluetooth service…
Jan 09 01:22:26 openHABianPi bluetoothd[494]: Bluetooth daemon 5.43
Jan 09 01:22:26 openHABianPi systemd[1]: Started Bluetooth service.
Jan 09 01:22:26 openHABianPi bluetoothd[494]: Starting SDP server
Jan 09 01:22:26 openHABianPi bluetoothd[494]: Bluetooth management interface 1.14 initialized
Jan 09 01:22:26 openHABianPi bluetoothd[494]: Failed to obtain handles for “Service Changed” characteristic
Jan 09 01:22:26 openHABianPi bluetoothd[494]: Sap driver initialization failed.
Jan 09 01:22:26 openHABianPi bluetoothd[494]: sap-server: Operation not permitted (1)
~
~
~
~
~
~
Here is what happens with TinyB
2018-01-09 12:16:43.944 [ERROR] [th.manager.impl.BluetoothManagerImpl] - Adapter discovery job error
at tinyb.BluetoothManager.getNativeAPIVersion(Native Method) ~[235:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.0.0]
at tinyb.BluetoothManager.getBluetoothManager(BluetoothManager.java:304) [235:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.0.0]
at org.sputnikdev.bluetooth.manager.transport.tinyb.TinyBFactory.getDiscoveredAdapters(TinyBFactory.java:121) [235:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.0.0]
at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerImpl$AdapterDiscoveryJob.discoverAdapters(BluetoothManagerImpl.java:538) [236:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth:1.0.0]
at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerImpl$AdapterDiscoveryJob.run(BluetoothManagerImpl.java:531) [236:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth:1.0.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]Preformatted text
I am running on Ubuntu 17.10 x64, with a Broadcom BCM20702A1 USB adapter, with bluez version 5.46 (if there’s anything else you need to know, please ask - I’m a bit of a linux newbie so just let me know any commands you would like the output from)
I have been able to get the adapter running, detected in the Inbox and have added it as a Thing, but it is not detecting any bluetooth devices, either automatically, or via a manual scan.
Edit: I just wasn’t close enough to the adapter… my walls are obviously thicker than I thought! It’s found my phone OK
Item Linking only in Simple Mode ? Is it possible to link manually my Items?
My Bluetooth Devices arrives Tomorrow, the Binding comes @ the right time … first a planned to used a Raspberry to track … but the Binding takes it all in one
Solved with this
Edit Bluez DBus config to add a permission to access Bluez for the bluetooth group (/etc/dbus-1/system.d/bluetooth.conf):
…
…
Add openhab user to the bluetooth group:
sudo usermod -a -G bluetooth openhab
Reload service definitions:
sudo systemctl daemon-reload
Restart bluez:
sudo systemctl restart bluetooth
I have a question. I use Windows and want to be able to recognize “Bluetooth Classic” (=BR/EDR) as well. But if I understand your matrix correctly, this will only work with linux. Correct?
Generic BlueGiga
Windows - Y
Linux Y Y
Mac - Y
X86 32bit Y Y
X86 64bit Y Y
ARM v6 (Raspberry PI) Y Y
Adapters autodiscovery Y Y
Adapter aliases Y -
Device aliases Y -
BLE devices support Y Y
BR/EDR devices support (legacy BT) Y -
So, under Windows, all my BT devices must have at least 4.0 (BLE)?
If I buy a BlueGiga, do I have to deactivate my embedded BT adapter?
EDIT: If I buy a “Silicon Labs BlueGiga BLED112-V1”, do they all have the same specifications or are there models without BGAPI support?
It looks like it does not work so well with the iphone. After adding the item, the item also goes online, but after 30 seconds of timeout it immediately goes offline again, although it still exists. After turning Bluetooth on and off (iphone), the item stays offline.
I think the bluetooth of the iphone does not permanently send a sign of life, but that’s actually the strength of Bluetooth LE?
Tomorow my Bluetooth Tags arrives … I think thats the better Solution for Presence and worked better because they all-time visible
To get it worked with iPhone or other Devices that not all-time visible for Pairing … I think they must be paired with they Bluetooth Apdater … but thats the next Problem… the RaspberryPi seen not to provide any Profile that worked with iPhone Perhaps we can adapt an Profile eg. Audio … but than connects the iPhone Audio to raspberry … thats no solution I think
But I also have too little idea of the whole, these are all just guesses
16:42:52.918 [INFO ] [smarthome.event.ItemStateChangedEvent] - IPhone7_Location changed from NULL to Bluetooth Adapters
16:42:53.003 [INFO ] [smarthome.event.ItemStateChangedEvent] - IPhone7_LastUpdated changed from NULL to 2018-01-09T14:58:12.445+0100
16:42:56.099 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "DFU Control Point" does not have either Value or Fields tags, therefore reading the such characteristic will not be possible.
16:42:56.115 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "DFU Packet" does not have either Value or Fields tags, therefore reading the such characteristic will not be possible.
16:42:56.601 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "Bond Management Control Point" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([Conditional]) write ([Conditional]).
16:42:56.728 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "CGM Measurement" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([C3]) write ([C3, C1, C2]).
16:42:56.743 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "CGM Session Run Time" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([C1]) write ([C1]).
16:42:56.759 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "CGM Session Start Time" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([C1]) write ([C1]).
16:42:56.794 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "CGM Specific Ops Control Point" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([C1]) write ([C1]).
16:42:56.811 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "CGM Status" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([C1]) write ([C1]).
16:42:56.888 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "Cycling Power Control Point" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([Optional, C1, C2]) write ([Optional, C1, C2]).
16:42:56.955 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "Cycling Power Measurement" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([C3, C4, C5, Optional, C1, C2]) write ([C3, C4, C5, Optional, C1, C2]).
16:42:56.986 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "Cycling Power Vector" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([Optional, C1, C2]) write ([Optional, C1, C2]).
16:42:57.091 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "Descriptor Value Changed" does not have either Value or Fields tags, therefore reading the such characteristic will not be possible.
16:42:57.795 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "LN Control Point" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([Optional, C1, C2]) write ([Optional, C1, C2]).
16:42:57.877 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "Location and Speed Characteristic" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([Optional, C1]) write ([Optional, C1]).
16:42:58.432 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "Navigation" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([Optional]) write ([Optional]).
16:42:58.458 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "Object Action Control Point" does not have either Value or Fields tags, therefore reading the such characteristic will not be possible.
16:42:58.468 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "Object Changed" does not have either Value or Fields tags, therefore reading the such characteristic will not be possible.
16:42:58.799 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "Position Quality" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([Optional]) write ([Optional]).
16:42:58.996 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "SC Control Point" is not valid neither for read nor for write operation due to unfulfilled requirements: read ([C3, C1, C2]) write ([C3, C1, C2]).
16:42:59.183 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "TDS Control Point" does not have either Value or Fields tags, therefore reading the such characteristic will not be possible.
16:42:59.414 [WARN ] [spec.BluetoothGattSpecificationReader] - Characteristic "User Control Point" does not have either Value or Fields tags, therefore reading the such characteristic will not be possible.
16:42:59.690 [INFO ] [ome.event.ThingStatusInfoChangedEvent] - 'bluetooth:generic:XXXXXXXXXXXX' changed from UNINITIALIZED to INITIALIZING
16:42:59.744 [WARN ] [e.core.thing.binding.BaseThingHandler] - BaseThingHandler.initialize() will be removed soon, ThingStatus can be set manually via updateStatus(ThingStatus.ONLINE)
@None_No, I’m glad you have resolved your issue. Unfortunately there are so many moving parts in the Bluetooth world, the Bluetooth binding consists of 80% of code that it responsible for making it more stable…
I’ve installed the TinyB transport bundle along with the binding.
Downloaded and built BlueZ from sources on my Raspberry Pi 3.
Followed the whole tutorial.
But still I’m receiving the following errors constantly:
2018-01-09 19:47:01.901 [ERROR] [th.manager.impl.BluetoothManagerImpl] - Adapter discovery job error
java.lang.RuntimeException: Error getting object manager client: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 2 matched rules; type="method_call", sender=":1.103" (uid=109 pid=27533 comm="/usr/bin/java -Dopenhab.home=/usr/share/openhab2 -") interface="org.freedesktop.DBus.ObjectManager" member="GetManagedObjects" error name="(unset)" requested_reply="0" destination=":1.6" (uid=0 pid=24888 comm="/usr/libexec/bluetooth/bluetoothd ")
at tinyb.BluetoothManager.getNativeAPIVersion(Native Method) ~[269:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.0.0]
at tinyb.BluetoothManager.getBluetoothManager(BluetoothManager.java:304) [269:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.0.0]
at org.sputnikdev.bluetooth.manager.transport.tinyb.TinyBFactory.getDiscoveredAdapters(TinyBFactory.java:121) [269:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.0.0]
at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerImpl$AdapterDiscoveryJob.discoverAdapters(BluetoothManagerImpl.java:538) [270:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth:1.0.0]
at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerImpl$AdapterDiscoveryJob.run(BluetoothManagerImpl.java:531) [270:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth:1.0.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]
2018-01-09 19:47:07.043 [ERROR] [th.manager.impl.BluetoothManagerImpl] - Device discovery job error
java.lang.RuntimeException: Error getting object manager client: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 2 matched rules; type="method_call", sender=":1.104" (uid=109 pid=27533 comm="/usr/bin/java -Dopenhab.home=/usr/share/openhab2 -") interface="org.freedesktop.DBus.ObjectManager" member="GetManagedObjects" error name="(unset)" requested_reply="0" destination=":1.6" (uid=0 pid=24888 comm="/usr/libexec/bluetooth/bluetoothd ")
at tinyb.BluetoothManager.getNativeAPIVersion(Native Method) ~[269:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.0.0]
at tinyb.BluetoothManager.getBluetoothManager(BluetoothManager.java:304) [269:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.0.0]
at org.sputnikdev.bluetooth.manager.transport.tinyb.TinyBFactory.getDiscoveredDevices(TinyBFactory.java:127) [269:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth.transport.tinyb:1.0.0]
at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerImpl$DeviceDiscoveryJob.discoverDevices(BluetoothManagerImpl.java:503) [270:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth:1.0.0]
at org.sputnikdev.bluetooth.manager.impl.BluetoothManagerImpl$DeviceDiscoveryJob.run(BluetoothManagerImpl.java:496) [270:org.sputnikdev.org.eclipse.smarthome.binding.bluetooth:1.0.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
at java.lang.Thread.run(Thread.java:748) [?:?]
Yes, unfortunately BlueGiga dongles can only work with BLE enabled devices. However, there is a workaround if you are planning to use your phone with the Bluetooth binding. You can install a Bluetooth Beacon app that should force you phone to start advertising BLE packets, so that the Bluetooth Binding should start recognising your phone as a BLE enabled device.
No, you don’t have to deactivate your embedded/internal BT adapter. Furthermore, if you are running linux, you can use both types of adapters simultaneously.