Programação RPi Python 21: Os comandos SIM900A AT

RPi Python 21 Programming: The SIM900A AT Commands

In the previous tutorial , we covered how to interface a SIM900A GSM-GPRS modem with Raspberry Pi, Arduino, and desktop computers. SIM900A can communicate data with the control device via universal asynchronous receiver/transmitter ( UART ), I2C or SPI protocol.

The modem is a mobile device with an IMEI number capable of carrying out all cell phone operations (voice calls, SMS, MMS, fax and Internet). It “understands” AT commands and can be configured and operated by passing those commands to it.

There was a time when cell phones (like Nokia handsets) were built by directly connecting a screen, keyboard, speakers, microphone and battery system to these modems. Smartphones are now built with high-end processors that run complex mobile operating systems (iOS, Android, Windows).

A mobile platform processor interfaces with the following to build a complete portable computer that is a smartphone:

  • TO KNOCK
  • ROM
  • A touchscreen
  • A dedicated graphics processing unit (GPU)
  • Microphone and speakers
  • Camera and sensors
  • A neural processing unit (NPU) for artificial intelligence
  • A battery system and a wireless modem, such as a 4G/5G modem. (Even on smartphones, there is the wireless modem that offers a complete cellular solution.)

Wireless modems communicate using AT commands, which is an abbreviation for “attention.” These commands serve as instructions that control the wireless modem. Wireless modules like the SIM900A are essentially mobile equipment with console access.

The console communicates and responds to AT commands, which can be exchanged with a modem using the serial interface (UART), I2C or SPI . The controlling device can be any microcontroller or computer. Much like the previous tutorial – where we discussed how to interface the SIM900A with Raspberry Pi Arduino or other microcontrollers, including desktop computers that use USB serial cards – the modem can also be controlled by all of these devices.

Understanding AT Commands
AT commands are instructions for a wireless modem. Basic AT commands are a subset of the Hayes command. There are also AT commands that are implemented in compliance with the cellular solution (such as GSM-GPRS, GSM-GPRS+GNSS, WCDMA/HSPA/HSPA+, 4G/LTE, and CAT/NB-IoT).

The modem manufacturer may also implement a subset of AT commands on a specific modem. For example, the way basic and extended AT commands are implemented in a modem may differ from one vendor to another.

Each modem has and responds to its own set of instructions. AT commands are the same for a wireless or telephone modem. Similar to a processor that receives instructions and outputs results through parallel ports (or, in some cases, through serial ports), a modem receives commands and responds to them through standard serial interfaces (such as UART, SPI, and I2C ).

The SIM900A modem supports AT commands in accordance with:

  • The ITU-T (International Telecommunication Union, Telecommunications sector)
  • The V.25TER document
  • The ETSI GSM07.07 (i.e. the ETSI standard AT command is defined for GSM mobile equipment)
  • ETSI GSM07.05 (i.e. the ETSI standard is for short message service or SMS)
  • Cellular Broadcast Service (or CBS)

It also implements the AT commands for the SIM Application Toolkit, GPRS support, TCP/IP Application Toolkit, and IP, HTTP, and FTP applications – and has additional AT commands implemented by your SIMCOM vendor.

However, the modem may not support all AT commands under the ITU-T and ETSI specifications and only a subset of them. The supported AT commands can be used to configure a modem and access services such as voice calls, SMS, MMS, faxes and data link via TCP/IP, IP, HTTP and FTP protocols.

The types of AT commands
Basic AT Commands are a subset of Hayes Commands. The others are called extended AT commands.

There are four types of basic AT commands:

1. Test commands: Used to test the compatibility of a command with a modem and to confirm that a command is implemented or supported by the modem. The modem may respond with an OK or a supported command configuration in response to the test command. These commands are in AT+ format =? where is the command.

2. Read commands: used to know the settings of the cell phone or modem. These commands are in AT+ format ? where is the command.

3. Set commands: used to modify cell phone or modem settings. These commands include parameters that must be set to change a specific phone/modem configuration. They are in AT+ format = where is the command and are the optional arguments. If arguments are not passed in the command, the modem defaults to default mode.

4. Execute commands: used to perform a cellular operation, such as making or answering a voice call, reading, sending or deleting an SMS, etc. These commands are in AT+ format where is the command.

The syntax of AT commands

All AT commands begin with the prefix “AT” or “at” and end with a command line entry . This is why these commands are called AT commands.

The modem response comes in the format .

SIM900A AT commands can be divided into three subsets:

1. Basic syntax: they are in the format “AT " where is the command and are the optional arguments. If arguments are not passed, the default arguments will automatically be used by the modem.

2. S parameter syntax: they are in the format “ATS = " where is the index of record S to be defined and is the value to be attributed to it. O It is optional and if the value is not passed, the default values ​​are assumed by the modem.

3. Extended syntax: These are syntax for extended AT commands. The syntax for test, read, configure and run commands is mentioned above.

Therefore, basic commands use basic or S parameter syntax and extended AT commands use a different syntax depending on their type.

The SIM900 modem command line buffer can accept a maximum of 556 characters. It is possible to pass a single or multiple commands on one line. If the line exceeds 556 characters, however, none of the commands will be executed and the modem will return “ERROR”.

If a single command is passed on one line, another command cannot be passed until the modem response is received. If multiple commands are passed on one line, the “AT” or “at” must be prefixed to the beginning of the line.

Basic syntax and parameter commands must not be delimited, but all extended AT commands must be delimited by semicolons (;) on the line. The line must also end with the command line enter to pass all commands to the modem.

SIM900 AT commands default to the IRA character set. Other character sets supported by the SIM900 modem include:

  • GSM format
  • UCS2
  • HEX
  • PCCP
  • PCDN
  • 8859-1

The character set affects SMS, SMS cell broadcast messages, phonebook entries, and SIM application toolkit alpha sequences. The character set in use by the modem can be interrogated using the AT command “AT+CSCS”.

The list of AT commands
The SIM900 modem supports the following basic AT commands:

This list is relatively short and only features some of the most common commands. The SIM900 modem supports hundreds of AT commands according to different specifications.

AT commands for voice calls
These AT commands are useful for making and receiving voice calls using a SIM900 modem:

AT commands for SMS messages

These AT commands are useful for sending and receiving SMS messages using a SIM900 modem:

AT commands for data link over an HTTP protocol
In an HTTP protocol, data can be communicated using two methods:

1. GET method – used to obtain data from the server
2. POST method – used to post data to the server

But first, the modem must connect to a GPRS by configuring a bearer profile.

These AT commands can help:

These AT commands are useful for getting data from the server using the HTTP GET method:

These AT commands are useful for getting data from the server using the HTTP GET method:

AT commands for a data link via the TCP/IP protocol
The SIM900 modem also supports a data link via the TCP/IP protocol. The modem can connect via the TCP/IP protocol in two modes:

1. Single connection mode – only one connection can be established
2. Multi-connection mode – a maximum of eight connections can be established

The TCP/IP application can also have two modes: transparent and non-transparent. In multi-connection mode, SIM900A only works in non-transparent application mode.

These AT commands are useful for communicating as a modem TCP client to a server:

How to send AT commands from a user program
AT commands can be sent to a wireless modem via a user program, as a Python script, and as bytes. A programming language may use an escape sequence for command line input.

For example, in Python3, the enter command line can be passed serially using a carriage return, for which '\r' is the escape sequence. In Python2, for command line input, the '\r\n' is the escape sequence.

In a user program, string manipulation functions can be used to properly encode and decode AT commands and their responses. String manipulation functions are particularly useful when characters, such as CTRL+Z (substitute), must be passed along with the AT command.

For example, in Python3, the str.encode function can be used to encode AT commands into a script (user program). CTRL+Z can be passed using the char function with 26 as an argument — like char(26) or char(0x1A).

In the next tutorial, we will learn how to make and receive calls and how to send and receive SMS on Raspberry Pi and a desktop computer using the SIM900A modem.

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.