Jazzy
Jazzy

Reputation: 344

How to send a text message via AT+CMGS?

I am testing different AT commands including the one used for sending a text message, which is AT+CMGS.

From what I've read online, you just need to provide a phone number as shown below and enter CTRL-Z to send a message but nothing really happens when I press CTRL-Z

echo -e "AT+CMGS='"<phone_number>"'"\r" > /dev/<port>
> Sending message...
<PRESS CTRL-Z but nothing happens>

Upvotes: 1

Views: 1670

Answers (1)

Roberto Caboni
Roberto Caboni

Reputation: 7490

I assume that, after sending characters to your port with echo -e, you also get the output from your serial port with

cat /dev/<port> &

so that every answer from the modem is automatically redirected to your console.

In this case, the character > doesn't mean you can directly send the text; you'll have to go on sending it with echo -e. Here is the sequence of commands, with some comments on the right that obviously don't have to be included

echo -e "AT+CMGS='"<phone_number>"'"\r" > /dev/<port>  // Command
>                                                      // Modem's response
echo -e "My text!\x1A" > /dev/<port>                   // Send text

+CMGS: XYZ                                             // Response to SMS sending
OK                                                     // It can take several seconds

Please note how binary data is sent through \xAB escape sequence, where AB is the ASCII value of the character you want to append. More info on the manual page.

Upvotes: 1

Related Questions