Mistake on this page?
Report an issue in GitHub or email us


ATCmdParser class hierarchy

ATCmdParser is an Mbed OS AT command parser and serializer. AT commands are instructions used to communicate with a communication device such as a modem, phone or Wi-Fi module. Each command is a text string in ASCII format, and every command starts with "AT" characters followed by a command specifying the operation to be carried out.

The ATCmdParser class implements functionality to send and receive AT commands to the devices capable of communicating using AT commands. The ATCmdParser internally uses the driver for the communication channel to talk to the device. It expects the driver to implement the FileHandle interface to invoke the functions on the driver.

For example, the UARTSerial communication driver implements the FileHandle interface, and you can use it with ATCmdParser to send and receive AT commands to a device connected through UART. ATCmdParser also does AT command parsing, which validates the data format and separates command and data portion of AT transactions. The actual command set and the format of AT commands used depends on the communication device used. The vendor of the device you are communcating with specifies this command set and format.

To use the ATCmdParser, the entity creating the ATCmdParser object passes a reference of object implementing FileHandle interface as an argument to the ATCmdParser constructor. The ATCmdParser also supports configuring a specific output delimiter character sequence, depending on the interface or device connected to the communication interface.

ATCmdParser class reference

Public Member Functions
 ATCmdParser (FileHandle *fh, const char *output_delimiter="\r", int buffer_size=256, int timeout=8000, bool debug=false)
 Constructor. More...
 ~ATCmdParser ()
 Destructor. More...
void set_timeout (int timeout)
 Allows timeout to be changed between commands. More...
void set_delimiter (const char *output_delimiter)
 Sets string of characters to use as line delimiters. More...
void debug_on (uint8_t on)
 Allows traces from modem to be turned on or off. More...
bool send (const char *command,...) MBED_PRINTF_METHOD(1
 Sends an AT command. More...
bool recv (const char *response,...) MBED_SCANF_METHOD(1
 Receive an AT response. More...
int putc (char c)
 Write a single byte to the underlying stream. More...
int getc ()
 Get a single byte from the underlying stream. More...
int write (const char *data, int size)
 Write an array of bytes to the underlying stream. More...
int read (char *data, int size)
 Read an array of bytes from the underlying stream. More...
int printf (const char *format,...) MBED_PRINTF_METHOD(1
 Direct printf to underlying stream. More...
int scanf (const char *format,...) MBED_SCANF_METHOD(1
 Direct scanf on underlying stream This function does not itself match whitespace in its format string, so
is not significant to it. More...
void oob (const char *prefix, mbed::Callback< void()> func)
 Attach a callback for out-of-band data. More...
void remove_oob (const char *prefix)
 remove_oob Removes oob callback handler More...
void flush ()
 Flushes the underlying stream. More...
void abort ()
 Abort current recv. More...
bool process_oob (void)
 Process out-of-band data. More...

ATCmdParser Example

The following is a program that uses the ATCmdParser class to communicate with a ESP8266 Wi-Fi module. ESP8266 is a Wi-Fi module that can be connected to an SoC over UART for Wi-Fi support. This program retrieves the FW version of the module using AT commands.

The output of the application can be viewed in a serial terminal with the following settings:

  • Baud rate: 9600
  • Data bits: 8
  • Stop bits: 1
  • Parity: None
/* ATCmdParser usage example
 * Copyright (c) 2016 ARM Limited
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *     http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.

#include "mbed.h"

#define   ESP8266_DEFAULT_BAUD_RATE   115200

int main()
    BufferedSerial *_serial;
    ATCmdParser *_parser;

    printf("\nATCmdParser with ESP8266 example");

    _serial = new BufferedSerial(D1, D0, ESP8266_DEFAULT_BAUD_RATE);
    _parser = new ATCmdParser(_serial, "\r\n");

    //Now get the FW version number of ESP8266 by sending an AT command
    printf("\nATCmdParser: Retrieving FW version");
    int version;
    if (_parser->recv("OK") && _parser->recv("SDK version:%d", &version)) {
        printf("\nATCmdParser: FW version: %d", version);
        printf("\nATCmdParser: Retrieving FW version successful");
    } else {
        printf("\nATCmdParser: Retrieving FW version failed");
        return -1;

The diagram below shows how the ESP8266 Wi-Fi driver uses the ATCmdParser class to communicate with an ESP8266 device.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.