Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
added initial code base for Blukii Bluetooth device support, mainly a…
Browse files Browse the repository at this point in the history
…s an example on how to deal with custom services/characteristics

Signed-off-by: Kai Kreuzer <[email protected]>
  • Loading branch information
kaikreuzer committed Jan 9, 2018
1 parent 8c8a2df commit 93d2da4
Show file tree
Hide file tree
Showing 13 changed files with 487 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.smarthome.binding.bluetooth.blukii</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<thing:thing-descriptions bindingId="bluetooth" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:thing="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0"
xsi:schemaLocation="http://eclipse.org/smarthome/schemas/thing-description/v1.0.0 http://eclipse.org/smarthome/schemas/thing-description-1.0.0.xsd">

<thing-type id="blukii_bts">
<supported-bridge-type-refs>
<bridge-type-ref id="bluegiga"/>
<bridge-type-ref id="bluez"/>
</supported-bridge-type-refs>

<label>Blukii Button</label>
<description>A Blukii Button</description>

<channels>
<channel id="rssi" typeId="rssi" />
<channel id="BATTERY_LEVEL" typeId="system.battery-level" />

<channel id="accelReport" typeId="blukii_accel_report" />
<channel id="accelX" typeId="blukii_accel">
<label>Acceleration X</label>
</channel>
<channel id="accelY" typeId="blukii_accel">
<label>Acceleration Y</label>
</channel>
<channel id="accelZ" typeId="blukii_accel">
<label>Acceleration Z</label>
</channel>
</channels>

<config-description>
<parameter name="address" type="text">
<label>Address</label>
<description>Bluetooth address in XX:XX:XX:XX:XX:XX format</description>
</parameter>
</config-description>

</thing-type>

<channel-type id="blukii_accel_report">
<item-type>Switch</item-type>
<label>Acceleration Reporting</label>
</channel-type>
<channel-type id="blukii_accel">
<item-type>Number</item-type>
<label>Acceleration</label>
<state readOnly="true"/>
</channel-type>

</thing:thing-descriptions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Blukii Binding
Bundle-SymbolicName: org.eclipse.smarthome.binding.bluetooth.blukii
Bundle-Vendor: Eclipse.org/SmartHome
Bundle-Version: 0.10.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ClassPath: .
Import-Package:
org.eclipse.jdt.annotation;resolution:=optional,
org.eclipse.smarthome.binding.bluetooth,
org.eclipse.smarthome.binding.bluetooth.discovery,
org.eclipse.smarthome.binding.bluetooth.notification,
org.eclipse.smarthome.config.core,
org.eclipse.smarthome.config.discovery,
org.eclipse.smarthome.core.common.registry,
org.eclipse.smarthome.core.library.types,
org.eclipse.smarthome.core.thing,
org.eclipse.smarthome.core.thing.binding,
org.eclipse.smarthome.core.thing.binding.builder,
org.eclipse.smarthome.core.thing.binding.firmware,
org.eclipse.smarthome.core.thing.type,
org.eclipse.smarthome.core.types,
org.slf4j
Service-Component: OSGI-INF/*.xml
Export-Package:
org.eclipse.smarthome.binding.bluetooth.blukii,
org.eclipse.smarthome.binding.bluetooth.blukii.handler
Bundle-ActivationPolicy: lazy
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This content is produced and maintained by the Eclipse SmartHome project.

* Project home: https://eclipse.org/smarthome/

== Declared Project Licenses

This program and the accompanying materials are made available under the terms
of the Eclipse Public License 2.0 which is available at
https://www.eclipse.org/legal/epl-2.0/.

== Source Code

https://github.com/eclipse/smarthome

== Copyright Holders

See the NOTICE file distributed with the source code at
https://github.com/eclipse/smarthome/blob/master/NOTICE
for detailed information regarding copyright ownership.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/*.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# YeeLightBlue Binding

_Give some details about what this binding is meant for - a protocol, system, specific device._

_If possible, provide some resources like pictures, a YouTube video, etc. to give an impression of what can be done with this binding. You can place such resources into a `doc` folder next to this README.md._

## Supported Things

_Please describe the different supported things / devices within this section._
_Which different types are supported, which models were tested etc.?_
_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._

## Discovery

_Describe the available auto-discovery features here. Mention for what it works and what needs to be kept in mind when using it._

## Binding Configuration

_If your binding requires or supports general configuration settings, please create a folder ```cfg``` and place the configuration file ```<bindingId>.cfg``` inside it. In this section, you should link to this file and provide some information about the options. The file could e.g. look like:_

```
# Configuration for the Philips Hue Binding
#
# Default secret key for the pairing of the Philips Hue Bridge.
# It has to be between 10-40 (alphanumeric) characters
# This may be changed by the user for security reasons.
secret=EclipseSmartHome
```

_Note that it is planned to generate some part of this based on the information that is available within ```ESH-INF/binding``` of your binding._

_If your binding does not offer any generic configurations, you can remove this section completely._

## Thing Configuration

_Describe what is needed to manually configure a thing, either through the (Paper) UI or via a thing-file. This should be mainly about its mandatory and optional configuration parameters. A short example entry for a thing file can help!_

_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._

## Channels

_Here you should provide information about available channel types, what their meaning is and how they can be used._

_Note that it is planned to generate some part of this based on the XML files within ```ESH-INF/thing``` of your binding._

## Full Example

_Provide a full usage example based on textual configuration files (*.things, *.items, *.sitemap)._

## Any custom content here!

_Feel free to add additional sections for whatever you think should also be mentioned about your binding!_
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
source..=src/main/java/
output..=target/classes
bin.includes=META-INF/,\
.,\
OSGI-INF/,\
ESH-INF/,\
NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.eclipse.smarthome.binding</groupId>
<artifactId>pom</artifactId>
<version>0.10.0-SNAPSHOT</version>
</parent>

<artifactId>org.eclipse.smarthome.binding.bluetooth.blukii</artifactId>

<name>Eclipse SmartHome Blukii Binding</name>
<packaging>eclipse-plugin</packaging>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2014,2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.smarthome.binding.bluetooth.blukii;

import java.util.UUID;

import org.eclipse.smarthome.binding.bluetooth.BluetoothBindingConstants;
import org.eclipse.smarthome.core.thing.ThingTypeUID;
import org.eclipse.smarthome.core.thing.type.ChannelTypeUID;

/**
* The {@link BlukiiBindingConstants} class defines common constants, which are
* used across the whole binding.
*
* @author Kai Kreuzer - Initial contribution
*/
public class BlukiiBindingConstants {

// List of all Thing Type UIDs
public static final ThingTypeUID THING_TYPE_BUTTON = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID,
"blukii_bts");

public final static String BLUKII_PREFIX = "blukii";

// Channel IDs
public final static String CHANNEL_ID_ACCELREPORT = "accelReport";
public final static String CHANNEL_ID_X = "accelX";
public final static String CHANNEL_ID_Y = "accelY";
public final static String CHANNEL_ID_Z = "accelZ";

// Channel types UIDs
public final static ChannelTypeUID CHANNEL_TYPE_UID_ACCEL_REPORT = new ChannelTypeUID(
BluetoothBindingConstants.BINDING_ID, "blukii_accel_report");
public final static ChannelTypeUID CHANNEL_TYPE_UID_ACCEL = new ChannelTypeUID(BluetoothBindingConstants.BINDING_ID,
"blukii_accel");

// Characteristics
public final static UUID CHAR_ACCEL_REPORT = UUID.fromString("0000feb1-0000-1000-8000-00805f9b34fb");
public final static UUID CHAR_ACCEL_X = UUID.fromString("0000feb3-0000-1000-8000-00805f9b34fb");
public final static UUID CHAR_ACCEL_Y = UUID.fromString("0000feb4-0000-1000-8000-00805f9b34fb");
public final static UUID CHAR_ACCEL_Z = UUID.fromString("0000feb5-0000-1000-8000-00805f9b34fb");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Copyright (c) 2014,2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.smarthome.binding.bluetooth.blukii.handler;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.smarthome.binding.bluetooth.BluetoothCharacteristic;
import org.eclipse.smarthome.binding.bluetooth.BluetoothDeviceListener;
import org.eclipse.smarthome.binding.bluetooth.ConnectedBluetoothHandler;
import org.eclipse.smarthome.binding.bluetooth.blukii.BlukiiBindingConstants;
import org.eclipse.smarthome.core.library.types.DecimalType;
import org.eclipse.smarthome.core.library.types.OnOffType;
import org.eclipse.smarthome.core.thing.ChannelUID;
import org.eclipse.smarthome.core.thing.Thing;
import org.eclipse.smarthome.core.types.Command;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The {@link BlukiiHandler} is responsible for handling commands, which are
* sent to one of the channels.
*
* @author Kai Kreuzer - Initial contribution and API
*/
public class BlukiiHandler extends ConnectedBluetoothHandler implements BluetoothDeviceListener {

private final Logger logger = LoggerFactory.getLogger(BlukiiHandler.class);

public BlukiiHandler(Thing thing) {
super(thing);
}

@Override
public void handleCommand(@NonNull ChannelUID channelUID, @NonNull Command command) {
super.handleCommand(channelUID, command);
if (channelUID.getId().equals(BlukiiBindingConstants.CHANNEL_ID_ACCELREPORT) && command instanceof OnOffType) {
BluetoothCharacteristic characteristic = device.getCharacteristic(BlukiiBindingConstants.CHAR_ACCEL_REPORT);
int[] value = command == OnOffType.ON ? new int[] { 1 } : new int[] { 0 };
characteristic.setValue(value);
device.writeCharacteristic(characteristic);
}
}

@Override
public void onServicesDiscovered() {
super.onServicesDiscovered();
BluetoothCharacteristic xAccel = device.getCharacteristic(BlukiiBindingConstants.CHAR_ACCEL_X);
BluetoothCharacteristic yAccel = device.getCharacteristic(BlukiiBindingConstants.CHAR_ACCEL_Y);
BluetoothCharacteristic zAccel = device.getCharacteristic(BlukiiBindingConstants.CHAR_ACCEL_Z);
activateChannel(xAccel, BlukiiBindingConstants.CHANNEL_TYPE_UID_ACCEL, BlukiiBindingConstants.CHANNEL_ID_X);
activateChannel(yAccel, BlukiiBindingConstants.CHANNEL_TYPE_UID_ACCEL, BlukiiBindingConstants.CHANNEL_ID_Y);
activateChannel(zAccel, BlukiiBindingConstants.CHANNEL_TYPE_UID_ACCEL, BlukiiBindingConstants.CHANNEL_ID_Z);
}

@Override
public void onCharacteristicUpdate(@NonNull BluetoothCharacteristic characteristic) {
super.onCharacteristicUpdate(characteristic);
if (characteristic.getUuid().equals(BlukiiBindingConstants.CHAR_ACCEL_REPORT)) {
OnOffType enabled = characteristic.getValue()[0] == 1 ? OnOffType.ON : OnOffType.OFF;
updateState(BlukiiBindingConstants.CHANNEL_ID_ACCELREPORT, enabled);
}
if (characteristic.getUuid().equals(BlukiiBindingConstants.CHAR_ACCEL_X)) {
Integer x = characteristic.getIntValue(BluetoothCharacteristic.FORMAT_SINT16, 0);
updateState(BlukiiBindingConstants.CHANNEL_ID_X, new DecimalType(x));
}
if (characteristic.getUuid().equals(BlukiiBindingConstants.CHAR_ACCEL_Y)) {
Integer y = characteristic.getIntValue(BluetoothCharacteristic.FORMAT_SINT16, 0);
updateState(BlukiiBindingConstants.CHANNEL_ID_Y, new DecimalType(y));
}
if (characteristic.getUuid().equals(BlukiiBindingConstants.CHAR_ACCEL_Z)) {
Integer z = characteristic.getIntValue(BluetoothCharacteristic.FORMAT_SINT16, 0);
updateState(BlukiiBindingConstants.CHANNEL_ID_Z, new DecimalType(z));
}
}
}
Loading

0 comments on commit 93d2da4

Please sign in to comment.