Hack 12. Send SMS from Linux

Tired of one letter typing on your phone keypad? Send complete SMS messages from Linux instead.

As shown in "Send SMS from a PowerBook" [Hack #7] and "Control Your Bluetooth Phone with FMA" [Hack #14], it's relatively simple to set up your Bluetooth phone so that you can send Short Message Service (SMS) text messages using your computer. Fortunately, there's also a way to do this in Linux.

In order to make this work, you'll need to have your Bluetooth phone paired and configured as a dial-up networking device [Hack #4]. Once those tasks are done, your phone will be communicating with your Linux box using Bluetooth, and you will have a new serial device mapped to /dev/rfcomm0 that you can use.

What this means practically is that you can treat your Bluetooth phone as a modem, and send it standard AT commands, using any serial terminal program like gkermit, minicom, or screen.

To find out whether your phone lets you send SMS messages using AT commands, you'll need to connect to your phone with one of these programs, and execute the query AT+CSMS=0. Here is an example using the screen program:

	screen /dev/rfcomm0
	ATE1 #this won't be echoed to the screen, but it turns echo on
	OK
	AT+CSMS=0
	+CSMS: 1,1,1

	OK 

The output after the AT+CSMS=0 command is listed in three columns, which indicate whether the device is capable of receiving messages, sending messages, or sending broadcast messages. In this case, the phone is capable of all three.

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/index.html) to send the message:

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

Brian Jepson


Bluetooth, Mobile Phones, and GPS

Network Discovery and Monitoring

Wireless Security

Hardware Hacks

Software Hacks

Do-It-Yourself Antennas

Wireless Network Design

Appendix A. Wireless Standards

Appendix B. Wireless Hardware Guide



Wireless Hacks
Wireless Hacks: Tips & Tools for Building, Extending, and Securing Your Network
ISBN: 0596101449
EAN: 2147483647
Year: 2004
Pages: 178

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net