# AT get function lags main program - 900 HP programmable

**URL:** <https://forums.digi.com/t/at-get-function-lags-main-program-900-hp-programmable/17450>\
**Category:** XBee & XBee Gateway\
**Tags:** programmable, 900hp, xbp9b, hp, 900\
**Created:** [September 24, 2016, 1:04pm UTC](https://forums.digi.com/t/at-get-function-lags-main-program-900-hp-programmable/17450 "2016-09-24T13:04:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![squarej](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@squarej](https://forums.digi.com/u/squarej)\
**Post date:** [September 24, 2016, 1:04pm UTC](https://forums.digi.com/t/at-get-function-lags-main-program-900-hp-programmable/17450/1 "2016-09-24T13:04:17Z")

</div>

I am trying to collect XBee parameters, TP/Temperature for example but when I call the function from Main it appears the rest of main finishes running while the AT command is being processed. This is preventing me from capturing the output of the AT request and using it in the rest of main. I know its something simple but could use some advice as to how to get main to wait for the response before continuing.

Thanks for the help,  
Jason

I’ve stripped down main to this:

printf("MAIN START  
");  
printf("Reading TP value  
");  
get\_atcmd\_value(“TP”);  
printf("MAIN END

");

I get this output

MAIN START  
Reading TP value  
MAIN END

ATTP: 00 1C

---

<div class="post-metadata">

**Author:** ![mvut](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/mvut/32/31_2.png) [@mvut](https://forums.digi.com/u/mvut)\
**Post date:** [September 29, 2016, 3:43pm UTC](https://forums.digi.com/t/at-get-function-lags-main-program-900-hp-programmable/17450/2 "2016-09-29T15:43:36Z")

</div>

Are you using API mode or AT mode on the radio?

---

<div class="post-metadata">

**Author:** ![squarej](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@squarej](https://forums.digi.com/u/squarej)\
**Post date:** [September 30, 2016, 11:35pm UTC](https://forums.digi.com/t/at-get-function-lags-main-program-900-hp-programmable/17450/3 "2016-09-30T23:35:49Z")

</div>

It is in API without escapes mode (1)

---

<div class="post-metadata">

**Author:** ![squarej](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@squarej](https://forums.digi.com/u/squarej)\
**Post date:** [October 2, 2016, 10:32pm UTC](https://forums.digi.com/t/at-get-function-lags-main-program-900-hp-programmable/17450/4 "2016-10-02T22:32:47Z")

</div>

I could not figure out how to capture the AT result in MAIN so I had to place code within the command\_dump function. I am no C coder so pardon the possibly poor code, but it works.

//Sends Temperature info  
if ( strncmp(response-\>command.str, “TP”, 2) == 0 )  
{  
//WORKS  
memset(SendBuffer, 0, 100 \* sizeof(SendBuffer[0]));  
printf("  
AT Read: %s = %d  
", response-\>command.str, response-\>value\_bytes[1] );  
strcat(SendBuffer, “Temperature:”);  
sprintf(IntegerString, “%d”, response-\>value\_bytes[1]);  
//sprintf(IntegerString, “%02x”, response-\>value\_bytes[1]);  
strcat(SendBuffer, IntegerString);  
env.payload = SendBuffer;  
//printf("AT env.payload: %02x  
", env.payload );  
env.length = strlen(SendBuffer);  
//printf("AT env.length: %i

", env.length );

```
  //Sends data
    xbee_transparent_serial(&amp;env);
}

```

---

<div class="post-metadata">

**Author:** ![mvut](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/mvut/32/31_2.png) [@mvut](https://forums.digi.com/u/mvut)\
**Post date:** [October 3, 2016, 8:54am UTC](https://forums.digi.com/t/at-get-function-lags-main-program-900-hp-programmable/17450/5 "2016-10-03T08:54:59Z")

</div>

I did some searching in the Code Warrior and I am not finding this command you want to use.

Why are you not using the xbee\_cmd\_request  
and xbee\_cmd\_response commands that exist?

---

<div class="post-metadata">

**Author:** ![squarej](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@squarej](https://forums.digi.com/u/squarej)\
**Post date:** [October 3, 2016, 10:29am UTC](https://forums.digi.com/t/at-get-function-lags-main-program-900-hp-programmable/17450/6 "2016-10-03T10:29:02Z")

</div>

Thanks for the response.

Either I missed something or its not quite that simple - My C is pretty weak. From what I could tell, using the at\_interactive sample program, the process flow goes something like this:

process\_command( &xdev, buffer) - Buffer = the AT command requested

Which calls  
process\_command\_remote(xbee, cmdstr, NULL);

Which calls  
request = xbee\_cmd\_create( xbee, cmdptr)

Which finally calls  
xbee\_cmd\_create( xbee, command)

Then you have to unwind and interpret the results with command\_dump - This is where I captured the result and sent the data to the base station.

I still don’t know how to capture within MAIN to actually use it locally.

Even the sample program sends the AT request then moves on in MAIN, only later printing the result from AT, regardless of what is going on in MAIN - separate thread apparently.

---

<div class="post-metadata">

**Author:** ![mvut](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.digi.com/mvut/32/31_2.png) [@mvut](https://forums.digi.com/u/mvut)\
**Post date:** [October 3, 2016, 4:19pm UTC](https://forums.digi.com/t/at-get-function-lags-main-program-900-hp-programmable/17450/7 "2016-10-03T16:19:54Z")

</div>

Wrong example. Try using the AT command Local example instead. It has it calling the commands from the Main.c file.

---

<div class="post-metadata">

**Author:** ![squarej](https://avatars.discourse-cdn.com/v4/letter/s/b19c9b/32.png) [@squarej](https://forums.digi.com/u/squarej)\
**Post date:** [October 3, 2016, 4:34pm UTC](https://forums.digi.com/t/at-get-function-lags-main-program-900-hp-programmable/17450/8 "2016-10-03T16:34:38Z")

</div>

Ah yes, my initial question/example was actually using the AT command local sample app, stripped down. My problem appears to be that the XBee command runs in its own ‘thread’ and main continues on. The AT result is not printed by MAIN but actually the same function, command\_dump. I would love an example that actually pulls the AT command back into MAIN as I didn’t solve my problem, I just worked around it by shipping out the data to my base station.
