zigbeer / zigbee-shepherd

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

Dynamic endpoint/profile mapping #27

Closed RobinBol closed 7 years ago

RobinBol commented 7 years ago

Hi all,

I am trying to create a generic fix for https://github.com/zigbeer/zigbee-shepherd/issues/26 which will not require the hardcoded endpoint switch (which will break implementation of other devices). My idea was to map an incoming ZCL: Report Attributes to the correct endpoint at this point in the code: https://github.com/zigbeer/zigbee-shepherd/blob/master/lib/components/af.js#L525. In order to find the correct endpoint on the controller we should be able to read the destination endpoint from the incoming message. I know it is present in the message, see this sniff:

Frame 15990: 48 bytes on wire (384 bits), 48 bytes captured (384 bits) on interface 0
IEEE 802.15.4 Data, Dst: 0x0000, Src: 0xc2c7
ZigBee Network Layer Data, Dst: 0x0000, Src: 0xc2c7
    Frame Control Field: 0x0248, Frame Type: Data, Discover Route: Enable, Security Data
    Destination: 0x0000
    Source: 0xc2c7
    Radius: 30
    Sequence Number: 100
    [Extended Source: SiliconL_ff:fe:23:21:20 (00:0b:57:ff:fe:23:21:20)]
    [Origin: 15422]
    ZigBee Security Header
ZigBee Application Support Layer Data, Dst Endpt: 0, Src Endpt: 1
    Frame Control Field: Data (0x40)
        .... ..00 = Frame Type: Data (0x0)
        .... 00.. = Delivery Mode: Unicast (0x0)
        ..0. .... = Security: False
        .1.. .... = Acknowledgement Request: True
        0... .... = Extended Header: False
    __Destination Endpoint: 0__
    Cluster: Level Control (0x0008)
    Profile: Home Automation (0x0104)
    Source Endpoint: 1
    Counter: 160
ZigBee Cluster Library Frame
    Frame Control Field: Cluster-specific (0x11)
        .... ..01 = Frame Type: Cluster-specific (0x1)
        .... .0.. = Manufacturer Specific: False
        .... 0... = Direction: Server
        ...1 .... = Disable Default Response: True
    Sequence Number: 10
    Command: Stop with OnOff (0x07)

However, it seems that the message does not arrive in zigbee-shepherd land, hence I can not replace the endpoint with the correct one (the mapping). I might miss something here, on what level in the zigbee stack does this incoming message gets assigned to the coordinators endpoint/profile combination?

Is this a viable approach or do you have other ideas?

RobinBol commented 7 years ago

I think I took a wrong approach regarding this issue. The coordinator should be able to configure routers and end devices to report to a specific endpoint (with the correct profile). The problem is that the Xiaomi devices do not respond to these bind requests, well, they respond successfully, but then do not change the destination endpoint on their attribute reports for example.

For others facing similar issues, for now we solved it by changing the profile on endpoint 1 to Home Automation (which is expected/the default of the Xiaomi devices). Therefore I'll close this issue.