niolabs / python-xbee

Python tools for working with XBee radios
MIT License
101 stars 45 forks source link

ZigBee / Digimesh 16 vs 64 bit destination address default values? #8

Closed hornc closed 8 years ago

hornc commented 8 years ago

Hi,

I'm using Series 1 XBees with Digimesh 2.4 firmware (VR=8073) and successfully using them via the ZigBee object (thanks for the recent documentation update! ;) )

There is one niggle I'm trying to work out though: the ZigBee object requires both a dest_addr_long (64 bit) and a dest_addr (16 bit) as there are no defaults provided. https://github.com/nioinnovation/python-xbee/blob/master/xbee/zigbee.py#L54

For my Digimesh xbees, the 16bit dest_addr seems to be ignored completely (which is in accordance with the digimesh Transmit Frame docs)

Cross referencing the ZigBee and Digimesh docs, it looks like the Digimesh protocol has marked the old 16bit address field as RESERVED Set to 0xFFFE

The ZigBee spec has "Set to the 16-bit address of the destination device, if known. Set to 0xFFFE if the address is unknown, or if sending a broadcast."

Would there be any issues with setting the default for the 16 bit addr to 0xFFFE? That would save Digmesh users having to explicitly set it to an arbitrary value. Not sure if it has any negative implications for ZigBee users though? I notice the ZigBee remote_at command has defaults set for both addresses: https://github.com/nioinnovation/python-xbee/blob/master/xbee/zigbee.py#L45

Alternatively, having a tx_long_addr available for ZigBee/Digimesh, like at https://github.com/nioinnovation/python-xbee/blob/master/xbee/ieee.py#L52 would help avoid having to set the 16bit addr.

I'm happy to raise a PR, but wanted to check whether a default 16bit addr of 0xFFFE makes sense. I imagine ZIgBee users might get frustrated having to enter both addresses too, should there be a default 64bit address also?

Thanks!

hansmosh commented 8 years ago

Thanks, I see the PR. I took over this repo fairly recently and have very little experience with digimesh so please bear with me.

So you're using 64 bit addresses and need to set the 16-bit address to the "unknown address"? That makes sense to me according to what I'm reading here: https://docs.digi.com/display/XBeeZigBeeMeshKit/Data+transmission

Given that, 0xFFFE looks like an appropriate default value. Can you think of any good reason the previous owner of this repo added defaults for remote_at commands but none of the others? It seems to me that if you're going to add a default to tx, might as well add it to tx_explicit too.

As for the default 64 bit addr. I'll propose another question about the existing code to you: do you have an idea why dest_addr_long for remote_at is struct.pack('>Q', 0) (i.e. \x00\x00\x00\x00\x00\x00\x00\x00)? This is neither the 64 bit "broadcast address" nor the "unknown address". (again, referring to this doc: https://docs.digi.com/display/XBeeZigBeeMeshKit/Data+transmission). I have had success with remote_at commands with xbee, leaving the dest_addr_long untouched, so I suppose the default is working.

tl;dr It feels wrong only adding a default dest_addr without a default dest_addr_long. Let's see if we can find the appropriate default for that too. And possible apply these defaults to the other api commands as well.

hornc commented 8 years ago

Thanks for the response!

I’m looking at the Digi docs for ZigBee here http://ftp1.digi.com/support/documentation/90002002.pdf and comparing them to the Digimesh version here: http://www.digi.com/resources/documentation/digidocs/pdfs/90000991.pdf

I’ve checked the ZigBee document again and realised I missed the 0xFFFFFFFFFFFFFFFF 64-bit unknown address mentioned in your link because it doesn’t appear in the API Frame specification section for the ZigBee Transmit and Explicit Addressing ZigBee Command Frame (pages 148 and 149) but now that I’m looking for it, I see that it is mentioned elsewhere in that document.

Now that I’ve seen it, I think 0xFFFFFFFFFFFFFFFF (Unknown address) is the appropriate equivalent default for the 64-bit addresses, equivalent to the 16-bit Unknown address 0xFFFE. That should allow ZIgBee users to just set the address version they want to use, and the other will not interfere. Digimesh users (like me) can safely ignore the 16-bit address.

The current 64-bit default for remote_at dest_addr_long did seem odd to me, according to the docs above it’s the ‘Reserved 64-bit address for the coordinator’, but the part of the doc I was focused on implied that it was the only other ‘special’ 64-bit address other than broadcast (0x000000000000FFFF). There doesn't seem to be a reason from the spec to have that as a default as far as I can see.

I agree with you that the corresponding default 64-bit unknown address should be added. I’ll update the PR to try and keep everything consistent. Thanks for that link, I had a feeling I was missing something about the 64 bit addressing, which is why I initially left those alone. After comparing the documents, the addresses are clearer to me now.

hornc commented 8 years ago

I'm going to leave the ieee defaults alone because from my reading of that spec, the only command that has both size addresses, remote_at, only depends on whether the 16-bit address is set to 0xFFFE or not. If it is not 0xFFFE, the 16 bit address is used. It doesn't say anything about a specific unknown address. The ieee AT command for DH and DL however defaults to 0x0 and 0x0, which is possibly where the default came from here? For comparison, the ZigBee and Digimesh AT DH and DLs default to the broadcast address.

hornc commented 8 years ago

Updated PR: https://github.com/nioinnovation/python-xbee/pull/9

hansmosh commented 8 years ago

Merged #9