Skip to content
simen edited this page Feb 8, 2017 · 3 revisions

1. Overview

zive is a Class that helps you create a ZigBee Application. With zive, you just need to prepare the ZCL Clusters of your ZigBee Application, and it will handle all ZCL messages automatically without the need to deal with by yourself.


2. Installation

$ npm install zive --save


3. Usage

Here is a quick example to show you how to create your ZigBee Application:

// Import the Zive Class
var Zive = require('zive');

// Prepare your endpoint information
var epInfo = {
        profId: 260,  // 'HA'
        devId: 257,   // 'dimmableLight'
        discCmds: []
    };

// Prepare your clusters and initialize with its attributes, access control flags, etc.
var Ziee = require('ziee'),
    ziee = new Ziee();

ziee.init('lightingColorCtrl', 'dir', ...);
ziee.init('lightingColorCtrl', 'attrs', ...);
ziee.init('lightingColorCtrl', 'acls', ...);
ziee.init('lightingColorCtrl', 'cmds', ...);

// New a zive instance to be your ZigBee Application
var zive = new Zive(epInfo, ziee);


4. APIs

Zive Class

Exposed by require('zive').



new Zive(epInfo, clusters)

Create a new instance of Zive class. This document will use zive to denote the instance of this class. A zive represents a ZigBee Application.

Arguments:

  1. epInfo (Object): Endpoint information. The following table shows the epInfo properties.
  2. clusters (Object): ZCL Clusters. Please refer to ziee for how to create clusters in your application.
Property Type Mandatory Description
profId Number required Profile ID
devId Number required Device ID
discCmds Array optional Discoverable Commands

Returns

  • (Object): zive

Example:

var Zive = require('zive'),
    Ziee = require('ziee');

var epInfo = {
        profId: 260,  // 'HA'
        devId: 257,   // 'dimmableLight'
        discCmds: []
    },
    ziee = new Ziee();

ziee.init(...);

var zive = new Zive(epInfo, ziee);



foundation(dstAddr, dstEpId, cId, cmd, zclData[, cfg], callback)

Send ZCL foundation command to another endpoint. Response will be passed through second argument of the callback.

Arguments:

  1. dstAddr (String | Number): Address of the destination device. dstAddr will be taken as an IEEE address if it is given with a string, or a network address if it is given with a number.
  2. dstEpId (Number): The endpoint id of the destination device.
  3. cId (String | Number): Cluster id, i.e. 'genBasic', 0, 'genOnOff', 6.
  4. cmd (String | Number): ZCL foundation command id, i.e. 'read', 0, 'discover', 12.
  5. zclData (Object | Array): ZCL data, which depends on the specified command. Please see ZCL Foundation Command Reference Tables for zclData format of different foundation command.
  6. cfg (Object): The following description shows the detail of cfg properties.
    • manufSpec (Number): Tells if this is a manufacturer-specific command. Default is 0.
    • direction (Number): Tells whether a command is sent from client-to-server (c2s) or from server-to-client (s2c). Default is 1 to send command from server-to-client.
    • disDefaultRsp (Number): Disable default response. Default is 0 to enable the default response.
  7. callback (Function): function (err, rsp) { }. Get called when receive the response of foundation command. Please refer to Payload in foundation command table to learn more about the rsp object.

Returns

  • (None)

Example:

zive.foundation(0x1234, 1, 'genBasic', 'read', [ { attrId: 3 }, { attrId: 4 } ], function (err, rsp) {
    if (!err)
        console.log(rsp);
// [
//     {
//         attrId: 3,     // hwVersion
//         status: 0,     // success
//         dataType: 32,  // uint8
//         attrData: 0
//     },
//     {
//         attrId: 4,     // manufacturerName
//         status: 0,     // success
//         dataType: 66,  // charStr
//         attrData: 'TexasInstruments'
//     }
// ]
});



functional(dstAddr, dstEpId, cId, cmd, zclData[, cfg], callback)

Send ZCL functional command to another endpoint. The response will be passed to the second argument of the callback.

Arguments:

  1. dstAddr (String | Number): Address of the destination device. dstAddr will be taken as an IEEE address if it is given with a string, or a network address if it is given with a number.
  2. dstEpId (Number): The endpoint id of the destination device.
  3. cId (String | Number): Cluster id.
  4. cmd (String | Number): ZCL functional command id.
  5. zclData (Object | Array): ZCL data, which depends on the specified command. Please see ZCL Functional Command Reference Table for zclData format of different functional command.
  6. cfg (Object): The following description shows the detail of cfg properties.
    • manufSpec (Number): Tells if this is a manufacturer-specific command. Default is 0.
    • direction (Number): Tells whether a command is sent from client-to-server (c2s) or from server-to-client (s2c). Default is 1 to send command from server-to-client.
    • disDefaultRsp (Number): Disable default response. Default is 0 to enable the default response.
  7. callback (Function): function (err, rsp) { }. Get called when receive the response of functional command. Please refer to Arguments in functional command table to learn more about the functional command rsp object.

Returns

  • (None)

Example:

zive.functional('0x00124b0001ce4beb', 1, 'lightingColorCtrl', 'moveHue', { movemode: 20, rate: 50 }, function (err, rsp) {
    if (!err)
        console.log(rsp);
// This example receives a 'defaultRsp'
// {
//     cmdId: 2,
//     statusCode: 0
// }
});