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:

  1. Check the prerequisites for sending an SMS from a modem
  2. Set up the hardware
  3. Configure the communications settings
  4. Reset the SMS modem to factory default
  5. Initialize the modem
  6. Use the appropriate SMSC number for your mobile network
  7. Enter the actual length of the SMS message in octets
  8. Construct the PDU message to send test SMS in PDU mode
  9. Refer to the SMS protocol description for instructions
  10. Send a test SMS message in Text mode

Hardware Requirements for sending an SMS from a modem

  1. An SMS modem
  2. A SIM card (You put the SIM card into the SMS modem)
  3. A GSM antenna connected to the SMS modem
  4. A power cable for the SMS modem
  5. A phone-to-pd data cable that connects the modem to the PC
  6. A PC running a terminal software such as Ozeki Terminal.
  7. A mobile phone that is capable of receiving the SMS messages

Hardware setup

  1. Insert the SIM card into the modem
  2. Attach the antenna to the modem
  3. Connect the SMS modem to a PC with the phone to PC data cable
  4. Turn on the PC and run Ozeki Terminal.
  5. 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.

  1. Set the SMS modem for text SMS using: AT+CMGF=1[ENTER]
  2. Enter the destination phone number in international format AT+CMGS=”+36419879619”[ENTER]
  3. Enter the text message and terminate it with “CTRL Z”: >hello[CTRL Z]
  4. The SMS modem will return: +CMGS: 1 OK
  5. 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.

  1. Step 1. Enter the actual length of the SMS message in octets: AT+CMGS=18
  2. Step 2. Enter the SMS message in PDU format and terminate it with “CTRL Z”
  3. >>0011000A81409178699100000105E8329BFD06[CTRL Z]
  4. The SMS modem should return: +CMGS: 12 OK
  5. 12 is the message reference MR, which is different for every SMS message sent
  6. 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