Home/Support/Support Forum/C Ansi library socket APIs

C Ansi library socket APIs

0 votes
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/ 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.
asked Apr 30, 2020 in RF Solutions and XBee by rutvij.trivedi New to the Community (4 points)
recategorized May 5, 2020 by LeonidM

Please log in or register to answer this question.

2 Answers

0 votes

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
answered Apr 30, 2020 by mvut Veteran of the Digi Community (15,223 points)
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 )

Is my understanding right here (?)

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

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.
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%7C_____0

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


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?

Not that I am aware of.

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

0 votes
is there anyone who can help with xbee_socket.c or any doc available ?

answered May 4, 2020 by rutvij.trivedi New to the Community (4 points)
All of the available documentation can be found at https://github.com/digidotcom/xbee_ansic_library
From the link given,
can this be used as reference ?

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

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

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
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.

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.
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.

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.

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.

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 ?

I am able to find the the firmware version XBXC-1140F and XBXC-11415 from the

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 ?

It is available in XCTU.
I refferd to your guidance and i updated firmware,
After couple of issue resolution now i am able to communicate to the AWS using Xbee3 Cellular and using this c Ansi library's extended sockets.

Thanks for the all support muvt.

We can close the issue i suppose.