-
Notifications
You must be signed in to change notification settings - Fork 780
Conversation
@cdjackson / @kaikreuzer I'm planning the look at https://github.com/openhab/openhab2-addons/pull/2491 to build in support of BLE there and see what I bump in to. Is it the idea that the bridge lives in the Bluetooth binding and the thing in the Miflora binding? |
Note, travis reports the following error, I suppose missing xml's because they are auto-generated, I'll include it while working on it.
|
@martinvw openhab/openhab2-addons#2491 would be cool :-)
I'll check why they are not generated during the Maven build. Your IDE should correctly generated those files. |
I would have hoped that the PR description already answers such questions :-) Just as some warning: This PR here is far from being merged, so if you look at openhab/openhab2-addons#2491 , please only do so in order to come up with improvements and suggestions for THIS PR here. Our efforts should be to collaborate on this and not already start too many specific device implementations on it. We should rather find some Bluetooth device that is a good candidate for initial support&testing. |
I did read and saw the same limitation so I wanted to validate my summary :-)
Yes will do
Do you mean device as in thing or device as in the bridge because I'm focussing now on a:
or optionally a connected toothbrush ;-) |
Devices as a thing like the Miflora. |
@@ -1,4 +1,13 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<!-- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be moved to a separate PR 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, removed it.
@martinvw Build issues are fixed. |
FTR, this is the architecture diagram that I had sketched out here and which has been followed in this PR: The missing part is the BlueZ-over-DBUS bundle - I'll try to add such to the PR as well (while I am not yet certain whether porting @cdjackson's implementation or betting on TinyB is the better choice for the start...) |
@cdjackson I have tried to port your BlueZ-over-DBUS code. The result is a skeleton that can be built on, but I learned that the code is really still in an early stage (especially wrt error handling) and that it also need heavy refactoring as the communication logic has to be moved out from the BlueZBluetoothGATT/Service/Characteristic/Descriptors to the Device and handler classes instead. I left the code in a state where everything compiles (and thus removed the communication logic from the old locations), but I haven't added an implementation to the BlueZBluetoothDevice and the BlueZBridgeHandler. Do you think you will find any time to look into finishing this code? Or shall we rather go for the TinyB library as an alternate BlueZ integration? |
|
||
<thing-type id="yeelight_blue2"> | ||
<supported-bridge-type-refs> | ||
<bridge-type-ref id="bluegiga"/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hurts on of the static code check:
[WARNING] .binding.miflora\ESH-INF\thing\miflora.xml:[0]
Missing the supported bridge with id bluegiga
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinvw Note that the yeelight binding is not o.esh.binding.yeelight
, but o.esh.binding.bluetooth.yeelight
- the same should be done for miflora, i.e. it would just be an extension bundle to the bluetooth binding - and as such have the "bluetooth" binding id.
But in any case you are right: "bluegiga" is not known in general, we will have to define an abstract bridge type that can be referenced by any extension, while having multiple implementations for it. This is not yet supported by the framework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we have one more challenge, the milfora binding strived to wrap both an mqtt connector and a bluetooth connector in a single binding (which feels good imho) in the end it would be great of that would be possible somehow...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
o.esh.binding.bluetooth.yeelight
But how can it be like that in openHAB...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's an interesting question indeed...
Probably best to directly contribute it to ESH :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hakan42 wdyt I intended to start from your openHAB miflora binding
@kaikreuzer what about the other question:
Then we have one more challenge, the milfora binding strived to wrap both an mqtt connector and a bluetooth connector in a single binding (which feels good imho) in the end it would be great of that would be possible somehow...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need to be able to reference bridges from another binding in that case - another feature that isn't yet supported by the framework.
But we would anyhow first need the MQTT bridge infrastructure in place as well. The according PR looks a bit stalled since September :-(.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@martinvw , feel free to take over the binding, I'd love if it started getting some proper love. Unfortunately, I am extremely swamped with work at the moment, so I won't be able to do much myself.
|
||
// Notify the user of the updated value | ||
if (characteristic != null) { | ||
notifyListeners(BluetoothEventType.CHARACTERISTIC_UPDATED, procedureCharacteristic); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdjackson this call pass null to the listener very often, can you agree with me that maybe passing characteristic
to the listeners might make more sense, or do I overlook some detail here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - you are right - this should be characteristic
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, but why does the if check for procedureCharacteristic
? Should that be changed to characteristic
as well? Or should it be an additional check?
5593a4b
to
17ccadb
Compare
I've made some improvements to this PR:
I will next go and extend the BlueZ bundle to also support proper pairing and service access on devices, so that custom device support bundles can be built on top. |
FTR: Currently, there still is an issue with the native TinyB libraries on a RaspPi when using Zulu JVM - with OracleJDK, it works as expected. |
Another update: I have split the "generic" thing type into "beacon" and "connected", so that both modes are supported out of the box by the core bluetooth binding. |
Battery level channel support has been added for "connected" devices and I have pushed quite some further improvements for the stability. |
Pushed another update with improvements. |
The battery service unfortunately is no longer accessible through the TinyB library with the most recent Bluez (v5.48): intel-iot-devkit/tinyb#131 |
@vkolotov Many thanks for the heads-up, that sounds like a very unfortunate bug/feature 😟 |
Also-By: Chris Jackson <[email protected]> Signed-off-by: Kai Kreuzer <[email protected]>
Signed-off-by: Kai Kreuzer <[email protected]>
I've now updated this PR to have just a diff commit on top of #4997. |
…ler disposal Signed-off-by: Kai Kreuzer <[email protected]>
@kaikreuzer As I see you have closed this PR. Actually we've been looking forward to use official bluetooth binding for a long time :) I would like to know about your roadmap about having a complete official bluetooth binding support in OH. |
@mronus Please note that there is already an official Bluetooth binding, which has been merged with #4997. |
This PR is a follow-up replacement of #3633. It includes heavy refactoring especially wrt discovery and lifecylcle. The namespace has also been changed from BLE to Bluetooth.
Overview
This provides an initial PR for a Bluetooth binding, with a BlueGiga USB adapter and a YeelightBlue device support implemented. It is still WIP.
Work to be completed
There is further testing, tidying and improving required.
Better connection management is needed to cope with disconnects. There is also some arbitration required in the BlueGiga handler to handle concurrency clashes between different thing handlers.
Bluetooth Binding overview
The Bluetooth binding is implemented to allow bundles to extend the main Bluetooth bundle in order to add new Bluetooth adapter as well as device support. This architecture means that such extension bundles must utilise the binding name
bluetooth
.A base class structure is defined in the org.eclipse.smarthome.binding.bluetooth bundle. This includes the main classes required to implement Bluetooth -:
Implementing a new Bluetooth Adapter bundle
Bluetooth adapters are modelled as a Bridge in ESH. The bridge handler provides the link with the Bluetooth hardware (eg a dongle, or system Bluetooth API). An adapter bundle needs to implement two main classes: the BridgeHandler which should implement BluetoothAdapter (any be registered as a service), and a ThingFactory, which is required to instantiate the handler.
The bridge handler must implement any functionality required to interface to the Bluetooth layer. It is responsible for managing the Bluetooth scanning, device discovery (ie the device interrogation to get the list of services and characteristics) and reading and writing of characteristics. The bridge needs to manage any interaction between the interface with any things it provides – this needs to account for any constraints that a interface may impose such that Things do not need to worry about any peculiarities imposed by a specific interface.
Classes such as BluetoothCharacteristic or BluetoothService may be extended to provide additional functionality to interface to a specific library if needed.
Implementing specific Bluetooth device support
A specific Bluetooth thing handler provides the functionality required to interact with a specific Bluetooth device. The new thing bundle needs to implement three main classes – a BluetoothDiscoveryParticipant, a ThingHandler and a ThingFactory, which is required to instantiate the handler.
Two fundamental communications methods can be employed in BLE – beacons, and connected mode. A Bluetooth thing handler can implement one or both of these communications. In practice, a connected mode Thing implementation would normally handle the beacons in order to provide as a minimum the RSSI data.
Thing Naming
To avoid naming conflicts with different Bluetooth bundles a strict naming policy for things and thing xml files is proposed. This should use the bundle name and the thing name, separated with an underscore - eg for the Yeelight binding Blue2 thing, the thing type is
yeelight_blue2
.Connected Mode Implementation
The connected mode BluetoothThingHandler needs to handle the following functionality
adapter
through which all communication is done.device.connect()
method to connect to the device. Once the device is connected, theBluetoothDeviceListener.onConnectionStateChange()
callback will be called.device.discoverServices()
method to discover all the BluetoothServices and BluetoothCharacteristics implemented by the device. Once this is complete, theBluetoothDeviceListener.onServicesDiscovered()
callback will be called.BluetoothDeviceListener.onCharacteristicReadComplete()
andBluetoothDeviceListener.onCharacteristicWriteComplete()
methods will be called on completion.BluetoothDeviceListener.onCharacteristicUpdate()
method to process any read responses or unsolicited updates of a characteristic value.Beacon Mode Implementation
The beacon mode thing handler needs to handle the following functionality:
adapter
through which all communication is done.BluetoothDeviceListener.onScanRecordReceived()
method to process the beacons. The notification will provide the current receive signal strength (RSSI), the raw beacon data, and various elements of generally useful beacon data is provided separately.Generic Bluetooth Device Support
The core Bluetooth binding already includes generic "beacon" and "connected" Bluetooth thing types. All devices for which no discovery participant defines a specific thing type are added to the inbox as a beacon device. The corresponding handler implementation (
BeaconBluetoothHandler
) uses Beacon mode and merely defines a channel for RSSI for such devices.The "connected" thing type can be used by manually defining a thing. The corresponding handler implementation (
ConnectedBluetoothHandler
) uses Connected mode and thus immediately connects to the device and reads its services. Common services are added as channels (t.b.d.).