Search code examples
xbee

API mode Xbee doesn't send digital samples?


I've been playing with getting an XBee to transmit whether a push button is up or down.

To do this I have the wire coming out of the circuit connected to DIO4 on the XBee. I used X-CTU to set DIO4 to digital input mode. Nothing else is enabled.

Now, the sensor XBee is transmitting a ZigBee I/O Data Sample Rx Indicator packet. I used the 'Building Wireless Sensor Networks' book to help parse out the packet. It says a packet always includes the analog sample values and will only include the digital ones if a digital pin is configured. I'm getting a 21 byte packet back, which implies the digital bit sample is not included. The digital mask says IO4 is enabled, and all the analog inputs are disabled. However, it appears the digital values were placed into the analog samples.

This is my confusion. Why is the digital sample being stuffed into the analog sample? Or is the analog sample simply left out if no analog inputs are configured (contrary to what the book says)?


Solution

  • Short answer: Yes, there are only analog samples in the payload if bits are set in the analog channel mask.

    Long answer: The XBee S2B documentation describes the details of the packet in the ZigBee IO Data Sample Rx Indicator section on page 114.

    In summary, the payload starts with the number of samples (always 0x01), then a 16-bit digital channel mask and an 8-bit analog channel mask. The masks indicate what data follows. If any bits were set in the digital channel mask, there will be a 16-bit value holding the digital samples. Then a 16-bit value for each analog sample indicated in the analog channel mask, from AD0 to AD3, followed by the supply voltage.

    Digi's Open Source XBee Host C Library has some code in include/xbee/io.h and src/xbee/xbee_io.c that demonstrate parsing of those frames.