• This repository has been archived on 27/Mar/2024
  • Stars
    star
    144
  • Rank 255,590 (Top 6 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created almost 11 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Zigbee API for Java provides simple Java interface to ZigBee network.

Gitter Build Status Codacy Badge Coverage Status Download

ZigBee API for Java

ZigBee API for Java provides simple Java interface to ZigBee network. ZigBee API for Java version 3 can be used in embedded or gateway mode. In gateway mode a gateway process is run to provide simultaneous administrator shell access and JSON RPC interface to ZigBee network. ZigBee Gateway Client library can be used to connect to gateway. See 'Usage'-chapter for examples.

ZigBee API for Java is originally a fork of ZB4OSGI.

See also https://github.com/zsmartsystems/com.zsmartsystems.zigbee

Questions can be sent to the following email address: '[email protected]'.

Or you can contact team members directly:

(Contributors, please add yourself to the list if you wish to provide support.)

Chat

Gitter

Discussion Group

The URL to the discussion group: https://groups.google.com/d/forum/zigbee4java

FAQ

The URL to the FAQ: https://groups.google.com/d/forum/zigbee4java

Hardware

This library provides API to ZigBee network through CC2531 dongle.

NOTE: To support other dongles it is necessary to implement ZigBeeDongle interface.

Example hardware that can be controlled with zigbee4java:

  1. Philips Hue Bulb

Prerequisites

  1. Java 7
  2. Maven 3 and/or Gradle
  3. CC2531 dongle with USB serial / coordinator firmware. Flashing new firmware requires CCDEBUGGER hardware component.
  4. Second CC2531 dongle if you want to have cheap packet sniffer. There are probably better packet sniffers out there.

Buying Hardware

You need to buy the following items:

  1. http://www.ti.com/tool/cc2531emk (NOTE: Buy two if you want to use another as packet sniffer.)
  2. http://www.ti.com/tool/cc-debugger

Flashing Dongle

  1. Download and install Z-STACK-HOME from http://www.ti.com/tool/z-stack
  2. View CCDEBUGGER user guide: http://www.ti.com/lit/ug/swru197h/swru197h.pdf
  3. Flash CC2531ZNP-Pro-Secure_Standard.hex with Smart RF Studio included in Z-STACK-HOME.

Maven Repository

Serial-comm and zigbee4java dependencies can be found from the following repository for convenience.

<repositories>
    <repository>
        <id>jcenter-bintray</id>
        <name>bintray</name>
        <url>http://jcenter.bintray.com</url>
    </repository>
</repositories>

Building from Sources

Maven:

git clone https://github.com/tlaukkan/zigbee4java.git zigbee4java
cd zigbee4java
mvn clean install

Gradle:

NOTE: Gradle build is currently broken in 3.0.

git clone https://github.com/tlaukkan/zigbee4java.git zigbee4java
cd zigbee4java
gradlew clean build

Embedded Usage

Maven build dependencies:

<dependencies>
    <dependency>
      <groupId>org.bubblecloud.zigbee4java</groupId>
      <artifactId>zigbee-dongle-cc2531</artifactId>
      <version>3.x.x</version>
      <type>pom</type>
    </dependency>
    <dependency>
      <groupId>org.bubblecloud.zigbee4java</groupId>
      <artifactId>zigbee-serial-javase</artifactId>
      <version>3.x.x</version>
      <type>pom</type>
    </dependency>
</dependencies>

Gradle build dependencies:

dependencies
{
    compile 'org.bubblecloud.zigbee:zigbee-dongle-cc2531:3.x.x'
    compile 'org.bubblecloud.zigbee:zigbee-serial-javase:3.x.x'
}

Example:

final byte[] networkKey = null; // Default network key
final SerialPort port = new SerialPortImpl("COM5");
final ZigBeeDongle dongle = new ZigBeeDongleTiCc2531Impl(port, 4951, 11, networkKey, false);
final ZigBeeApiDongleImpl api = new ZigBeeApiDongleImpl(dongle, false);

api.startup();

final ZigBeeDevice device = api.getZigBeeDevices().get(3);

api.on(device);
Thread.sleep(1000);
api.color(device, 1.0, 0.0, 0.0, 1.0);
Thread.sleep(1000);
api.color(device, 0.0, 1.0, 0.0, 1.0);
Thread.sleep(1000);
api.color(device, 0.0, 0.0, 1.0, 1.0);
Thread.sleep(1000);
api.off(device);

api.shutdown();
port.close();

Gateway Usage

You can run ZigBee gateway as a separate process from command line and connect to it with ZigBee Gateway Client. ZigBee Gateway Client provides ZigBee API and console commands remotely.

Run server by building zigbee4java with maven and executing gateway shell script under zigbee-gateway-server.

Maven build dependencies:

<dependencies>
    <dependency>
      <groupId>org.bubblecloud.zigbee4java</groupId>
      <artifactId>zigbee-gateway-client</artifactId>
      <version>3.x.x</version>
      <type>pom</type>
    </dependency>
</dependencies>

Gradle build dependencies:

dependencies
{
    compile 'org.bubblecloud.zigbee:zigbee-gateway-client:3.x.x'
}

Example:

final ZigBeeGatewayClient api = new ZigBeeGatewayClient("http://127.0.0.1:5000/", "secret");

api.startup();

api.addCommandListener(new CommandListener() {
    @Override
    public void commandReceived(final Command command) {
        System.out.println(command);
    }
});

final ZigBeeDevice device = api.getZigBeeDevices().get(3);

api.on(device);
Thread.sleep(1000);
api.color(device, 1.0, 0.0, 0.0, 1.0);
Thread.sleep(1000);
api.color(device, 0.0, 1.0, 0.0, 1.0);
Thread.sleep(1000);
api.color(device, 0.0, 0.0, 1.0, 1.0);
Thread.sleep(1000);
api.off(device);

api.shutdown();

This is an example how to interface directly with ZCL commands to accept IAS zone enroll request:

if (command instanceof ZoneEnrollRequestCommand) {
    final ZoneEnrollRequestCommand request = (ZoneEnrollRequestCommand) command;
    final int remoteAddress = request.getSourceAddress();
    final int remoteEndPoint = request.getSourceEnpoint();
    final byte transactionId = request.getTransactionId();

    final ZoneEnrollResponseCommand response = new ZoneEnrollResponseCommand();
    response.setDestinationAddress(remoteAddress);
    response.setDestinationEndpoint(remoteEndPoint);
    response.setTransactionId(transactionId);
    response.setEnrollResponseCode(0);
    response.setZoneId(0);

    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                zigBeeApi.sendCommand(response);
            } catch (ZigBeeException e) {
                e.printStackTrace();
            }
        }
    }).start();
}

Kotlin example:

package org.bubblecloud.zikky

import org.bubblecloud.zigbee.v3.ZigBeeGatewayClient
import org.bubblecloud.zigbee.v3.zcl.protocol.command.ias.zone.ZoneStatusChangeNotificationCommand
import kotlin.concurrent.fixedRateTimer

fun main(args : Array<String>) {
    val api = ZigBeeGatewayClient("http://127.0.0.1:5000/", "secret")

    println("Zikky startup...")
    api.startup()
    println("Zikky startup.")

    onExit {
        println("Zikky shutdown...")
        api.shutdown()
        println("Zikky shutdown.")
    }

    val devices = api.devices.filter { it.label != null }.associateBy({it.label}, {it})
    val groups = api.groups.associateBy({it.label}, {it})

    val zone = devices["zone"]!!
    val lamps = groups["lamps"]!!

    var movement = false
    var lighting = false
    var changeTime = currentTime()

    api.addCommandListener {
        if (it is ZoneStatusChangeNotificationCommand) {
            val command: ZoneStatusChangeNotificationCommand = it

            if (command.sourceAddress == zone.networkAddress && command.sourceEnpoint == zone.endpoint) {
                val alarm1 = command.zoneStatus and (1 shl 0) > 0
                val alarm2 = command.zoneStatus and (1 shl 1) > 0
                movement = alarm1 || alarm2
                changeTime = currentTime()
                if (movement) {
                    println("Zone movement detected.")
                } else {
                    println("Zone movement not detected.")
                }
            }
        }
    }

    fixedRateTimer("Lighting timer", true, 0, 1000, {
        if (movement != lighting) {
            if (movement) {
                api.on(lamps)
                lighting = true
                changeTime = currentTime()
                println("Occupied, switched lamps on.")
            } else {
                if (currentTime() - changeTime > 15 * 60000) {
                    api.off(lamps)
                    lighting = false
                    changeTime = currentTime()
                    println("Unoccupied, switched lamps off.")
                }
            }
        }
    })

}

fun currentTime(): Long {
    return System.currentTimeMillis()
}

fun onExit(shutdownHook: () -> Unit) {
    Runtime.getRuntime().addShutdownHook(Thread(shutdownHook))
}

More API Examples

  1. ZigBeeGateway.java

Contributing

  1. Follow Google Java style: https://google.github.io/styleguide/javaguide.html
  2. Add unit tests for your commit if applicable / possible.
  3. Build before commit.
  4. Rebase instead of merge when pushing.
  5. Check that Travis CI build passes after pushing.
  6. Fix any issues in your commit found in Codacy analysis.

Releasing

Release can be done only from master branch by tagging the head revision with the following syntax:

{VERSION}-release-ready

For example:

3.0.0-release-ready

This will trigger a release build by the build agent.

More Repositories

1

vaadin-lazyquerycontainer

Lazy Query Container is a lazy loading container implementation for accessing data from business services.
Java
38
star
2

mono-uuid-generator

Mono Uuid Generator (Mug) is a library for generating all (3) types of UUIDs on Mono and is direct translation from Java Uuid Generator (JUG).
C#
14
star
3

aframe-arcade-controls-component

A-Frame Arcade Controls Component provides keyboard controls for walking, jumping and colliding on all meshes on scene.
JavaScript
11
star
4

aframe-three-color-gradient-shader

JavaScript
10
star
5

rust-ray-intersect-js

Ray intersect
Rust
7
star
6

aframe-tiny-terrain-component

A-Frame Tiny Terrain Component
JavaScript
7
star
7

aframe-atmosphere-component

A-Frame Atmosphere Sky Component
JavaScript
6
star
8

kotlin-machine-learning-shell

Machine learning functions for kotlin REPL shell based on deeplearning4j library.
Kotlin
6
star
9

kotlin-speech-api

Simple interface for speech using microphone and Google Cloud API.
Kotlin
4
star
10

code-reality

Code Reality framework enables building networked extended reality (XR) experiences with A-Frame.
TypeScript
3
star
11

naf-mesh-adapter

Networked A-Frame peer to peer mesh adapter.
JavaScript
2
star
12

reality-space

reality-space servers provide a shared space to store and transmit scene data between code-reality clients
TypeScript
2
star
13

babylonjs-kotlin

Kotlin bindings for BabylonJS.
Kotlin
2
star
14

aframe-asset-collection

Shell
2
star
15

resource-bundle-translation-site

Open source software for translating java language resource bundles on hard drive. These files can be pulled and pushed with git and cron.
Java
2
star
16

kotlin-web-vr

A Kotlin Web VR client-server framework.
JavaScript
1
star
17

lejos-nxj-room-rover

This repository contains projects related to Room Rover robot based on Lego Mindstorms NXT 2.0 parts and Lejos NXJ software.
Java
1
star
18

aframe-github-storage

A-Frame Github Storage provides WebSocket API for storing scene to github.
JavaScript
1
star
19

naf-mesh-server-peer

JavaScript
1
star
20

groom-code-review-site

Gnome Review Orb Of Magic a.k.a. Code Review Assist for Shrewd Humans
Java
1
star
21

boteelis

Java Robotics
Java
1
star
22

kui

Kotlin Web UI
Kotlin
1
star
23

aframe-typescript-boilerplate

TypeScript
1
star
24

webrtc-signaling

WebRTC signaling based on Node.js WebSocket server
JavaScript
1
star