AT Commands Client

API Reference

Warning
Some AT commands may conflict with Legato APIs; using both may cause problems that can be difficult to diagnose. AT commands should be avoided whenever possible, and should only be used with great care.

The AT Client Service handles the AT commands sent to the modem on a specified serial device. It also supports getting AT command responses (intermediate, final or unsolicited responses). This service can be subscribed to by several apps simultaneously.

IPC interfaces binding

All the functions of this API are provided by the atService.

Here's a code sample binding to the AT commands server:

bindings:
{
   atClientTest.atClientTestComp.le_atClient -> atService.le_atClient
}

Device Binding

le_atClient_Start() must be called to bind a specific device with the ATClient, the user app must also pass in an open file descriptor to le_atClient_Start() The file descriptor will automatically close when le_atClient_Stop() is called.

Multiple devices can be bound. The app has to configured the device before using it with the ATClient.

A device can be unbound using le_atClient_Stop(), which will also automatically close the file descriptor.

Statement

An AT command statement is requested before sending it. The following steps have to be done for its declaration:

Command responses given in le_atClient_SetIntermediateResponse() and le_atClient_SetFinalResponse() are the first characters of the response lines. They are used as a filter of the received lines (a line are the characters received between receiving a <CR> and an <LF>). Other lines are dropped.

  • text can be set using le_atClient_SetText(). This is used for commands that answers a '>' character to receive additional information. The given text is sent to the modem when '>' is detected. The character CTRL-Z is automatically sent.

Sending

When the AT command declaration is complete, it can be sent using le_atClient_Send(). This API is synchronous (blocking until final response is detected, or timeout reached).

le_atClient_SetCommandAndSend() is equivalent to le_atClient_Create(), le_atClient_SetCommand(), le_atClient_SetDevice(), le_atClient_SetTimeout(), le_atClient_SetIntermediateResponse() and le_atClient_SetFinalResponse(), in case of an Error le_atClient_Delete(), in one API call. The AT command reference is created and returned by this API. When an error occurs the command reference is deleted and is not a valid reference anymore

Responses

When the AT command has been sent correctly (i.e., le_atClient_Send() or le_atClient_SetCommandAndSend() execution is successful), the app gets these AT command responses:

When a response has been set in the AT command declaration, the AT command response returned by these APIs start with the given pattern, and ends when a <CR><LF> is detected.

Deleting

When the AT command is over, the reference has to be deleted by calling le_atClient_Delete().

Unsolicited Responses

An app can subscribe to a specific, unsolicited response using le_atClient_AddUnsolicitedResponseHandler(), and can be removed using le_atClient_RemoveUnsolicitedResponseHandler(). The subscribed handler is called when the given pattern is detected. The handler receives a parameter with the complete line of the unsolicited response. The parameter lineCount is used to set the unsolicited lines number. For example, +CMT unsolicited response has the following syntax:

+CMT: ...<CR><LF>
<sms text>

In this case, lineCount has to be set to 2 to receive both lines into the handler. +CREG unsolicited response is sent only one line, so lineCount is set to 1.