npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

zibase

v1.5.0

Published

A NodeJS API to ZiBase

Downloads

19

Readme

Build Status NPM version Dependency Status Coverage Status

NPM

zibase

A NodeJS API to ZiBase

Introduction

This module is a SDK to connect to a Zibase. Most of it should be working fine, as it is currently used in a real home automation installation. However, it has been tested so far only against a Zibase Classic.

This SDK is strongly inspired from the PHP SDK written by Benjamin Garel.

Installation

Install as a npm module:

npm install zibase

Usage

Use as a npm module:

var zibase = require('zibase');

Connection to a Zibase

In order to communicate with a Zibase it is necessary to connect to it by instanciating the ZiBase class. For this, the IP address zibaseIP and the credentials deviceId and token of the Zibase are needed.

var Zibase = new zibase.ZiBase(
                   zibaseIP,
                   deviceId,
                   token);

An optional callback parameter can be used to be notified once the Zibase has been recognized.

var Zibase = new zibase.ZiBase(
                   zibaseIP,
                   deviceId,
                   token,
                   function (err) {
                       if (err)
                           console.log(err);
                       else
                           console.log("Connection established.");
                   });

It will initialize a connexion to the Zibase, register the calling application as a client of the Zibase, letting the Zibase send its activity information to the client. The first message sent by the Zibase indicates that the registration was successful:

21/02/2016 20:32:51.929 <info> zibase.js:424 (ZiBase.processZiBaseData) Zapi linked to host IP=<zip>192.168.0.10</zip> UDP Port=<zudp>60580</zudp>

Descriptors

The descriptors of the Zibase are loaded when the ZiBase class is instanciated. They can be accessed through:

  • the ZiBase.descriptors member:
console.log(Zibase.descriptors);

will produce:

 [ { type: 'device',
    name: 'Ventilation SdB',
    t: 'receiverXDom',
    i: 'logotype_airfan.png',
    c: 'C3' },
  { type: 'device',
    name: 'Conso Wall Plug',
    t: 'power',
    i: 'logotype_power.png',
    c: 'PZA3' },
  { type: 'device',
    name: 'Pompe à Chaleur',
    t: 'receiverXDom',
    i: 'logotype_heatpomp.png',
    c: 'P7',
    p: '5' },
  { type: 'scenario',
    name: 'simulation intrusion',
    id: '9',
    icon: 'logoMacro_Portes.png' },
  { type: 'scenario',
    name: 'Notification iOS',
    id: '16',
    icon: 'logoMacro_Scenario.png' }
 ]
  • the ZiBase.getDescriptor(id) method:
console.log(Zibase.getDescriptor("P7"));

will produce:

{ type: 'device',
  name: 'Pompe à Chaleur',
  t: 'receiverXDom',
  i: 'logotype_heatpomp.png',
  c: 'P7',
  p: '5' }

Variables

The variables V0 to V31 can be read through ZiBase.getVariable:

Zibase.getVariable(10, function(err, value) {
    if (err)
        console.log(err);
    console.log("V10=" + value);
});

Devices

The state of devices can be retrieved through ZiBase.getState:

Zibase.getState("ZB5", function(err, value) {
    if (err)
        console.log(err);
    console.log("ZB5 state =" + value);
});

Sensors

The information about a sensor can be retrieved through ZiBase.getSensorInfo:

Zibase.getSensorInfo("OS439157578", function(err, value) {
    if (err)
        console.log(err);
    console.log("Infos =" + value);
});

Events

The activity of the Zibase is logged through tracer messages:

21/02/2016 22:00:48.955 <info> zibase.js:352 (ZiBase.processZiBaseData) Received radio ID (<rf>ZWAVE ZB5</rf> <dev>Low-Power Measure</dev> Total Energy=<kwh>121.4</kwh>kWh Power=<w>00</w>W Batt=<bat>Ok</bat>): <id>PZB5</id>

The ZiBase object is an event emitter that can call registered callbacks when receiving a given activity message. The supported events are:

  • message: this event is emitted each time the Zibase sends a message
  • change: this event is emitted each time the Zibase sends a message about a device
  • error: this event is emitted when a ZWAVE error message is sent by the Zibase
  • restart: this event is emitted when the Zibase is restarting
  • restarted: this event is emitted once the Zibase has restarted

Listening to events is done with on(event, id, callback), or once(event, id, callback) in which case the event is triggered only once.

The following code:

Zibase.on('change', "PZB5", function(msg){
     console.log(msg);
});

will produce the following output:

21/02/2016 21:36:20.553 <info> zibase.js:352 (ZiBase.processZiBaseData) Received radio ID (<rf>ZWAVE ZB5</rf> <dev>Low-Power Measure</dev> Total Energy=<kwh>121.4</kwh>kWh Power=<w>00</w>W Batt=<bat>Ok</bat>): <id>PZB5</id>
{ rf: 'ZWAVE ZB5',
  dev: 'Low-Power Measure',
  kwh: '121.4',
  w: '00',
  bat: 'Ok',
  id: 'PZB5' }

Deconnexion

When no more interaction with the Zibase is needed, it is recommended to deconnect from it thanks to deregisterListener().

Zibase.deregisterListener();

The effect of this call is to ask the Zibase to stop sending its information. It seems the Zibase can keep track of 4 clients only. When a fifth client is registered, it will replace the oldest one, hence causing a forced deregistration of the first client. When using a single client, it usually not a problem to not call deregisterListener(). However, when using several clients connected to a single Zibase, it is highly recommended to make the call, to avoid the others from being disconnected. A good practice is to use the following code:

function exitHandler() {
    Zibase.deregisterListener();
    console.log("Deregistered from Zibase.");
}

process.on('exit', exitHandler);
process.on('SIGINT', exitHandler);
process.on('uncaughtException', exitHandler);

Documentation

A more detailed JSDoc generated documentation can be found here.