Linux Unwired [Electronic resources]

Edd Dumbill, Brian Jepson, Roger Weeks

نسخه متنی -صفحه : 100/ 63
نمايش فراداده

9.5 Text Messaging

Some phones and modems let you send a text message via Short Message Service (SMS) using AT commands. To find out whether your device supports this (nearly all GSM devices do), connect with Kermit, as shown in Example 9-1, and issue the query AT+CSMS=0 (the three columns indicate whether the device is capable of receiving messages, sending messages, or sending broadcast messages):

AT+CSMS=0
+CSMS: 1,1,1
OK

If your cell phone supports this capability, you can work with text messages using AT commands. You can list your text messages with AT+CMGL=4 (the 4 indicates all messages: use 0 for unread, 1 for read, 2 for unsent, and 3 for sent messages) and read a message with AT+CMGR=MESSAGE_NUMBER:

AT+CMGL=4
+CMGL: 1,1,,28
07919170389103F2040B91XXXXXXXXXXF100013011320211500A0AD3771D7E9A83DEEE10
+CMGL: 2,1,,25
07919170389103F2040B91XXXXXXXXXXF100013011329135610A06C8F79D9C0F01
OK
AT+CMGR=1
+CMGR: 1,,28
07919170389103F2040B91XXXXXXXXXXF100013011320211500A0AD3771D7E9A83DEEE10
OK

However, you'll want to put the phone into text mode, so the responses that you receive are human-readable. Use AT+CMGF=1 for this, and try reading the message again:

AT+CMGF=1
OK
AT+CMGR=1
+CMGR: "REC READ","+14015559000",,"03/11/23,20:11:05-20"
Soup's on!
OK

You can send a message with AT+CMGS="PHONE_NUMBER" (but make sure you've set responses to be human-readable with AT+CMGF=1). You'll be prompted for the message; type it and press Ctrl-Z when you are finished:

AT+CMGF=1
OK
AT+CMGS="4015559000"
> Hello, world!^Z
OK

You can also use the gsmsendsms utility from gsmlib (http://www.pxh.de/fs/gsmlib/indexl) to send the message:

bjepson@debian:~$ gsmsendsms -d /dev/ttyUSB0 4015559000 "Hello, World"