-
Notifications
You must be signed in to change notification settings - Fork 6
Home
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.
$ npm install zive --save
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);
Exposed by require('zive')
.
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:
-
epInfo
(Object): Endpoint information. The following table shows theepInfo
properties. -
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);
Send ZCL foundation command to another endpoint. Response will be passed through second argument of the callback.
Arguments:
-
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. -
dstEpId
(Number): The endpoint id of the destination device. -
cId
(String | Number): Cluster id, i.e.'genBasic'
,0
,'genOnOff'
,6
. -
cmd
(String | Number): ZCL foundation command id, i.e.'read'
,0
,'discover'
,12
. -
zclData
(Object | Array): ZCL data, which depends on the specified command. Please see ZCL Foundation Command Reference Tables forzclData
format of different foundation command. -
cfg
(Object): The following description shows the detail ofcfg
properties.-
manufSpec
(Number): Tells if this is a manufacturer-specific command. Default is0
. -
direction
(Number): Tells whether a command is sent from client-to-server (c2s) or from server-to-client (s2c). Default is1
to send command from server-to-client. -
disDefaultRsp
(Number): Disable default response. Default is0
to enable the default response.
-
-
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 thersp
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'
// }
// ]
});
Send ZCL functional command to another endpoint. The response will be passed to the second argument of the callback.
Arguments:
-
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. -
dstEpId
(Number): The endpoint id of the destination device. -
cId
(String | Number): Cluster id. -
cmd
(String | Number): ZCL functional command id. -
zclData
(Object | Array): ZCL data, which depends on the specified command. Please see ZCL Functional Command Reference Table forzclData
format of different functional command. -
cfg
(Object): The following description shows the detail ofcfg
properties.-
manufSpec
(Number): Tells if this is a manufacturer-specific command. Default is0
. -
direction
(Number): Tells whether a command is sent from client-to-server (c2s) or from server-to-client (s2c). Default is1
to send command from server-to-client. -
disDefaultRsp
(Number): Disable default response. Default is0
to enable the default response.
-
-
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 commandrsp
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
// }
});