Skip to content

openwebnet/rx-openwebnet

Repository files navigation

rx-openwebnet

Build Status Download

OpenWebNet Java client with RxJava, see also the documentation

Supported frames

  • WHO=1 Lighting Javadoc
  • WHO=2 Automation Javadoc
  • WHO=4 Heating Javadoc
  • WHO=16 SoundSystem Javadoc
  • WHO=17 Scenario Javadoc
  • WHO=18 EnergyManagement Javadoc
  • a single generic frame/message
  • a list of generic frames/messages

Setup

Add the dependency to build.gradle

repositories {
    jcenter()
}
dependencies {
    compile 'com.github.openwebnet:rx-openwebnet:2.1.1'
}

Examples

// connects to the default gateway
OpenWebNet simpleClient = OpenWebNet.newClient(OpenWebNet.defaultGateway("192.168.1.41"));

// requests status light 21
simpleClient
    .send(Lighting.requestStatus("21"))
    .map(Lighting.handleStatus(() -> System.out.println("ON"), () -> System.out.println("OFF")))
    .subscribe(System.out::println);

// connects to the gateway with domain and password
OpenWebNet client = OpenWebNet.newClient(OpenWebNet.gateway("vpn.home.it", 20000, "12345"));

// turns light 21 on    
client
    .send(Lighting.requestTurnOn("21"))
    .map(Lighting.handleResponse(() -> System.out.println("success"), () -> System.out.println("fail")))
    .subscribe(System.out::println);
    
// sends a list of generic frames/messages with a custom thread pool
ExecutorService executor = Executors.newSingleThreadExecutor();
OpenWebNet
    .newClient(OpenWebNet.gateway("192.168.1.41", 20000))
    .send(Arrays.asList(() -> "*#1*21##", () -> "*#1*22##"))
    .subscribeOn(Schedulers.from(executor))
    .doOnError(throwable -> System.out.println("ERROR " + throwable))
    .doAfterTerminate(() -> executor.shutdown())
    .subscribe(System.out::println, throwable -> {});

// turns light 21 on with a custom scheduler on Android
OpenWebNet
    .newClient(OpenWebNet.gateway("10.0.2.2", 20000))
    .send(Lighting.requestTurnOff("21"))
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .map(Lighting.handleResponse(() -> System.out.println("success"), () -> System.out.println("fail")))
    .subscribe(System.out::println, throwable -> {});
    

Development

export JAVA_HOME='/usr/lib/jvm/java-8-oracle'

./gradlew clean build

# verbose tests
./gradlew :lib:test --debug

# run example
./gradlew runOpenWebNetExample

# update javadocs
./gradlew copyJavaDoc

# publish javadoc
git subtree push --prefix javadoc origin gh-pages

# publish on bintray
./gradlew bintrayUpload

# list tasks
./gradlew tasks

# upgrade gradle version
./gradlew wrapper --gradle-version=4.6

# verify jar content
unzip lib/build/libs/lib-2.1.1.jar -d /tmp/openwebnet-jar

Command Line Interface

# build uber jar
./gradlew shadowJar

# show usage
java -jar lib/build/libs/openwebnet-2.1.1.jar

# example simple
java -jar lib/build/libs/openwebnet-2.1.1.jar \
  -h 192.168.1.41 \
  -f *#1*21##

# example complete
java -jar lib/build/libs/openwebnet-2.1.1.jar \
  --host "192.168.1.41" \
  --port 8080 \
  --password "12345" \
  --frame "*#1*21##"