diff --git a/lib/Af.js b/lib/Af.js index 94e9ed9..e678ae4 100644 --- a/lib/Af.js +++ b/lib/Af.js @@ -65,7 +65,7 @@ class Af extends EventEmitter { nextZclSeqNum() { seqNumber += 1; // seqNumber is a private var on the top of this module - if (seqNumber > 255 || seqNumber < 0) + if (seqNumber >= 253 || seqNumber < 0) seqNumber = 0; this._seq = seqNumber; @@ -110,12 +110,14 @@ class Af extends EventEmitter { const frameType = msg.zclMsg.frameCntl.frameType; zclDebug(`0x${msg.srcaddr.toString(16)}:${msg.srcendpoint}->0x00:${msg.dstendpoint} (${msg.zclMsg.seqNum}) ${msg.clusterid} ${frameType === 0 ? 'foundation' : 'functional'}(${msg.zclMsg.cmdId}) ${JSON.stringify(msg.zclMsg.payload)}`); - // for broadcast responses only - this.emit('ZCL:incomingMsg:' + msg.dstendpoint + ':' + msg.zclMsg.seqNum, msg); + if(msg.zclMsg.frameCntl.direction === 1) { + // for broadcast responses only + this.emit('ZCL:incomingMsg:' + msg.dstendpoint + ':' + msg.zclMsg.seqNum, msg); - // { groupid, clusterid, srcaddr, srcendpoint, dstendpoint, wasbroadcast, linkquality, securityuse, timestamp, transseqnumber, zclMsg } - this.emit('ZCL:incomingMsg:' + msg.srcaddr.toString(16) + ':' + msg.srcendpoint + ':' + msg.dstendpoint + ':' + msg.zclMsg.seqNum, msg); - this.emit('ZCL:incomingMsg:' + msg.srcaddr.toString(16) + ':' + msg.srcendpoint + ':' + msg.zclMsg.seqNum, msg); + // { groupid, clusterid, srcaddr, srcendpoint, dstendpoint, wasbroadcast, linkquality, securityuse, timestamp, transseqnumber, zclMsg } + this.emit('ZCL:incomingMsg:' + msg.srcaddr.toString(16) + ':' + msg.srcendpoint + ':' + msg.dstendpoint + ':' + msg.zclMsg.seqNum, msg); + this.emit('ZCL:incomingMsg:' + msg.srcaddr.toString(16) + ':' + msg.srcendpoint + ':' + msg.zclMsg.seqNum, msg); + } // Necessary, some IAS devices don't respect endpoints if (remoteEp) {