# Facing problem while sending AT commands using le\_atclient api service

**URL:** <https://forum.legato.io/t/facing-problem-while-sending-at-commands-using-le-atclient-api-service/2389>\
**Category:** Legato Linux distribution (Yocto project)\
**Created:** [March 16, 2017, 7:12am UTC](https://forum.legato.io/t/facing-problem-while-sending-at-commands-using-le-atclient-api-service/2389 "2017-03-16T07:12:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [March 16, 2017, 7:12am UTC](https://forum.legato.io/t/facing-problem-while-sending-at-commands-using-le-atclient-api-service/2389/1 "2017-03-16T07:12:44Z")

</div>

Hi all,

I am trying to send AT commands and using AT command I want to connect to gprs.  
I am getting some error as below and application get stop:  
**le\_atClient\_client.c GetCurrentSessionRef() 320 | le\_atClient\_ConnectService() not called for current thread**

my source code is as below:

```
void fSendandReceiveAtCommand()
    {
        char fd[200];
        strcpy(fd,"WP8548");
        char cmd[100];
        strcpy(cmd,"AT+CSQ");
        char interResp[100];
        char finalResp[100];

        le_result_t res;

        le_atClient_DeviceRef_t ref_device = le_atClient_Start(fd);

        le_atClient_ConnectService();

         le_atClient_CmdRef_t ref_client = le_atClient_Create();

        res = le_atClient_SetCommandAndSend(&ref_client,ref_device,cmd,NULL,"+CPIN:READY",1000);

        if(res == LE_OK)
        {
            LE_INFO("send cmd success inter resp %s Final resp %s" , interResp, finalResp);
        }
        else if(res == LE_FAULT)
        {
            LE_INFO("fault in send");
        }
        else if(res == LE_TIMEOUT)
        {
            LE_INFO("time out occured");
        }
        else
        {
            LE_INFO("not found ");
        }

    }

```

In " le\_atClient\_Start" api, the device path is to be given as argument, which path ideally to be added.?

Can any one please give me solution?  
Thank you in advance

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/dfrey/32/563_2.png) [@dfrey](https://forum.legato.io/u/dfrey)\
**Post date:** [March 16, 2017, 3:35pm UTC](https://forum.legato.io/t/facing-problem-while-sending-at-commands-using-le-atclient-api-service/2389/2 "2017-03-16T15:35:48Z")

</div>

I believe you want to call `open()` on `/dev/ttyAT` and then pass the resulting file descriptor as the parameter to `le_atClient_Start()`

---

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [March 21, 2017, 8:52am UTC](https://forum.legato.io/t/facing-problem-while-sending-at-commands-using-le-atclient-api-service/2389/3 "2017-03-21T08:52:53Z")

</div>

Hello dfrey

I have added “open()” before le\_atClient\_Start() but it is giving same error.

source code:

```
void fSendandReceiveAtCommand()
    {
        char fd[50];
        strcpy(fd,"/dev/ttyAT");
        char cmd[100];
        strcpy(cmd,"AT+CSQ?");
        char interResp[100];
        char finalResp[100];

        le_result_t res;

        int open_res = 0;

        open_res = open(fd,O_RDWR);

        //sprintf(fd,"%d",open_res);

        le_atClient_DeviceRef_t ref_device = le_atClient_Start(open_res);

        le_atClient_ConnectService();

         le_atClient_CmdRef_t ref_client = le_atClient_Create();

        res = le_atClient_SetCommandAndSend(&ref_client,ref_device,cmd,NULL,"+CPIN:READY",1000);

        if(res == LE_OK)
        {
            LE_INFO("send cmd success inter resp %s Final resp %s" , interResp, finalResp);
        }
        else if(res == LE_FAULT)
        {
            LE_INFO("fault in send");
        }
        else if(res == LE_TIMEOUT)
        {
            LE_INFO("time out occured");
        }
        else
        {
            LE_INFO("not found ");
        }

    }

COMPONENT_INIT
{
    LE_INFO("Hello, world.");

    fSendandReceiveAtCommand();

}

```

---

<div class="post-metadata">

**Author:** ![dfrey](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/dfrey/32/563_2.png) [@dfrey](https://forum.legato.io/u/dfrey)\
**Post date:** [March 22, 2017, 2:02pm UTC](https://forum.legato.io/t/facing-problem-while-sending-at-commands-using-le-atclient-api-service/2389/4 "2017-03-22T14:02:47Z")

</div>

I haven’t used the ATClient service myself. Maybe this test code can be used as a reference to get you started:

> <https://github.com/legatoproject/legato-af/blob/master/apps/test/atServices/atClientTest/atClientTestComp/atClientTest.c#L73>

---

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [April 22, 2017, 11:39am UTC](https://forum.legato.io/t/facing-problem-while-sending-at-commands-using-le-atclient-api-service/2389/5 "2017-04-22T11:39:38Z")

</div>

Hi,

I am using same sample code as given in the above link but it is giving me same error at le\_atClient\_ConnectService().  
Error : **le\_atClient\_client.c GetCurrentSessionRef() 320 | le\_atClient\_ConnectService() not called for current thread**

when I tried to use api : **le\_atClient\_TryConnectService**  
it gives me error : **LE\_NOT\_PERMITTED = -5, ///\< Current user does not have permission to perform requested action.**

Due to this error, application get stop at starting only and does not execute rest of code.

As I have taken sample code as it is, then also facing this issue.  
please give me solution for this issue.

Thank you!

---

<div class="post-metadata">

**Author:** ![CoRfr](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/corfr/32/69_2.png) [@CoRfr](https://forum.legato.io/u/CoRfr)\
**Post date:** [May 2, 2017, 1:08pm UTC](https://forum.legato.io/t/facing-problem-while-sending-at-commands-using-le-atclient-api-service/2389/6 "2017-05-02T13:08:50Z")

</div>

I would think it is because you have not connected your atClient API client to the atClient API server.

Cf [Application Definition .adef - Legato Docs](http://legato.io/legato-docs/latest/defFilesAdef.html#defFilesAdef_bindings) for the doc.

It should look like:

```
bindings:
{
    myApp.myComp.le_atClient -> atService.le_atClient
}

```
