florianagr:
Hi Valen, what do you mean by 64 Bit adress? Where can i read that?
As you obviously found out already: there is a sticker on the bottom of the module with the serial number found in the SH and SL register. This can be considered the unique 64bit hardware adress. The adress of the router that you stated last does not match exactly what I find in the partial API packet that you initially posted. But after further consideration, it can be explained.
You state that:
The “discardByte = 0 18 146 0 125 51 162 0 64 173 23 24 85 236 1 1 0”
These seem all decimal values, confirmed by your code.
First of all, it is risky to pick out specific bytes out of a packet that can change in length. You should really analyze each part of the packet and group the bytes received. Only afterwards can you decide which bytes you do not care about. If the 3rd byte in discardByte wasn’t 146 (or 0x92 in hexadecimal), for some unexpected reason, then your program would produce faulty output values as it picked the wrong bytes as analog measurements. (which it does anyway) In this case you seem to be lucky as it is a “ZigBee IO Data Sample Rx” packet. Another reason, and this seems to happen in this particular case, is that Escape characters may be injected in the stream, to not interfere with the dataframe sequencing. See page 55 of the Manual, 6.0.1 Api Frame Specifications.
Lets analyze this. Have you done this yourself, using the Zigbee 2.5 series 2 manual? Page 67 internal page count (68 PDF page count)
http://ftp1.digi.com/support/documentat … 0976_S.pdf
The next two bytes after the header byte 0x7E is “0 18” is the length of the packet, excluding the header byte, length and Checksum. This means the following 18 bytes contain the message. But you only show 15 of them.
Next comes the API Frame type identifier “146”. In hexadecimal this is 0x92. Which means it is infact a Zigbee IO Data Sample Receive packet.
Next comes the 64 bit hardware adress/SH SL serial number . This does not seem to match to your stated serial number, as it contains partially ‘faulty’ numbers. These 9 bytes from the discardByte stream suggest they are the SH and SL adress: "0 125 51 162 0 64 173 23 24 " As the end of them match pretty closely. The first byte seems ok also, as the most significant byte of SH is also 0. Next comes 125, or 0x7D. This happens to be the token for starting an escaped character. The next byte bitwise-eXclusiveOR-ed with 0x20 should result in the right byte of the adress. (use the Programmer function of the Windows calculator to perform this yourself) 51 decimal is 0x33. 0x33 XOR 0x20= 0x13 (which is 19 in decimal) And this byte with the remaining 6 confirms the 64 bit adress.
Next comes the 16 bit network adress, 2 bytes: 85 236. Which would be 0x55EC. I cannot say anything about it’s validity because I know nothing about this Zigbee network adressing protocol routing business. I only know about the series 1 modules. I’ll assume this is correct. (and not very important in this case, since the 64 bit hardware adress is verified)
Next should follow a byte called Receive Options. Being 1 for Packet Acknowledged, and 2 for if it was broadcast packet. Your next byte is 1, so it is acknowledged. Fine.
Next is 1 byte, number of samples. Also as expected, as it is also 1.
Then comes 2 bytes representing the Digital Channel Mask, showing which digital IO lines are sampled. This is not of any concern to you, but it is part of the frame. It is 0, so no digital line samples in the frame.
Now your code expects to read the analog values. But because of the Escaped character this is offset further away. And you decided to ignore any later bytes of the frame. So nothing can be said now about what the analog value should be. Even then, you are a few bytes too early with expecting the analog values. First comes the Analog channel mask (1 byte), and the Digital samples (2 bytes). Since there are no digital lines selected the last is probably not part of the packet. The analog sample of 2 bytes would make the 18 bytes in the frame complete. (The escape token is not part of it apparently, need to test that) And to confirm the integrity of the entire packet it should end with the checksum value. That should prove if you have all the bytes of the packet received. If not, it should be ignored.
TL/DR: Analyze the entire API packet, or use a Xbee/Zigbee API library for Arduino to do it for you. You picked the wrong bytes. And ignored the part of the frame that contains them.
For the sensor i used a 10k ohm resitor. i used this sensor without Xbee and it worked very well, but when i attached it to the xbee i have this error 5105. What do you mean by “Kind of voltage”, i´m using a xbee regulated that convert a 5 v in 3.3v for the xbee module. thank you for your answer.
The analog to digital converter inside the Xbee module doesn’t know that you applied (approximately!!) 5 volt to the sensor. In order to measure the voltage on it’s analog pin it needs to compare this to a reference voltage. Most microcontrollers have a built-in reference, but sometimes also a pin into which the designer can apply an external voltage which would resemble the value 1023 (or whatever the max resolution can be). For the XBees S2, according to the manual, this seems to be fixed to an internal reference of 1.2 volt. (Series 1 needs an external reference) So you do not need to apply a voltage to the Vref pin (14). But is important to know that the voltage to be measured needs to be lower than this. Or else all you get it 0x3FF, or 1023 as a result.
I do not know what voltage your sensor is supposed to output in it’s voltage divider configuration with the 10 K resistor. [edit: Datasheet of sensor: Rs is between 10k and 100k in air, so with 10k resistor it would be around halve of 5 volt or lower.) Did you measure it yourself with a multimeter? And did it change by blowing into it with your breath? It should respond to humidity changes.What ‘analog’ value would you have expected from the Xbee, knowing the real voltage of the sensor? Do realize that the Xbee cannot handle more than 3.6 volt on it’s pins. 5 volt from the sensor output is too much. It might break down. And definitely too high to make a useful measurement. Instead of using the voltage above the 10K load resistor, you may reduce the output voltage even more by replacing it (the load resistor) with another voltage divider resistor set (totaling 10 K). Just so the ultimate output it is less than 1.2 volt.