I’ve used gnokii to set up a SMS server in our college as a part of Spider Project. Though I didn’t actually believe that a computer and a mobile phone can be connected when Manas suggested the idea, I coded much for this SMS server later. 😛
So here is the short manual about how to configure gnokii in a system. Let us assume that we have a basic Fedora or Ubuntu installed machine, a Nokia 7250i mobile and an USB data cable.
Gnokii Installation :
This can be done in two ways like any other open source software.
Installing from binary.
Installing from binary is very easy if you have yum (Fedora) or apt (Ubuntu) configured for your system. All you need to do is to execute the following command as root or as sudo
In Ubuntu the command is
hari@spider:~$ sudo apt-get install gnokii gnokii-smsd gnokii-smsd-mysql
In fedora the command is
root@spider:~# yum install gnokii gnokii-smsd gnokii-smsd-mysql
The above packages have lots of dependencies like libgnokii3, liblockfile1, timeout, dialog, mysql-common, libmysqlclient15off. So it is better to install gnokii using yum (Fedora) or apt (Ubuntu) instead of rpm (Fedora )or dpkg (Ubuntu).
Installing from Source:
This will be useful if you don’t have a yum or apt configured. Download the source package from http://www.gnokii.org/download/gnokii/. Then execute the following. I have used gnokii-0.6.9 for example. It might differ in your case.
[root@spider ~]# tar -zxvf gnokii-0.6.9.tar.gz
[root@spider ~]# cd gnokii-0.6.9/
[root@spider gnokii-0.6.9]# ./configure
[root@spider gnokii-0.6.9]# make
[root@spider gnokii-0.6.9]# make install
Gnokii Configuration :
Once gnokii is installed, we need to change the configuration file (gnokiirc) and check whether the computer can identify the mobile phone. The configuration file can be located at two places. One in your home folder and the another in /etc.
If there is no file in your home folder, then gnokii uses the configuration file present in /etc.
The mobile phone i use is Nokia, model 7250i, type NHL-4JX.
For the example below, let us assume that you have permissions to edit the configuration file in /etc. Else copy the file from /etc and do the changes mentioned below.
1. Open gnokiirc file in any editor as root or sudo.
2. Since I’m using an USB cable to connect the mobile to computer, set the value of port as “/dev/ttyUSB0” (quotes for clarity).
This value may rarely change from computer to computer. You can from the output of the command “dmesg | tail” after you connect the USB cable to the computer. I get an output like this
[ 325.740151] pl2303 2-1:1.0: pl2303 converter detected
[ 325.740847] usb 2-1: pl2303 converter now attached to ttyUSB0
[ 325.741245] usbcore: registered new interface driver pl2303
[ 325.741253] /build/buildd/linux-source-2.6.22-2.6.22/drivers/usb/serial/pl2303.c: Prolific PL2303 USB to serial adaptor driver
So in line 2, I know that that it is ttyUSB0.
3. Set the model as AT
4. Set the value of connection as serial
Then execute the command “gnokii –identify”. The above command shoud produce an output like
hari@spider:~$ gnokii --identify
GNOKII Version 0.6.18
IMEI : 352955008063785
Manufacturer : Nokia
Model : Nokia 7250i
Product name : Nokia 7250i
Revision : V 4.63
If the command takes more than 5 or 10 seconds, than it just means that the computer hasn’t identified your mob yet. Remove the data cable from mob and USB cable from computer. Connect them once again and try. This time it may work. This has happened so many times in my machine. Still not able to come up with a nice reason why this happens 🙂
Once the computer has identifed your mobile phone, you can do lots and lots after that. 🙂
man gnokii will give you a huge list of commands which you can use to control your mob. Some of them which will be useful for SMS interface is
gnokii --getsms SM 1 end
Above command reads all the messages stored in SIM memory
gnokii --getsms ME 1 end
Above command reads all the messages stored in phone memory.
See man gnokii to see more options for getsms.
To send SMS using gnokii, try this command
echo "Spider SMS Server" | gnokii --sendsms 9940557688
Working with smsd
Once gnokii is configured, we can use smsd to send messages. This is more like a wrapper for gnokii. After you install gnokii-smsd, a database called SMS is created in your database.
To start the smsd server, you run the command
smsd -h or smsd --help will be quite useful if you can’t remember the above options.
Once smsd is running, any SMS which comes to the mobile is taken by the computer, stored in the inbox table and then deleted. Similarly any entry added in outbox is sent to the destination. An very useful field in these two tables is “processed”. Any message which is added to the inbox has a default “processed” value of “0”. So once we are done with this message, we should change the value to 1. Any message which is inserted in the outbox has a default “processed” value of 0 and “error” value -1. If the message is sent successfully, the value of processed and error is changed to 1 and 0 respectively. If there is any error in sending the message, the value of processed and error is changed to 1 and some positive integer. Also note that changing the value of processed in outbox to 0 will result in resending the message again.
So any script which checks the inbox table every 5 seconds for messages with processed = 0 and does the required action when there is any new message will complete the SMS server model.
This PHP script sends a “Thank you” message to anyone who sends any message to the SMS server.
This PHP script sends mass message to all the numbers in a text file
This PHP script sends mass message to all the numbers in a mysql table
This is the PHP script I used for LEO poll.
You can download all the above scripts as a single zip file here.