How to Send Sms Using at Commands

How to Send/Receive SMS using AT commands?

Here's some example code that should get you started (in Python 3000):

import time
import serial

recipient = "+1234567890"
message = "Hello, World!"

phone = serial.Serial("/dev/ttyACM0", 460800, timeout=5)
try:
time.sleep(0.5)
phone.write(b'ATZ\r')
time.sleep(0.5)
phone.write(b'AT+CMGF=1\r')
time.sleep(0.5)
phone.write(b'AT+CMGS="' + recipient.encode() + b'"\r')
time.sleep(0.5)
phone.write(message.encode() + b"\r")
time.sleep(0.5)
phone.write(bytes([26]))
time.sleep(0.5)
finally:
phone.close()

You need to do two additional things:

  • Encode the message in the appropriate format (mostly GSM 03.38, there's a handy translation table at unicode.org). If you really don't care about any characters other than ASCII, you can just check if every character is in string.printable.

  • Check the length of the message (I'm not sure if it's to do with the encoding, but it's sometimes 140 characters, sometimes 160).

You can use phone.readall() to check for errors, but it's best to make sure your message is OK before you send it off to the phone. Note also that the sleeps seem to be necessary.

Most phones will understand this. In order to get my old Nokia C5 to open up the serial connection, I had to select "PC Suite" from the menu that pops up when you insert the USB cable. This should work equally well over Bluetooth.

The code uses the PySerial package, available for python 2 and 3.

See also:

  • How do i go about writting a program to send and receive sms using python?

name instead of number to send sms using AT commands

Actually,
The sender can not send normal SMS message so that the receiver can read his name.
The receiving terminal can have capacity to search the number from phonebook and replace the number.
When the SMS is sent, then the number of the sender is not coded in to sending sms, because it is the feature of the network:
When the MO SMS (SMS-Submit) is converted into MT- SMS (SMS-Deliver), then the number of the receiver
"is replaced" with the number of the sender.
So you can not send the name instead of the number when you are using SMS.
The network provider needs to be contacted in case a specific name/number needs to be displayed. AT commands would accept only the phone number as the CMGS parameter.
Hope this answers your question.

How to send long message using AT Commands, vb.Net

SMS length is limited to 160 seven-bit characters. It was subsequently codified into the SMPP signalling protocol that transmits SMS and is limited to precisely 140 bytes (or 1120 bits).

try reading this

Sending multi part sms with GSM using AT Commands

General AT command handling

You are on the right track, I am pleased to see several basic things done right (terminating AT command lines with \r, waiting for "\r\n> " for AT+CMGS, and waiting for the OK final result code instead of sleeping), very good start!

You do need however to change the structure somewhat. First you need to handle all the other final result codes and not just OK. And you should treat the AT+CMGS command differently from the other commands since you should wait for two things (first the prefix and later the final result code after sending the message text) for that command compared to waiting only for one thing (e.g. the final result code) for those. Also all responses from the modem are complete lines (except the "\r\n> " prefix), so change your algorithm to process the response(s) line by line.

String input;
do {
input = ReadLine(port, responseTimeout);
} while (!isFinalResultCode(input));

None of the commands you are using in the question produces an intermediate response for consumption, but if you were to run a command like AT+CPBR you would consume those intermediate responses inside that loop (and you would have to move the final result test into the loop before attempting to consume the line as an intermediate response).

You can see the is_final_result function in atinout or corresponding functions in ST-Ericsson's U300 RIL (see link and notes in this answer).

Multipart SMS

I think this is not possible in text mode. See the link suggested by Naser Asadi for details on multipart SMS in PDU mode. Also some useful information at
http://mobiletidings.com/2009/02/18/combining-sms-messages/ and http://developer.nokia.com/community/discussion/showthread.php/109602-Concatenated-SMS-in-PDU-Mode.



Related Topics



Leave a reply



Submit