diff --git a/bundles/org.openhab.binding.bluetooth.generic/src/main/java/org/openhab/binding/bluetooth/generic/internal/GenericBluetoothHandler.java b/bundles/org.openhab.binding.bluetooth.generic/src/main/java/org/openhab/binding/bluetooth/generic/internal/GenericBluetoothHandler.java index c68f01b755449..644e23bf898f8 100644 --- a/bundles/org.openhab.binding.bluetooth.generic/src/main/java/org/openhab/binding/bluetooth/generic/internal/GenericBluetoothHandler.java +++ b/bundles/org.openhab.binding.bluetooth.generic/src/main/java/org/openhab/binding/bluetooth/generic/internal/GenericBluetoothHandler.java @@ -28,7 +28,9 @@ import org.openhab.binding.bluetooth.BluetoothBindingConstants; import org.openhab.binding.bluetooth.BluetoothCharacteristic; import org.openhab.binding.bluetooth.BluetoothDevice.ConnectionState; +import org.openhab.binding.bluetooth.BluetoothService; import org.openhab.binding.bluetooth.ConnectedBluetoothHandler; +import org.openhab.binding.bluetooth.notification.BluetoothScanNotification; import org.openhab.bluetooth.gattparser.BluetoothGattParser; import org.openhab.bluetooth.gattparser.BluetoothGattParserFactory; import org.openhab.bluetooth.gattparser.FieldHolder; @@ -57,7 +59,7 @@ * channels based off of a bluetooth device's GATT characteristics. * * @author Connor Petty - Initial contribution - * @author Peter Rosenberg - Use notifications + * @author Peter Rosenberg - Use notifications, add support for ServiceData * */ @NonNullByDefault @@ -159,6 +161,71 @@ public void onCharacteristicUpdate(BluetoothCharacteristic characteristic, byte[ getCharacteristicHandler(characteristic).handleCharacteristicUpdate(value); } + @Override + public void onScanRecordReceived(BluetoothScanNotification scanNotification) { + super.onScanRecordReceived(scanNotification); + + handleServiceData(scanNotification); + } + + /** + * Service data is specified in the "Core Specification Supplement" + * https://www.bluetooth.com/specifications/specs/ + * 1.11 SERVICE DATA + *
+ * Broadcast configuration to configure what to advertise in service data
+ * is specified in "Core Specification 5.3"
+ * https://www.bluetooth.com/specifications/specs/
+ * Part G: GENERIC ATTRIBUTE PROFILE (GATT): 2.7 CONFIGURED BROADCAST
+ *
+ * This method extracts ServiceData, finds the Service and the Characteristic it belongs
+ * to and notifies a value change.
+ *
+ * @param scanNotification to get serviceData from
+ */
+ private void handleServiceData(BluetoothScanNotification scanNotification) {
+ Map