zigbeer / zigbee-shepherd

An open source ZigBee gateway solution with node.js.
MIT License
250 stars 89 forks source link

update short adress of a device in database.db if not status 205 #60

Closed picsou83 closed 5 years ago

picsou83 commented 5 years ago

Hi, Regularly end device changes its short network address.

example: in database.db end device 0x000d6ffffe105635 have short adress 21279 {"type":"Router","ieeeAddr":"0x000d6ffffe105635","nwkAddr":21279

the ZDO_NWK_ADDR_REQ command finds the new short address from the long address but how to update the database.db cc-znp:AREQ <-- SAPI:findDeviceConfirm, { searchtype: 1, searchkey: 38391, result: '0x000d6ffff e7c09ed' } 38391 is the new short adress

as long as the database is not updated we have a network error status 205 from zigbee shepherd command cc-znp:AREQ <-- AF:dataConfirm, { status: 205, endpoint: 1, transid: 1 } +836ms

Thanks for your ideas

picsou83 commented 5 years ago

I added in controller.js if SAPI:findDeviceConfirm (response of ZDO', 'nwkAddrReq' with new short addr) update database

and

I added in af.js, if cnf.status == 205 launch ZDO', 'nwkAddrReq' request it works to do with time

controller.js

    this.on('SAPI:findDeviceConfirm', function (data) {
        if(!data.result){
        return
        }
    var dev = this.getShepherd()._findDevByAddr(data.result);
    dev.update({ nwkAddr: data.searchkey });
    shepherd._devbox.maintain(function (err){ });
    });

af.js

} else if(cnf.status == 205){
              indirecter.handleTimeout()
               var IeeeAddr = dstEp.getIeeeAddr();
               af.controller.request('ZDO', 'nwkAddrReq', { ieeeaddr: IeeeAddr, reqtype: 0, startindex:1 });
            }