SMS Gateway, OpenWRT from TP-Link TL-WR1043ND and Pro-Link PHS-100

SMS Gateway, OpenWRT from TP-Link TL-WR1043ND and Pro-Link PHS-100

Cheap SMS Gateway

OpenWRT, TP-Link TL-WR1043ND and Pro-Link PHS-100


By using OpenWRT, TP-Link TL-WR1043ND and Pro-Link PHS-100 I wanted to make a small, cheap and use full SMS gateway. So in conditions when I am abroad I can send/receive messages to my friends in my home country. I chose this device as it consumes less power, as it works on 12v and is < 1A DC device, it can be placed any where or could be mounted on wall. I have also ported OpenWRT so it can be used as simple x86 machine/server. I was able to compile Pro-Link PHS-100 and 300 drivers onto it and smstools. The whole procedure for the setup is defined below.

Installing Prolink PHS-100 on OpenWRT

root@OpenWrt:/# opkg install kmod-usb-serial kmod-usb-serial-wwan kmod-usb-serial-option
If you don’t already have installed them,
otherwise move forward, plug ProLink PHS-100 to USB port of TP-Link,
root@OpenWrt:/# dmesg
[   12.140000] USB Mass Storage support registered.
[   12.270000] USB Serial support registered for GSM modem (1-port)
[   12.270000] usbcore: registered new interface driver option
[  ;  12.280000] option: v0.7.2:USB Driver for GSM modems
[   13.140000] scsi 0:0:0:0: CD-ROM            PROLINK  HSDPA Modem      2.31 PQ: 0 ANSI: 0

Which means the TPLINK has detected something interesting on it’s USB Port, now the modem is in  USB Flash storage mode which means you can read/write to its flash port but can’t use it as GSM Modem. The device when ever turns on or plugged in, it will always be in storage mode. You need a utility to switch its mode to GSM Modem.

opkg install
let it download and install all other dependencies/packages as well,
as the above step finishes create a new configuration file to be used with usb_switch utitlity.
vi /etc/usb_switch.conf

# Option iCON 210
# PROLiNK PHS100 (various looks)
# Hyundai Mobile MB-810
# One report of switching with DetachStorageOnly. Needs at least
# a second to settle before binding to usbserial
# Contributor: wahlm, Peter Kraker, Pakdhetimin Sekum

DefaultVendor=  0x1e0e
DefaultProduct= 0xf000

TargetVendor=   0x1e0e
TargetProduct=  0x9000
TargetClass= 0xff

Now Run the following Command,
root@OpenWrt:# usb_modeswitch -c /etc/usb_switch.conf

If it runs without any error you should see, 

root@OpenWrt:/tmp/spool/sms/outgoing# ls /dev/tty*
/dev/tty      /dev/ttyS0    /dev/ttyUSB0  /dev/ttyUSB1  /dev/ttyUSB3
/dev/ttyUSB* (0,1,2) all devices has relation with Prolink PSH-100.

One of these three ports is the one you need, to find execute the following, but before this you need to download and compile for MIPS.
smstools is a daemon which sends and receives sms.

Compile it for MIPS architecture

Use Ubuntu or any other linux distro, install the packages required for development and install openwrt cross compiler from openwrt’s site. I have already posted how to compile kernel and other packeges for MIPS arch, You can find it in my other posts.
All the packages installed.

vi smstools3/src/Makefile

set CC='path to your mips-gcc compiler'
in my case,
run make, after successful make copy smsd from src directly to your openwrt router.
now to check which of your ttyUSB is the one used as source for sending sms execute the following,

create a file in /etc/smsd.conf

devices = GSM1
logfile = /var/log/smsd.log
loglevel = 7
device = /dev/ttyUSB2
incoming = no
# Service Center Address
smsc = +923455000010
send_delay = 10
baudrate = 19200
report_device_details = yes
rtscts = no
execute the following command:
smsd -C COM1
follow the prompt and press enter
if reponse is OK this is the port you can use in your smsd.conf (mentioned above) for sending msgs,
if theres no message try other ports when prompted for device above.
now a very important step,
If you plug PHS-100 to a linux box the light will always be red and the reponce of AT+CREG? will always be 0,0 in this case the device will never be able to register with network, a workaround to this is,, read this blog, it has very useful information.
it turned out that the modem needs to be sort of activated in Windows. Plug the modem in a Microsoft Windows machine and wait until the manager software runs, connect internet and the LED of the modem turns magenta. Without doing anything else, unplug the “activated” modem. If this step that I discovered accidentally is not done, wvdial will always get stuck with error message “No network protocols running” due to IPCP Config-Requests timeout and the LED of the modem will always be red in the GNU/Linux machine. Otherwise, the LED will start with red and then turn to magenta and wvdial will succeed. To deactivate the modem, simply plug the modem in a Microsoft Windows machine, wait until the manager software runs, and without doing anything, close the manager. You will be see a prompt that should be answered with OK. Then, the LED of the modem will turn red.
Connect modem to TP-LINK again the LED should turn green,
ssh into and run smsd -c /etc/smsd.conf &
Create the following directories to make it work:
/var/spool/sms/outgoing, /var/spool/sms/incoming, /var/spool/sms/checked
create a file in /var/spool/sms/outgoing/send.sms
vi  /var/spool/sms/outgoing/send.sms
To: +923xxxxxxx
Text of the SMS.
The message will be moved to checked directory before it is sent and will be removed from the outgoing directory, you can verify the behavior in log file. all the msgs recieved will be placed in /var/spool/sms/incoming/ directory, each message in saperate file.
I’m working with a friend who will create an interface for this which will be released as Open-Source Software. An web interface which could be accessed through a web browser for sending and receiving messages.

In order to automate the process you need to run the 'usb_modeswitch' and /usr/sbin/smsd -C /etc/smsd.conf on each reboot or run it through /etc/rc.local.
Please fell free to contact in-case of bugs or suggestions.