Sie sind auf Seite 1von 2

Send SMS using a USB Modem and Ubuntu 12.

04
Posted on April 12, 2013

I developed a Java ERP system for a customer and he asked me if the system could send
SMS messages. My first thought was to pay a SMS Gateway, the internet has thousands
of them, easy to use, relatively cheap and fast to integrate.
But, there is always a but, I discovered that my customer has several Huawei E173
GSM USB modems with a SMS plan! They have the hardware, they already pay for
SMS, so why not use these modems?!.
So here it is, a simple way to send SMS using a Huawei E173 GSM USB modem in a
Ubuntu Server 12.04.
The E173 modem that Im using, when plugged in, will emulate a CD-ROM driver
containing the software needed by this modem. The modem device will not be available
unless we switch mode the USB device, this is called a flip flop USB device. To
handle that we need to install the usb_modeswitch(usb_modeswitch) if it isnt already.
This command will install the usb-modeswitch and the gsm-utils that will do the
magic:
1 apt-get install usb-modeswitch gsm-utils
Before connecting you modem to the USB port, run this command:
1 tail -f /var/log/syslog
Go ahead, connect the modem, wait some seconds(+5) and you will see something like
this:

1
2
3
4
5
6
7
8
9
1
0

Apr 12 11:26:00 server kernel: [ 1862.731001]


speed USB device number 3 using ehci_hcd
Apr 12 11:26:01 server kernel: [ 1863.381742]
modem (1-port) converter detected
Apr 12 11:26:01 server kernel: [ 1863.382231]
port) converter now attached to ttyUSB0
Apr 12 11:26:01 server kernel: [ 1863.382279]
modem (1-port) converter detected
Apr 12 11:26:01 server kernel: [ 1863.382321]
port) converter now attached to ttyUSB1
Apr 12 11:26:01 server kernel: [ 1863.385510]
1:1.2
Apr 12 11:26:02 server kernel: [ 1864.386423]
ROM
HUAWEI
Mass Storage
2.31
Apr 12 11:26:02 server kernel: [ 1864.398748]
Apr 12 11:26:02 server kernel: [ 1864.399381]
scsi CD-ROM sr1
Apr 12 11:26:02 server kernel: [ 1864.400494]
scsi generic sg2 type 5

Press Ctrl+C to exit tail.

usb 1-1: new highoption 1-1:1.0: GSM


usb 1-1: GSM modem (1option 1-1:1.1: GSM
usb 1-1: GSM modem (1scsi4 : usb-storage 1scsi 4:0:0:0: CDPQ: 0 ANSI: 2
sr1: scsi-1 drive
sr 4:0:0:0: Attached
sr 4:0:0:0: Attached

Send SMS using a USB Modem and Ubuntu 12.04


Posted on April 12, 2013

If you see a line like this "GSM modem (1-port) converter now attached to
ttyUSBX" means that your modem is ready to use.
And finally, how to send a SMS message(In my case my modem is in /dev/ttyUSB0 and
the baudrate is 19200, change according to your setup):
echo "SMS Test Message!" | gsmsendsms -d /dev/ttyUSB0 -b 19200

1PHONE_NUMBER

There should be no output. The exit code is 0 if everything is OK, greater than 0 if fail.
Great, I already can send SMS using the console, but I need to integrate into my
application. The fastest and easiest way is to call the same command I ran in the
console.
1
2
3
4 public static boolean sendSmsSynchronous(final String phone, final
5 String message)
{
6
final ProcessBuilder processBuilder = new
7 ProcessBuilder().command("/usr/bin/gsmsendsms", "-d",
8 "/dev/ttyUSB0", "-b", "19200", phone, message);
Process gsmsendsmsProcess;
9
try
1
{
0
gsmsendsmsProcess = processBuilder.start();
11
gsmsendsmsProcess.waitFor();
}
1
catch (final Exception e)
2
{
1
return false;
3
}
1
4
return gsmsendsmsProcess.exitValue() == 0;
1 }
5
1
6

Das könnte Ihnen auch gefallen