# C Ansi library socket APIs

**URL:** <https://forums.digi.com/t/c-ansi-library-socket-apis/21328>\
**Category:** XBee & XBee Gateway\
**Tags:** tcp-sockets, xbee-api-mode, clibrary\
**Created:** [April 30, 2020, 12:03pm UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328 "2020-04-30T12:03:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [April 30, 2020, 12:03pm UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/1 "2020-04-30T12:03:08Z")

</div>

Hi,  
I am working with the Xbee3 LTE-M module and microcontroller unit.

I want to make a network interface layer using the LTE module and in doing so I need to implement socket calls(create, send, receive, etc) which interns talk to Xbee hardware using AT command via USART.

To do so I am referring [https://github.com/digidotcom/xbee\_ansic\_library/](https://github.com/digidotcom/xbee_ansic_library/) library.

I am not able to connect the dots for callbacks given here.

My query is there anyone who has any reference code in c for the same or document to start with?

Is anyone able to achieve socket communication on any embedded microcontroller device so far?

Any help would be greatly appreciable.

Thanks & Reg.

---

<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:** [April 30, 2020, 12:20pm UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/2 "2020-04-30T12:20:07Z")

</div>

Rutvij,

This code requires the XBee to be in API mode (ATAP1) and at a baud rate of 115.2kbps (ATBD7).

As for sockets, you don’t control it like you would think. You only need to send the TX request (IPV4) which will have the IP address and port number for the device you want to send the data to. The radio will keep the socket open for the timeout period set on the radio and the remote device.

The data will be sent back on what ever port number the xbee is set to (DE and CO).

Digi Support

---

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [May 1, 2020, 9:25am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/3 "2020-05-01T09:25:44Z")

</div>

Hi,  
Thank you for the quick replay.

So here I am trying to enable Amazon Freertos with LTE-M.  
AWS freeRTOS wants socket API stubs to be filled in order to communicate.

What I believe it should be like below starting from forming MQTT packets to UART packet for radio

1.MQTT msgs  
|  
2.MBEDTLS (encryption done here)  
|  
3.SSL -\> socket apis stubs  
|  
4.xbee\_ansic\_library xbee\_socket.c  
|  
5.AT+ Commands harwadere + (encrypted) PAYLOAD )  
|  
6.AWS

Is my understanding right here (?)

In the above dia. 3 and 4 steps socket stubs can be interconnected as shown?

## i.e. Socket APIS | Xbee Apis

SOCK\_Create–|-\> Xbee\_sock\_create  
SOCK\_recv----|-\> Xbee\_sock\_recv  
SOCK\_Send----|-\> Xbee\_sock\_send

Help would be appreciable.

Thanks & Reg.

---

<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:** [May 1, 2020, 9:30am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/4 "2020-05-01T09:30:28Z")

</div>

I know there is an example for Micro python at [https://www.digi.com/resources/documentation/digidocs/90002219/default.htm#container/cont\_aws.htm%3FTocPath%3DUse%2520AWS%2520IoT%2520from%2520MicroPython|\_\_\_\_\_0](https://www.digi.com/resources/documentation/digidocs/90002219/default.htm#container/cont_aws.htm%3FTocPath%3DUse%2520AWS%2520IoT%2520from%2520MicroPython%7C _____ 0)

I would suggest you go thru that first and see how it works as the process should be similar.

---

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [May 1, 2020, 12:23pm UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/5 "2020-05-01T12:23:21Z")

</div>

Hi,  
Thanks for the replay.

[https://github.com/digidotcom/xbee-python](https://github.com/digidotcom/xbee-python)

Earlier I did go through that but it is written in python, where I don’t have much knowledge in.

Also, my MCU will gonna support only C lan.

So is there any C lan. example available?

Thanks

---

<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:** [May 1, 2020, 12:30pm UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/6 "2020-05-01T12:30:22Z")

</div>

Not that I am aware of.

---

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [May 4, 2020, 8:29am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/7 "2020-05-04T08:29:16Z")

</div>

Hi,  
is there anyone who can help with xbee\_socket.c or any doc available ?

Thanks,

---

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [May 4, 2020, 8:27am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/8 "2020-05-04T08:27:52Z")

</div>

Hi,

No satisfying answer, as Title is it slef says “C Ansi library socket APIs”

Thanks.

---

<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:** [May 4, 2020, 8:36am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/9 "2020-05-04T08:36:22Z")

</div>

All of the available documentation can be found at [https://github.com/digidotcom/xbee\_ansic\_library](https://github.com/digidotcom/xbee_ansic_library)

---

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [May 4, 2020, 9:28am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/10 "2020-05-04T09:28:45Z")

</div>

From the link given,  
can this be used as reference ?  
xbee\_ansic\_library/samples/common/socket\_test.c

Thanks,

---

<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:** [May 4, 2020, 9:35am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/11 "2020-05-04T09:35:27Z")

</div>

Sure it can.

---

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [May 4, 2020, 11:29am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/12 "2020-05-04T11:29:29Z")

</div>

Hi,  
Thanks for conforming,  
I Will give it a shot and will let you know.

Thanks.

---

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [August 13, 2020, 11:13am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/13 "2020-08-13T11:13:00Z")

</div>

Hi,  
I tried using above mentioned example as well as xbee\_netcat.c but I am facing issue while getting callback response from xbee for socket apis in both the cases.

After call to  
netcat\_socket = xbee\_sock\_create(xbee, proto,netcat\_sock\_notify\_cb);  
I am getting xbee\_sock\_frame\_handler 0x8a and then nothing happens.

my frame dispatcher looks like

#define XBEE\_SOCK\_FRAME\_HANDLERS { 0, 0, xbee\_sock\_frame\_handler, NULL } //receive for every frame event

const xbee\_dispatch\_table\_entry\_t xbee\_frame\_handlers[] = {  
XBEE\_FRAME\_HANDLE\_LOCAL\_AT, //local side  
XBEE\_SOCK\_FRAME\_HANDLERS,  
XBEE\_FRAME\_TABLE\_END  
};

After initializing xbee module and going into API mode I am able to resolve FQDN and getting IP of remote host from its callback network is also available .

Below are the logs I am receiving in the process

xbee\_sock\_frame\_handler 0x88,  
Cellular module connected…  
xbee\_sock\_frame\_handler 0x88,  
My IP is 10.117.118.127  
xbee\_sock\_create: created socket 0x0037  
xbee\_sock\_frame\_handler 0x8a

So my query is why callbacks are not being called for socket apis ?  
Furthermore i have XBEE\_CELLULAR\_ENABLED=1 is enabled.

What is there i am missing here ?

Any help would be appreciable.

Thanks

---

<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:** [August 13, 2020, 11:23am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/14 "2020-08-13T11:23:12Z")

</div>

The code you are working with has not been updated to support the new socket functions that exits in the XBee 3 CAT M module. You are going to need to look at the manual for the XBee and add the necessary functions to this code.

---

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [August 13, 2020, 12:49pm UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/15 "2020-08-13T12:49:39Z")

</div>

Hi,  
Thanks for the quick reply.

I have used xbee\_ansic\_library/samples/common/xbee\_netcat.c code with minor modification of removal of windows related functions to support my platform as xbee\_ansic\_library/samples/common/socket\_test.c did now work for me.

xbee\_netcat.c file seems doing initialization and command layer init, and IP management.

Is there any recommended sequence available ?  
I also tried to map the socket api frames with manual but i was not able to find frame to guide.  
socket\_frames.h has  
//Frame definitions and support functions for Extended Socket frames  
(0x40-0x4F and 0xC0-0xCF).

But could not find them into manual.

Thanks

---

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [August 14, 2020, 7:46am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/16 "2020-08-14T07:46:02Z")

</div>

Hi,  
Currently my module has “1140b” firmware version.  
To support socket apis which version of firmware is needed ?

My module info. XB3-C-A2-UT-001 revB.

Thanks.

---

<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:** [August 14, 2020, 7:50am UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/17 "2020-08-14T07:50:37Z")

</div>

The firmware version you are working with is very old. I would suggest you update it to the current version. Make sure you do it using one of the new XBIB-CU-TH boards so you can update the U-Blox modules as well. Also make sure you do it in at least 3 steps. That is, update to version 1140F, then 11413 and finally 11415.

---

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [August 14, 2020, 12:51pm UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/18 "2020-08-14T12:51:20Z")

</div>

Hi,

LTE-M module is located at remote location and is attached with EFM32 Geint gecko.  
I am able to communicate with the module and able to Get ip and cell network.  
So is there any FOTA way to do it from MCU ?  
Any sample or guide available to do it easy way ?

Thanks

---

<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:** [August 14, 2020, 1:10pm UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/19 "2020-08-14T13:10:08Z")

</div>

There is a Python script at [https://www.digi.com/support/productdetail?pid=5635&amp;type=documentation](https://www.digi.com/support/productdetail?pid=5635&amp;type=documentation) to help perform that function. There are also directions in the manual for this at [https://www.digi.com/resources/documentation/Digidocs/90002258/#concepts/c\_update\_cellular\_fw.htm%3FTocPath%3DUpdate%2520the%2520firmware|Update%2520the%2520cellular%2520firmware|\_\_\_\_\_0](https://www.digi.com/resources/documentation/Digidocs/90002258/#concepts/c_update_cellular_fw.htm%3FTocPath%3DUpdate%2520the%2520firmware%7CUpdate%2520the%2520cellular%2520firmware%7C _____ 0)

---

<div class="post-metadata">

**Author:** ![rutvij.trivedi](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@rutvij.trivedi](https://forums.digi.com/u/rutvij.trivedi)\
**Post date:** [August 17, 2020, 12:48pm UTC](https://forums.digi.com/t/c-ansi-library-socket-apis/21328/20 "2020-08-17T12:48:53Z")

</div>

Hi,  
I am able to find the the firmware version XBXC-1140F and XBXC-11415 from the  
[https://www.digi.com/support/productdetail?pid=5635&amp;type=firmware](https://www.digi.com/support/productdetail?pid=5635&amp;type=firmware)  
link,

However I am not able to find the firmware version 11413.  
Can you please share the link from where i can get this firmware sequences ?

Thanks

[Next page](https://forums.digi.com/t/c-ansi-library-socket-apis/21328.md?page=2)
