# Problem and Example API Mode

**URL:** <https://forums.digi.com/t/problem-and-example-api-mode/1062>\
**Category:** XBee - Zigbee\
**Created:** [August 25, 2009, 7:47am UTC](https://forums.digi.com/t/problem-and-example-api-mode/1062 "2009-08-25T07:47:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![weilbs](https://avatars.discourse-cdn.com/v4/letter/w/35a633/32.png) [@weilbs](https://forums.digi.com/u/weilbs)\
**Post date:** [August 25, 2009, 7:47am UTC](https://forums.digi.com/t/problem-and-example-api-mode/1062/1 "2009-08-25T07:47:22Z")

</div>

Hello,

I have an interface board with an Xbee coordinator API module and a Xbee sensor and a wall router xbee.

My aim is to get the tmeprature and the light measure over API or AT command?

How i can do it? I can’t understand how to build APi frame?

Please help me, it’s very important

---

<div class="post-metadata">

**Author:** ![mgrierson](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@mgrierson](https://forums.digi.com/u/mgrierson)\
**Post date:** [August 26, 2009, 9:38pm UTC](https://forums.digi.com/t/problem-and-example-api-mode/1062/2 "2009-08-26T21:38:00Z")

</div>

Hello Weilbs,  
samples can be taken from the XBee sensor and wall router by polling then using an “IS” remote AT command from an API radio, or they can be pushed from the wall router or sensor by setting the sample rate “IR” parameter on them. This would have to be done by means of remote configuration, as there is no serial interface on these devices.  
To poll the sensors from an API radio you will need to send a remote AT command with the IS parameter such as the following example.  
7E 00 0F 17 01 00 13 A2 00 40 4A BA 3B FF FE 02 49 53 18  
See page 92 of teh product manual found here for a byte by byte breakdown of this packet.  
This example is going to take a sample from a sensor or wall router with the 64 bit address 00 13 A2 00 40 4A BA 3B.  
The response frame will look something like this:  
7E 00 1B 97 01 00 13 A2 00 40 4A BA 3B 20 FA 49 53 00 01 08 00 0E 08 00 00 C3 02 63 01 F0 45.

The frame breaks down like this:  
7E - Delimiter  
00 1B - Length bytes  
97 - API frame Identifier  
01 - Frame ID  
00 13 A2 00 40 4A BA 3B - 64 bit address of sending module  
20 FA - 16 bit address of sending module  
49 53 - AT command sent (IS)  
00 - Option Byte  
01 - number of samples  
08 00 - digital channel mask  
0E - Analog Channel Mask  
08 00 - Digital samples  
00 C3 02 63 01 F0 - Analog Samples  
45 - Checksum

This frame happens to come from a Temp/Light/Hum sensor so there are 3 analog samples of interest. (00 C3 02 63 01 F0)  
The samples are read in this order: (light,temp,hum)  
Light =00 C3 or decimal 195  
Temp=02 63 or decimal 611  
Hum=01 F0 or decimal 496  
The formulas to convert these values to Lux, temp and Humidity are:  
light = ADC1  
temp = ADC2  
hum = ADC3

Temperature:  
temp\_C = (mVanalog - 500.0)/ 10.0  
mVanalog = (ADC2/1023.0) \* 1200

Humidity:  
hum = (((mVanalog \* 108.2 / 33.2) / 5000 - 0.16) / 0.0062)  
mVanalog = (ADC3/1023.0) \* 1200

Light:  
lux = (ADC1) /1023.0) \* 1200

So using these formulas, we get the following results.  
Light (Lux)= 228.7390029  
Temperature (C)= 21.67155425  
Humidity= 35.36020917

The formulas for the wall router are similar:  
mVanalog = (TempADC/1023.0)\*1200.0  
temp\_C = (mVanalog - 500.0)/ 10.0 - 4.0  
lux = (LightADC/1023.0)\*1200.0  
Hopefully this helps and is not too confusing. Let me know if you need any clarification.

---

<div class="post-metadata">

**Author:** ![mgrierson](https://avatars.discourse-cdn.com/v4/letter/m/22d042/32.png) [@mgrierson](https://forums.digi.com/u/mgrierson)\
**Post date:** [August 26, 2009, 9:49pm UTC](https://forums.digi.com/t/problem-and-example-api-mode/1062/3 "2009-08-26T21:49:40Z")

</div>

I have built an excel 2007 spreadsheet to assist with calculating the values received from the API frame to Temp, Lux and Humidity.

I have also attached a simple checksum calculator to assist in building API frames.

---

<div class="post-metadata">

**Author:** ![waltr](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@waltr](https://forums.digi.com/u/waltr)\
**Post date:** [August 27, 2009, 3:30pm UTC](https://forums.digi.com/t/problem-and-example-api-mode/1062/4 "2009-08-27T15:30:59Z")

</div>

Excellent post. It took me a few weeks to figure this out from the Documents.  
Why can’t Digi write their doc’s this clearly.

---

<div class="post-metadata">

**Author:** ![sale84](https://avatars.discourse-cdn.com/v4/letter/s/51bf81/32.png) [@sale84](https://forums.digi.com/u/sale84)\
**Post date:** [October 19, 2010, 11:23am UTC](https://forums.digi.com/t/problem-and-example-api-mode/1062/5 "2010-10-19T11:23:39Z")

</div>

Where is the manual ??? The page 92 ???

---

<div class="post-metadata">

**Author:** ![Admin1](https://avatars.discourse-cdn.com/v4/letter/a/bbce88/32.png) [@Admin1](https://forums.digi.com/u/Admin1)\
**Post date:** [August 27, 2009, 3:35pm UTC](https://forums.digi.com/t/problem-and-example-api-mode/1062/6 "2009-08-27T15:35:02Z")

</div>

This sort of “nuts and bolts” information is normally found in our Knowledgebase, which is basically a collection of articles written by Tech Support personnel based on experiences.

We will be adding an article based on the type of situation you mentioned in this thread at some point in the future.

---

<div class="post-metadata">

**Author:** ![waltr](https://avatars.discourse-cdn.com/v4/letter/w/898d66/32.png) [@waltr](https://forums.digi.com/u/waltr)\
**Post date:** [September 12, 2009, 8:40pm UTC](https://forums.digi.com/t/problem-and-example-api-mode/1062/7 "2009-09-12T20:40:12Z")

</div>

Thanks for the checksum calculator. It was very handy for hand assembling API frames.

---

<div class="post-metadata">

**Author:** ![ishmell](https://avatars.discourse-cdn.com/v4/letter/i/ea5d25/32.png) [@ishmell](https://forums.digi.com/u/ishmell)\
**Post date:** [October 20, 2010, 9:12pm UTC](https://forums.digi.com/t/problem-and-example-api-mode/1062/8 "2010-10-20T21:12:18Z")

</div>

I’m having an issue with calculating checksums and even the Excel checksum calculator didn’t seem to help me come up with the correct answer.

I’ve set up a Series 2 XBee Pro 900Mhz DigiMesh module to send periodic I/O samples via escaped API frames. The data packets I receive don’t make any sense to me at all.

Here is a packet with escape characters still in tact;

7E 126  
00 0  
14 20  
92 146  
00 0  
7D 125  
33 51  
A2 162  
00 0  
40 64  
47 71  
7F 127  
DA 218  
FF 255  
FE 254  
01 1  
01 1  
10 16  
11 17  
00 0  
40 64  
21 33  
00 0  
40 64  
3F 63  
FF 255  
AD 173

Now if I unescape them;

7E 126  
00 0  
14 20  
92 146  
00 0  
13 19  
A2 162  
00 0  
40 64  
47 71  
7F 127  
DA 218  
FF 255  
FE 254  
01 1  
01 1  
10 16  
11 17  
00 0  
40 64  
21 33  
00 0  
40 64  
3F 63  
FF 255  
AD 173

The first thing I notice is the length is wrong. The length bytes indicate a total payload length of 20 bytes, but this is obviously not the case. Also, I’ve tried arriving at the checksum of AD (173) by doing just about every combination of bytes in the payload possible and I can’t seem to figure it out.

Any help would be very much appreciated!
