How to send an SMS with a GSM modem using AT commands (at+cmgs)
AT+CMGS command is used to send sms messages with GSM modem in Text or PDU mode. This document describes the process of sending SMS messages from an SMS modem to a mobile phone using the SMS protocol. The mobile phone referred to in this document can be any GSM phone, that is capable of receiving SMS text messages. If you read this document, you will understand how the modem connection in Ozeki SMS Gateway works.
What are AT commands?
“AT” commands are also known as “Attention Commands”. AT commands are a set of instructions used to control and configure modems. “AT” stands for “come to ATtention”. Originally developed for Hayes smart modems, they were used in dial-up modems in the 1990s. In the present day, AT commands are employed by all GSM modems, and they are also supported by 2G, 3G, and 4G modems.
How to send SMS with at commands (Easy to follow guidelines)
To send SMS with at commands:
- Check the prerequisites for sending an SMS from a modem
- Set up the hardware
- Configure the communications settings
- Reset the SMS modem to factory default
- Initialize the modem
- Use the appropriate SMSC number for your mobile network
- Enter the actual length of the SMS message in octets
- Construct the PDU message to send test SMS in PDU mode
- Refer to the SMS protocol description for instructions
- Send a test SMS message in Text mode
Hardware Requirements for sending an SMS from a modem
- An SMS modem
- A SIM card (You put the SIM card into the SMS modem)
- A GSM antenna connected to the SMS modem
- A power cable for the SMS modem
- A phone-to-pd data cable that connects the modem to the PC
- A PC running a terminal software such as Ozeki Terminal.
- A mobile phone that is capable of receiving the SMS messages
Hardware setup
- Insert the SIM card into the modem
- Attach the antenna to the modem
- Connect the SMS modem to a PC with the phone to PC data cable
- Turn on the PC and run Ozeki Terminal.
- Select the serial port that appears when the phone to pc data cable is connected.
Communications Settings
Baud Rate | 115200 bps |
Data Bits | 8 |
Stop Bits | 1 |
Parity | None |
Flow Control | Hardware |
Connector | COM10 or another COM port |
Modem initialization
To reset the SMS modem to factory default use the AT&F command. After rest, the following commands should be issued
AT+CMGF=0[ENTER] Set the SMS modem to PDU mode
If your modem does not support PDU mode, you can issue AT+CMGF=1[ENTER] Set the SMS modem to text mode
AT+CSCA=”+36209300099”[ENTER] Enter the SMS Centre Address
Note that you will have to use the appropriate SMSC number for your mobile network. Each country has its own SMSC address. These can be found in the SMS Service Centre Address table.
How to send an SMS Message using AT commands in Text mode
In text mode, to send a message, e.g. “hello”, follow the three steps below.
- Set the SMS modem for text SMS using: AT+CMGF=1[ENTER]
- Enter the destination phone number in international format AT+CMGS=”+36419879619”[ENTER]
- Enter the text message and terminate it with “CTRL Z”: >hello[CTRL Z]
- The SMS modem will return: +CMGS: 1 OK
- Record the number 1, which is the message reference MR, which is different for every SMS message sent.
How to send an SMS Message using AT commands in PDU mode
In PDU mode, to send a message like the "Ozeki test SMS", initially, you have to convert it to a PDU format message. Refer to the SMS protocol description for instructions on how to construct the PDU message. Note that the actual length of the PDU string (without the Service Centre Address) must be specified for all SMS. Follow the steps below for sending the SMS message.
- Step 1. Enter the actual length of the SMS message in octets: AT+CMGS=18
- Step 2. Enter the SMS message in PDU format and terminate it with “CTRL Z”
- >>0011000A81409178699100000105E8329BFD06[CTRL Z]
- The SMS modem should return: +CMGS: 12 OK
- 12 is the message reference MR, which is different for every SMS message sent
- Store the MR for later to be able to identify delivery reports
Key takeaways
This document explains how to send SMS messages from a GSM modem to a mobile phone using AT commands. AT commands are instructions used to control and configure modems.
The guide outlines two methods: text mode and PDU mode. Text mode is simpler but offers less control over the message. PDU mode requires converting the message to a specific format but provides more options.
To send an SMS using AT commands, you'll need an SMS modem, SIM card, antenna, and terminal software. The guide details hardware setup, communication settings, and modem initialization steps.
More information
- How to receive an SMS Message with a modem using AT commands
- How to send an SMS with a GSM modem using AT commands
- SMS Protocol explained
- Introduction to SMS PDU Mode
- How to use an SMS modem on a virtual machine
- Ozeki 4G SMS Modem
- Ozeki 4G SMS Modem Dual Sim
- Ozeki SMS Gateway One
- Ozeki SMS Gateway PLC
- Compare SMS devices