### Install cc-znp package Source: https://github.com/zigbeer/cc-znp/blob/master/README.md Command to install the cc-znp library via npm. ```bash $ npm install cc-znp --save ``` -------------------------------- ### Handle ready event Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Triggered when the initialization procedure is complete. ```js znp.on('ready', function () { console.log('Initialization completes.'); }); ``` -------------------------------- ### .init(spCfg, callback) Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Initializes the serial port connection to the CC253X SoC. ```APIDOC ## .init(spCfg, callback) ### Description Enables a serial port connecting to the CC253X SoC using the provided configuration. ### Parameters - **spCfg** (Object) - Required - Configuration object containing 'path' (String) and 'options' (Object). - **callback** (Function) - Required - Callback function executed with an error argument. ``` -------------------------------- ### Initialize cc-znp interface Source: https://github.com/zigbeer/cc-znp/wiki/Home Configure the serial port and initialize the ZNP interface to begin application operations. ```javascript var znp = require('cc-znp'); var spCfg = { path: '/dev/ttyUSB0', options: { baudrate: 115200, rtscts: true } }; znp.on('ready', function () { console.log('Initialization completes.'); // start to run your application }); znp.init(spCfg, function (err) { if (err) console.log(err); }); ``` -------------------------------- ### UTIL Commands Reference Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables A collection of utility commands for managing device information, network settings, and source matching in the Z-Stack ZNP interface. ```APIDOC ## UTIL Commands ### getDeviceInfo - **Type**: SREQ - **Arguments**: None - **Result**: { status, ieeeaddr, shortaddr, devicetype, devicestate, numassocdevices, assocdeviceslist } ### getNvInfo - **Type**: SREQ - **Arguments**: None - **Result**: { status, ieeeaddr, scanchannels, panid, securitylevel, preconfigkey } ### setPanid - **Type**: SREQ - **Arguments**: { panid } - **Result**: { status } ### setChannels - **Type**: SREQ - **Arguments**: { channels } - **Result**: { status } ### setSeclevel - **Type**: SREQ - **Arguments**: { securitylevel } - **Result**: { status } ### setPrecfgkey - **Type**: SREQ - **Arguments**: { preconfigkey } - **Result**: { status } ### callbackSubCmd - **Type**: SREQ - **Arguments**: { subsystemid, action } - **Result**: { status } ### keyEvent - **Type**: SREQ - **Arguments**: { keys, shift } - **Result**: { status } ### timeAlive - **Type**: SREQ - **Arguments**: None - **Result**: { seconds } ### ledControl - **Type**: SREQ - **Arguments**: { ledid, mode } - **Result**: { status } ### testLoopback - **Type**: SREQ - **Arguments**: { data } - **Result**: { data } ### dataReq - **Type**: SREQ - **Arguments**: { securityuse } - **Result**: { status } ### srcMatchEnable - **Type**: SREQ - **Arguments**: None - **Result**: { status } ### srcMatchAddEntry - **Type**: SREQ - **Arguments**: { addressmode, address, panid } - **Result**: { status } ### srcMatchDelEntry - **Type**: SREQ - **Arguments**: { addressmode, address, panid } - **Result**: { status } ### srcMatchCheckSrcAddr - **Type**: SREQ - **Arguments**: { addressmode, address, panid } - **Result**: { status } ### srcMatchAckAllPending - **Type**: SREQ - **Arguments**: { option } - **Result**: { status } ### srcMatchCheckAllPending - **Type**: SREQ - **Arguments**: None - **Result**: { status, value } ### addrmgrExtAddrLookup - **Type**: SREQ - **Arguments**: { extaddr } - **Result**: { nwkaddr } ``` -------------------------------- ### Send binary data with sendCmd Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Demonstrates equivalent ways to call the send method using different combinations of command types and subsystem identifiers. ```js // The following calls do the same thing znp.send('AREQ', 'SYS', 0, new Buffer([ 0 ])); znp.send('AREQ', 1, 0, new Buffer([ 0 ])); znp.send(2, 'SYS', 0, new Buffer([ 0 ])); znp.send(2, 1, 0, new Buffer([ 0 ])); ``` -------------------------------- ### Initialize Serial Port Connection Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Configures and opens the serial port connection to the CC253X SoC. ```js var znp = require('cc-znp'); var spCfg = { path: '/dev/ttyUSB0', options: { baudrate: 115200, rtscts: true } }; znp.init(spCfg, function (err) { if (err) console.log(err); }); ``` -------------------------------- ### UTIL API Commands Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Utility commands for address management, association, binding, ZCL key establishment, and GPIO control. ```APIDOC ## SREQ UTIL Commands ### Description Utility commands for managing network addresses, association tables, binding entries, ZCL key establishment, and GPIO pin states. ### Methods - addrmgrNwkAddrLookup: { nwkaddr } -> { extaddr } - apsmeLinkKeyDataGet: { extaddr } -> { status, seckey, txfrmcntr, rxfrmcntr } - apsmeLinkKeyNvIdGet: { extaddr } -> { status, linkkeynvid } - apsmeRequestKeyCmd: { partneraddr } -> { status } - assocCount: { startrelation, endrelation } -> { count } - assocFindDevice: { number } -> { device } - assocGetWithAddress: { extaddr, nwkaddr } -> { device } - bindAddEntry: { addrmode, dstaddr, dstendpoint, numclusterids, clusterids } -> { srcep, dstgroupmode, dstidx, dstep, numclusterids, clusterids } - zclKeyEstInitEst: { taskid, seqnum, endpoint, addrmode, extaddr } -> { status } - zclKeyEstSign: { inputlen, input } -> { status, key } - srngGen: {} -> { outrng } - gpioSetDirection: { port, bit, direction } -> { oldp0dir, oldp1dir, oldp2dir, p0dir, p1dir, p2dir } - gpioRead: {} -> { p0, p1, p2, p0dir, p1dir, p2dir } - gpioWrite: { port, bit, value } -> { oldp0, oldp1, oldp2, p0, p1, p2, p0dir, p1dir, p2dir } ``` -------------------------------- ### ZDO Management and Configuration Commands Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables A collection of ZDO SREQ commands for network management, link key handling, and device startup configuration. ```APIDOC ## ZDO Commands (SREQ) | Command | Method | Parameters | Response | | :--- | :--- | :--- | :--- | | ZDO_MGMT_LQI_REQ | mgmtLqiReq | { dstaddr, startindex } | { status } | | ZDO_MGMT_RTG_REQ | mgmtRtgReq | { dstaddr, startindex } | { status } | | ZDO_MGMT_BIND_REQ | mgmtBindReq | { dstaddr, startindex } | { status } | | ZDO_MGMT_LEAVE_REQ | mgmtLeaveReq | { dstaddr, deviceaddress, removechildren_rejoin } | { status } | | ZDO_MGMT_DIRECT_JOIN_REQ | mgmtDirectJoinReq | { dstaddr, deviceaddr, capinfo } | { status } | | ZDO_MGMT_PERMIT_JOIN_REQ | mgmtPermitJoinReq | { addrmode, dstaddr, duration, tcsignificance } | { status } | | ZDO_MGMT_NWK_UPDATE_REQ | mgmtNwkUpdateReq | { dstaddr, dstaddrmode, channelmask, scanduration, scancount, nwkmanageraddr } | { status } | | ZDO_MSG_CB_REGISTER | msgCbRegister | { clusterid } | { status } | | ZDO_MSG_CB_REMOVE | msgCbRemove | { clusterid } | { status } | | ZDO_STARTUP_FROM_APP | startupFromApp | { startdelay } | { status } | | ZDO_SET_LINK_KEY | setLinkKey | { shortaddr, ieeeaddr, linkkey } | { status } | | ZDO_REMOVE_LINK_KEY | removeLinkKey | { ieeeaddr } | { status } | | ZDO_GET_LINK_KEY | getLinkKey | { ieeeaddr } | { status, ieeeaddr, linkkeydata } | | ZDO_NWK_DISCOVERY_REQ | nwkDiscoveryReq | { scanchannels, scanduration } | { status } | | ZDO_JOIN_REQ | joinReq | { logicalchannel, panid, extendedpanid, chosenparent, parentdepth, stackprofile } | { status } | | ZDO_SET_REJOIN_PARAMETERS_REQ | setRejoinParametersReq | { backoffduration, scanduration } | { status } | ``` -------------------------------- ### Event Listeners Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Documentation for events emitted by the znp instance. ```APIDOC ### .on('ready', callback) Fired when the initialization procedure is complete. ### .on('close', callback) Fired when the serial port is closed. ### .on('data', callback) Fired when data is received. The callback receives a parsed object containing the packet structure and checksum. ### .on('AREQ', callback) Fired when an 'AREQ' message is received from the ZNP. The callback receives the message content. ``` -------------------------------- ### .request(subsys, cmdId, valObj, callback) Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Invokes TI Z-Stack Monitor and Test (MT) commands. ```APIDOC ## .request(subsys, cmdId, valObj, callback) ### Description Invokes specific Z-Stack Monitor and Test commands by subsystem and command ID. ### Parameters - **subsys** (Number | String) - Required - The subsystem identifier (e.g., 'SYS', 1). - **cmdId** (Number | String) - Required - The command identifier. - **valObj** (Object) - Required - Argument object for the command. - **callback** (Function) - Required - Callback function executed with (err, result) when the 'SRSP' is received. ``` -------------------------------- ### MAC Command Reference Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables A collection of MAC layer SREQ commands used to interface with the Z-Stack ZNP. ```APIDOC ## MAC_RESET_REQ ### Description Resets the MAC layer. ### Request Body - **setdefault** (boolean) - Required ### Response - **status** (integer) - Operation status ## MAC_DATA_REQ ### Description Sends a data packet via the MAC layer. ### Request Body - **destaddressmode** (integer) - Required - **destaddress** (string) - Required - **destpanid** (integer) - Required - **srcaddressmode** (integer) - Required - **handle** (integer) - Required - **txoption** (integer) - Required - **logicalchannel** (integer) - Required - **power** (integer) - Required - **keysource** (string) - Required - **securitylevel** (integer) - Required - **keyidmode** (integer) - Required - **keyindex** (integer) - Required - **msdulength** (integer) - Required - **msdu** (string) - Required ### Response - **status** (integer) - Operation status ## MAC_GET_REQ ### Description Retrieves a MAC attribute. ### Request Body - **attribute** (integer) - Required ### Response - **status** (integer) - Operation status - **data** (string) - Attribute value ``` -------------------------------- ### .sendCmd(type, subsys, cmdId, payload) Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Sends a binary command to the ZNP. This method wraps the Unpi send API. ```APIDOC ### .sendCmd(type, subsys, cmdId, payload) #### Description Sends a binary command to the ZNP. This method is an export of the Unpi send() API. #### Arguments - **type** (Number | String) - The command type (e.g., 'SREQ', 'AREQ', 1, 2). - **subsys** (Number | String) - The subsystem identifier (e.g., 'SYS', 'UTIL', 1, 7). - **cmdId** (Number) - The command ID specific to the subsystem. - **payload** (Buffer) - The data payload to send. #### Returns - **Buffer** - The built command packet. #### Example ```js znp.send('AREQ', 'SYS', 0, new Buffer([ 0 ])); ``` ``` -------------------------------- ### SAPI Commands Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Synchronous and Asynchronous requests for managing ZigBee device operations. ```APIDOC ## SAPI Commands ### systemReset - Type: AREQ - Arguments: {} - Result: none ### startRequest - Type: SREQ - Arguments: {} - Result: { status } ### permitJoiningRequest - Type: SREQ - Arguments: { destination, timeout } - Result: { status } ### bindDevice - Type: SREQ - Arguments: { action, commandid, destination } - Result: {} ### allowBind - Type: SREQ - Arguments: { timeout } - Result: {} ### sendDataRequest - Type: SREQ - Arguments: { destination, commandid, handle, txoptions, radius, payloadlen, payloadvalue } - Result: {} ### readConfiguration - Type: SREQ - Arguments: { configid } - Result: { status, configid, len, value } ### writeConfiguration - Type: SREQ - Arguments: { configid, len, value } - Result: { status } ### getDeviceInfo - Type: SREQ - Arguments: { param } - Result: { param, value } ### findDeviceRequest - Type: SREQ - Arguments: { searchKey } - Result: {} ``` -------------------------------- ### Use Request Shorthands Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Convenience methods for invoking commands on specific subsystems without passing the subsystem identifier. ```js // examples with shorthands znp.sysRequest('ping', {}, function (err, result) { console.log(result); // { capabilities: 121 } }); znp.utilRequest('setPanid', { panid: 0xFFFF }, function (err, result) { console.log(result); // { status: 0 } }); ``` -------------------------------- ### Invoke Z-Stack Monitor and Test Commands Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Executes commands against specific subsystems using either string identifiers or numeric IDs. ```js { "SYS": 1, "MAC": 2, "NWK": 3, "AF": 4, "ZDO": 5, "SAPI": 6, "UTIL": 7, "DBG": 8, "APP": 9 } ``` ```js // example of calling ping() from the subsystem 'SYS' znp.request('SYS', 'ping', {}, function (err, result) { if (err) console.log(err); else console.log(result); // { capabilities: 121 } }); // use numbered ids. The first 1 is subsystem 'SYS', and the second 1 is command 'ping' znp.request(1, 1, {}, function (err, result) { if (err) console.log(err); else console.log(result); // { capabilities: 121 } }); ``` -------------------------------- ### APP_USER_TEST Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Executes a user test command. ```APIDOC ## SREQ APP_USER_TEST ### Description Executes a user-defined test command. ### Arguments - **srcep** (uint8) - Source endpoint - **commandid** (uint8) - Command ID - **param1** (uint8) - Parameter 1 - **param2** (uint8) - Parameter 2 ### Response - **status** (uint8) - Status of the request ``` -------------------------------- ### ZDO_BIND_REQ Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Requests to bind two devices together. ```APIDOC ## ZDO_BIND_REQ ### Description Requests to bind two devices together. ### Method SREQ ### Request Body - **dstaddr** (hex) - Required - **srcaddr** (hex) - Required - **srcendpoint** (int) - Required - **clusterid** (hex) - Required - **dstaddrmode** (int) - Required - **addr_short_long** (hex) - Required - **dstendpoint** (int) - Required ### Response - **status** (int) - Status of the request ``` -------------------------------- ### AF Commands Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Synchronous request (SREQ) commands for the Application Framework (AF) layer. ```APIDOC ## AF_REGISTER (register) ### Description Registers an application endpoint. ### Arguments - endpoint, appprofid, appdeviceid, appdevver, latencyreq, appnuminclusters, appinclusterlist, appnumoutclusters, appoutclusterlist ### Result - status ## AF_DATA_REQUEST (dataRequest) ### Description Sends a data request to a destination address. ### Arguments - dstaddr, destendpoint, srcendpoint, clusterid, transid, options, radius, len, data ### Result - status ## AF_DATA_REQUEST_EXT (dataRequestExt) ### Description Sends an extended data request. ### Arguments - dstaddrmode, dstaddr, destendpoint, dstpanid, srcendpoint, clusterid, transid, options, radius, len, data ### Result - status ## AF_DATA_REQUEST_SRC_RTG (dataRequestSrcRtg) ### Description Sends a data request with source routing. ### Arguments - dstaddr, destendpoint, srcendpoint, clusterid, transid, options, radius, relaycount, relaylist, len, data ### Result - status ## AF_INTER_PAN_CTL (interPanCtl) ### Description Controls Inter-PAN communication. ### Arguments - cmd, data ### Result - status ## AF_DATA_STORE (dataStore) ### Description Stores data at a specific index. ### Arguments - index, length, data ### Result - status ## AF_DATA_RETRIEVE (dataRetrieve) ### Description Retrieves stored data. ### Arguments - timestamp, index, length ### Result - status, length, data ## AF_APSF_CONFIG_SET (apsfConfigSet) ### Description Sets APSF configuration for an endpoint. ### Arguments - endpoint, framedelay, windowsize ### Result - status ## apsfConfigGet ### Description Gets APSF configuration for an endpoint. ### Arguments - endpoint ### Result - framedelay, windowsize, nomean ## delete ### Description Deletes an endpoint configuration. ### Arguments - endpoint ### Result - status ``` -------------------------------- ### MAC Indication API Reference Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables A collection of MAC layer indications that can be received via the Z-Stack MT interface. ```APIDOC ## MAC Indication Reference | Command | Type | Name | Parameters | | :--- | :--- | :--- | :--- | | MAC_SCAN_CNF | AREQ | scanCnf | { status, ed, scantype, channelpage, unscannedchannellist, resultlistcount, resultlistmaxlength, resultlist } | | MAC_COMM_STATUS_IND | AREQ | commStatusInd | { status, srcaddrmode, srcaddr, dstaddrmode, dstaddr, devicepanid, reason, keysource, securitylevel, keyidmode, keyindex } | | MAC_START_CNF | AREQ | startCnf | { status } | | MAC_RX_ENABLE_CNF | AREQ | rxEnableCnf | { status } | | MAC_PURGE_CNF | AREQ | purgeCnf | { status, handle } | ``` -------------------------------- ### zllTlInd Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Indication event for ZLL Touchlink. ```APIDOC ## AREQ zllTlInd ### Description Indication received for ZLL Touchlink events. ### Data - **nwkaddr** (uint16) - Network address - **endpoint** (uint8) - Endpoint - **profileid** (uint16) - Profile ID - **deviceid** (uint16) - Device ID - **version** (uint8) - Version ``` -------------------------------- ### SYS_GET_TIME Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Retrieves the current system time. ```APIDOC ## SREQ SYS_GET_TIME ### Description Retrieves the current system time from the device. ### Method SREQ ### Request Body - None ### Response - **utc** (number) - UTC time - **hour** (number) - Hour - **minute** (number) - Minute - **second** (number) - Second - **month** (number) - Month - **day** (number) - Day - **year** (number) - Year ``` -------------------------------- ### SYS_RESET_IND Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Indication triggered upon system reset. ```APIDOC ## AREQ SYS_RESET_IND ### Description Asynchronous indication sent when the system resets. ### Method AREQ ### Response - **reason** (number) - Reset reason - **transportrev** (number) - Transport revision - **productid** (number) - Product ID - **majorrel** (number) - Major release - **minorrel** (number) - Minor release - **hwrev** (number) - Hardware revision ``` -------------------------------- ### ZDO SREQ Commands Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables A collection of ZDO synchronous request commands used for managing security, routing, and group configurations in the ZigBee network. ```APIDOC ## ZDO SREQ Commands ### Description These commands are synchronous requests (SREQ) used to interact with the ZigBee Device Object layer. ### Commands | Command | Request Parameters | Response Fields | | :--- | :--- | :--- | | ZDO_SEC_ADD_LINK_KEY | { shortaddr, extaddr, linkkey } | { status } | | ZDO_SEC_ENTRY_LOOKUP_EXT | { extaddr } | { status, ami, keynvid, authenticateoption } | | ZDO_SEC_DEVICE_REMOVE | { extaddr } | { status } | | ZDO_EXT_ROUTE_DISC | { dstAddr, options, radius } | { status } | | ZDO_EXT_ROUTE_CHECK | { dstaddr, rtstatus, options } | { status } | | ZDO_EXT_REMOVE_GROUP | { endpoint, groupid } | { status } | | ZDO_EXT_REMOVE_ALL_GROUP | { endpoint } | { status } | | ZDO_EXT_FIND_ALL_GROUPS_ENDPOINT | { endpoint } | { groups, grouplist } | | ZDO_EXT_FIND_GROUP | { endpoint, groupid } | { status, groupid, namelen, groupname } | | ZDO_EXT_ADD_GROUP | { endpoint, groupid, namelen, groupname } | { status } | | ZDO_EXT_COUNT_ALL_GROUPS | { } | { status } | | ZDO_EXT_RX_IDLE | { setflag, setvalue } | { status } | | ZDO_EXT_UPDATE_NWK_KEY | { dstaddr, keyseqnum, key } | { status } | | ZDO_EXT_SWITCH_NWK_KEY | { dstaddr, keyseqnum } | { status } | | ZDO_EXT_NWK_INFO | { } | { shortaddr, devstate, panid, parentaddr, extendedpanid, parentextaddr, channel } | | ZDO_EXT_SEC_APS_REMOVE_REQ | { parentaddr, nwkaddr, extaddr } | { status } | ``` -------------------------------- ### ZDO_EXT_SET_PARAMS Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Sets extended parameters for the ZDO layer. ```APIDOC ## SREQ extSetParams ### Description Sets extended parameters for the ZDO layer. ### Request Body - **usemulticast** (boolean) - Required ### Response - **status** (integer) - Status of the operation ``` -------------------------------- ### endDeviceTimeoutReq Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Requests a timeout for an end device. ```APIDOC ## SREQ endDeviceTimeoutReq ### Description Requests a timeout for an end device. ### Request Body - **parentaddr** (integer) - Required - **reqrimeout** (integer) - Required ### Response - **status** (integer) - Status of the operation ``` -------------------------------- ### ZDO_SIMPLE_DESC_REQ Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Requests the simple descriptor for a specific endpoint on a device. ```APIDOC ## ZDO_SIMPLE_DESC_REQ ### Description Requests the simple descriptor for a specific endpoint on a device. ### Method SREQ ### Request Body - **dstaddr** (hex) - Required - **nwkaddrofinterest** (hex) - Required - **endpoint** (int) - Required ### Response - **status** (int) - Status of the request ``` -------------------------------- ### nwkAddrOfInterestReq Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Requests the network address of interest. ```APIDOC ## SREQ nwkAddrOfInterestReq ### Description Requests the network address of interest. ### Request Body - **shortaddr** (integer) - Required - **nwkaddr** (integer) - Required - **cmd** (integer) - Required ### Response - **status** (integer) - Status of the operation ``` -------------------------------- ### DEBUG API Commands Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Debugging commands for setting thresholds and sending debug messages. ```APIDOC ## DEBUG Commands ### Description Commands used for system debugging, including setting component thresholds and sending debug strings. ### Methods - DEBUG_SET_THRESHOLD (SREQ): { componentid, threshold } -> { status } - DEBUG_MSG (AREQ): { length, string } -> _none_ ``` -------------------------------- ### .close([callback]) Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Closes the active serial port connection. ```APIDOC ## .close([callback]) ### Description Closes the currently opened serial port. ### Parameters - **callback** (Function) - Optional - Callback function executed with an error argument. ``` -------------------------------- ### MAC_SET_RX_GAIN_REQ Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Sets the receiver gain mode. ```APIDOC ## SREQ MAC_SET_RX_GAIN_REQ ### Description Sets the receiver gain mode for the device. ### Request Body - **mode** (integer) - Required - The gain mode to set. ### Response - **status** (integer) - The status of the request. ``` -------------------------------- ### ZDO_FORCE_CONCENTRATOR_CHANGE Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Forces a concentrator change in the network. ```APIDOC ## SREQ forceConcentratorChange ### Description Forces a concentrator change in the network. ### Request Body - Empty object `{}` ### Response - Empty object `{}` ``` -------------------------------- ### Handle close event Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Triggered when the serial port connection is closed. ```js znp.on('close', function () { console.log('The serialport is closed.'); }); ``` -------------------------------- ### ZDO_NWK_ADDR_REQ Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Requests the network address of a device given its IEEE address. ```APIDOC ## ZDO_NWK_ADDR_REQ ### Description Requests the network address of a device given its IEEE address. ### Method SREQ ### Request Body - **ieeeaddr** (hex) - Required - **reqtype** (int) - Required - **startindex** (int) - Required ### Response - **status** (int) - Status of the request ``` -------------------------------- ### sendData Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Sends data via the ZDO layer. ```APIDOC ## SREQ sendData ### Description Sends data via the ZDO layer. ### Request Body - **shortaddr** (integer) - Required - **transseq** (integer) - Required - **cmd** (integer) - Required - **len** (integer) - Required - **buf** (array) - Required ### Response - **status** (integer) - Status of the operation ``` -------------------------------- ### ZDO_IEEE_ADDR_REQ Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Requests the IEEE address of a device given its short network address. ```APIDOC ## ZDO_IEEE_ADDR_REQ ### Description Requests the IEEE address of a device given its short network address. ### Method SREQ ### Request Body - **shortaddr** (hex) - Required - **reqtype** (int) - Required - **startindex** (int) - Required ### Response - **status** (int) - Status of the request ``` -------------------------------- ### Handle AREQ event Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Triggered when an AREQ message is received from the ZNP, providing the message content. ```js { subsys: 'ZDO', ind: 'endDeviceAnnceInd', data: { srcaddr: 63536, nwkaddr: 63536, ieeeaddr: '0x00124b0001ce3631', capabilities: 142 } } ``` ```js znp.on('AREQ', function (msg) { console.log(msg); }); ``` -------------------------------- ### Handle data event Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Triggered when data is received, providing a parsed object containing the payload and checksum information. ```js { sof: 254, len: 6, type: 2, subsys: 1, cmd: 128, payload: , fcs: 193, // this is the checksum originated from the sender csum: 193 // this is the checksum calculated from the received binaries } ``` ```js znp.on('data', function (data) { console.log(data); // The parsed data }); ``` -------------------------------- ### AF Indications Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Asynchronous request (AREQ) indications for the Application Framework (AF) layer. ```APIDOC ## AF_DATA_CONFIRM (dataConfirm) ### Description Indicates the status of a data request. ### Data - status, endpoint, transid ## AF_REFLECT_ERROR (reflectError) ### Description Indicates a reflection error. ### Data - status, endpoint, transid, dstaddrmode, dstaddr ## AF_INCOMING_MSG (incomingMsg) ### Description Indicates an incoming message. ### Data - groupid, clusterid, srcaddr, srcendpoint, dstendpoint, wasbroadcast, linkquality, securityuse, timestamp, transseqnumber, len, data ## AF_INCOMING_MSG_EXT (incomingMsgExt) ### Description Indicates an extended incoming message. ### Data - groupid, clusterid, srcaddrmode, srcaddr, srcendpoint, srcpanid, dstendpoint, wasbroadcast, linkquality, securityuse, timestamp, transseqnumber, len, data ``` -------------------------------- ### APP_MSG Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Sends an application message to a specified destination endpoint and cluster. ```APIDOC ## SREQ APP_MSG ### Description Sends an application message to a destination address and endpoint. ### Arguments - **appendpoint** (uint8) - Source endpoint - **destaddress** (uint16) - Destination network address - **destendpoint** (uint8) - Destination endpoint - **clusterid** (uint16) - Cluster ID - **msglen** (uint8) - Length of the message - **message** (uint8[]) - Message payload ### Response - **status** (uint8) - Status of the request ``` -------------------------------- ### securitySetReq Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Sets a security attribute. ```APIDOC ## SREQ securitySetReq ### Description Sets a specific security attribute on the device. ### Request Body - **attribute** (integer) - Required - The attribute ID to set. - **attributevalue** (integer) - Required - The value to assign to the attribute. ### Response - **status** (integer) - The status of the request. ``` -------------------------------- ### SYS_SET_TX_POWER Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Sets the transmit power level. ```APIDOC ## SREQ SYS_SET_TX_POWER ### Description Sets the transmit power level for the device. ### Method SREQ ### Request Body - **level** (number) - Power level ### Response - **txpower** (number) - Current transmit power ``` -------------------------------- ### SYS_NV_READ Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Reads data from Non-Volatile memory. ```APIDOC ## SREQ SYS_NV_READ ### Description Reads a specific length of data from NV memory at a given offset. ### Method SREQ ### Request Body - **sysid** (number) - System ID - **itemid** (number) - Item ID - **subid** (number) - Sub ID - **offset** (number) - Offset - **len** (number) - Length ### Response - **status** (number) - Operation status - **len** (number) - Length of data read - **value** (array) - Data read ``` -------------------------------- ### securityGetReq Source: https://github.com/zigbeer/cc-znp/wiki/6.-Z-Stack-MT-API-Reference-Tables Retrieves a security attribute. ```APIDOC ## SREQ securityGetReq ### Description Retrieves a specific security attribute from the device. ### Request Body - **attribute** (integer) - Required - The attribute ID to retrieve. - **index1** (integer) - Required - First index parameter. - **index2** (integer) - Required - Second index parameter. ### Response - **status** (integer) - The status of the request. ``` -------------------------------- ### Close Serial Port Source: https://github.com/zigbeer/cc-znp/wiki/5.-APIs-and-Events Terminates the active serial port connection. ```js znp.close(function (err) { if (err) console.log(err); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.