SMS Texting using 3G dongle
I initially did this on a Raspberry Pi, but have since moved to various other Linux flavours and platforms. The instructions below can still be used if the similar issue is experienced.
The problem I’m having to solve is that the 3G Dongle isn’t being recognised as a serial port, it is being recognised as a storage device. Even though the description obtained from lsusb clearly identifies it as a modem.
root@rasp-storage:~# lsusb Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp. Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. Bus 001 Device 004: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB Bus 001 Device 005: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB Bus 001 Device 006: ID 12d1:1446 Huawei Technologies Co., Ltd.E1552/E1800/E173 (HSPA modem)
Anyway, before we get started ensure the system is up to date. I’m using the latest Raspian so its a simple case of:
apt-get update
apt-get upgrade
The tool we are going to be using is called usb-modeswitch.
root@rasp-storage:~# apt-cache search modeswitch
usb-modeswitch - mode switching tool for controlling "flip flop" USB devices
usb-modeswitch-data - mode switching data for usb-modeswitch
root@rasp-storage:~# apt-get install usb-modeswitch usb-modeswitch-data
I found the information for the usb_modeswitch elements by googling the “Huawei E173 modem”, the details below are unlikely to work on other 3G modems. Create a file named 12d1:1446 under /etc/usb_modeswitch.d/
which contains:
DefaultVendor=0x12d1 DefaultProduct=0x1446 MessageContent="55534243123456780000000000000011062000000100000000000000000000"
Create a file /usr/local/sbin/3gmodemswitch
containing.
usb_modeswitch -I -W -c /etc/usb_modeswitch.d/12d1\:1446
Create a file /etc/udev/rules.d/99-3gmodem.rules
which contains:
ACTION=="add", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1446", RUN+="/usr/local/sbin/3gmodemswitch"
So when the modem is plugged in, udev rules pick it up and execute the 3gmodemswitch script, which in turn calls usb_modeswitch. If we have a look at the output from lsusb now, we see:
lsusb Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 009: ID 12d1:1506 Huawei Technologies Co., Ltd. E398 LTE/UMTS/GSM Modem/Networkcard
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0781:5571 SanDisk Corp.
Bus 001 Device 005: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
Bus 001 Device 006: ID 1a40:0101 Terminus Technology Inc. 4-Port HUB
root@rasp-sms:/etc/usb_modeswitch.d#
I was able to reboot, and do a complete power down restart, and the modem continued to be recognized as a 3G modem. It should be noted I have in the past experienced an issue where the root filesystem was not on the SD card, but a USB drive. However when starting the Pi in that configuration sometimes the built in storage of the 3G modem was identified as SDA rather than the USB thumb drive. To fix this situation I made sure to use the root=PARTUUID=XXXXX notation in the /boot/cmdline.txt file. Finally, install smstools using:
apt-get install smstools
Following which edit the /etc/smsd.conf file and append the following to the bottom (using the correct ttyUSB device:-
[GSM1]
#init =
device = /dev/ttyUSB0
incoming = yes
#pin =
baudrate = 19200
Now when I drop a file into the /var/spool/sms/outgoing/ directory in the format:
To: 444797575B134
Hello From My Raspberry Pi. :)
Incidentally the number above is random, furthermore I put a letter B in the text on purpose just to save some poor soul getting unsolicited texts by anyone reading this and simply copying the text.
So with a little more scripting, I now use this Raspberry Pi as a notification server, it polls other devices (predominately network equipment) and services and text’s me if there are problems. I can also sent it texts to perform simple actions, but that element is still very much a work in progress.