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. :P
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 -u
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.

May 19th, 2008 at 6:55 am
This is a fine guide, but I am wondering what to do when things go wrong. I get the right response from –identify, but when I try to send an sms it looks like this:
echo “Testing message in a bottle!” | gnokii –sendsms 5550124
GNOKII Version 0.6.14
SMS Send failed (Unknown error - well better than nothing!!)
May 25th, 2008 at 9:44 pm
Possible cause, the SMS center is not readable by gnokii. tTry gnokii –getsmsc first. If it says command error, you have to specify –smsc param manually.
May 26th, 2008 at 1:35 am
Btw.. I have found a work around for this one. We can use connect script to set the SMSC number into the phone.
1. Create a file, say /etc/gnokii-smsc-init.chat
=============================================
#! /usr/sbin/chat -vEf
TIMEOUT 10 “” “” ABORT “BUSY” ABORT “NO DIAL TONE” ABORT “ERROR” ABORT “VOICE” ”
”
AT+CSCA=+xxxxxx “OK”
============================================================
2. Modify the gnokiirc, set connect script
connect_script = /etc/gnokii-smsc-init.chat
+xxxxxx : The smsc number, it depends on your network carrier.
This should work, if not, check the syslog.
September 6th, 2008 at 5:37 pm
Hi. I can send sms with smsd and I can receive with “gnokii –smsreader” but i cant receive messages with smsd -m file. Why?
October 8th, 2008 at 4:53 am
Hi,
i have configured gnokii smsd but when i issued command as stated above i.e
smsd abcUser xyzPassword localhost mysql
it gives error : wrong number of arguments
can you please tell me how to use smsd command exactly with arguments
suppose [db_username = abcUser], [db_password = xyzPassword], [db_hostname = localhost],[module = mysql].
please help me as i am a newbie
October 8th, 2008 at 9:16 am
@shoaib
Try this
smsd –user abcUser –password xyzPassword –host localhost –module mysql
You better check the available options in http://linux.die.net/man/8/gnokii-smsd
November 6th, 2008 at 12:27 am
Hi
All are functioning as expected here except that I can’t save the sms in my database mysql
I”m following the instruction from http://invalid.name/wiki/index.php/Setting_up_an_SMS_Gateway and I got this error below by issuing this command: smsd -u -p -c -m mysql
dlopen error: /usr/lib/smsd/libmysql.so: cannot open shared object file: no such file or directory!
November 16th, 2008 at 11:35 pm
Eric, locate the file on which your system is giving dlopen error, when you find that file path make a symlink to the file with the location your system is giving error.
Thanks,
Shoaib
February 2nd, 2009 at 12:11 pm
hi..
how can i install gnokii-smsd and gnokii-smsd-mysql on centos 5.2. Already using yum install gnokii-smsd it’s failed. Please i need youe help.
February 2nd, 2009 at 12:18 pm
Are you the root user?
Is your yum configured to get packages from repos?
Can you try downloading from http://www.gnokii.org/download/ and see if you can compile the code from source?
Let me know if the above helps. :)
February 2nd, 2009 at 12:30 pm
Thanks for reply.
Yes im using root user and i have go to http://www.gnokii.org/download/ but don have gnokii-smsd also gnokii-smsd-mysql. It’s there else i can install?
February 2nd, 2009 at 12:33 pm
Hi,
If you install gnokii from there, I think it will have a smsd folder inside that. I generally install it from apt. I’m not too sure about gnokii-smsd-mysql, but I _think_ it also comes with gnokii package. I’m not too sure. Can you check this up and update me? :)
February 2nd, 2009 at 12:41 pm
Okay thanks, may i will check tomorrow… i want go to sleep… do have email add and contact no… can u send to my email… Thanks.
February 2nd, 2009 at 12:44 pm
Hey, yes I checked it. gnokii package has everything. :) Happy hacking :)
February 2nd, 2009 at 6:47 pm
Hi… are u there…
1. i already check in my linux machine and found smsd inside gnokii-6.11, but i don know how to configure.
2. Why only one time sent sms by using command line echo “testing” | gnokii –send 012XXXXXXX then i tried one more time it failed. This error msg SMS Send failed (Unknown error - well better than nothing!!)
Can you help me??!!!
February 15th, 2009 at 8:20 pm
Your are Great. And so is your site! Awesome content. Good job guys!
February 18th, 2009 at 4:22 am
Hi
thanx for providing such a useful tutorial
i have installed gnokii suscessfully and was able to send sms using command linke
but now tell me how to configure smsd properly and how to send sms via php .
the following error i got while running gnokii-smsd command.
plz give me brief answer to setup http interface
/usr/lib/smsd/libsmsd_pq.so: cannot open shared object file: No such file or directory!
Cannot load database module pq in directory /usr/lib/smsd!
February 18th, 2009 at 4:30 am
and cant run this command too
smsd -u -p -c -m mysql
smsd -h or smsd –help
February 18th, 2009 at 8:18 am
@tauseef hi,
you will have a file called libsmsd_pq.so in your current directory. You can copy paste it to /usr/lib/smsd/ folder. Also by default, smsd starts pqsql. If you want to try connecting to mysql, try starting with mysql module ( -m mysql)
Hope that helps
February 18th, 2009 at 11:14 am
thanx alot sir
my sms server is working fine now. how to make it start automatically. so that i dont have to run command manually
February 18th, 2009 at 11:23 am
@tauseef:
You can add the command in /etc/init.d/ folder. Read more on how to start a program when system boots :-)
March 3rd, 2009 at 5:06 am
Dear all,
I have the same configuration of this tutorial ( Ubuntu Server, gnokii GNOKII Version 0.6.22 , not .18, and the same nokia phone, 7250i). I follow all the steps and it’s all ok until I start the command “gnokii –identify”.
Here the final report is the following string:
Error in link initialisation: 11
Time out
Impossible to unlock the device
Why?
Thanks in advance for your reply
DDF
March 3rd, 2009 at 6:10 am
Hi ddf,
I’m just guessing this. Is your mobile phone locked when you try this gnokii –identify?
To be frank, it’s been a long time since I’ve worked with gnokii. But I’ll try my best to help you out. :)
March 3rd, 2009 at 7:26 am
Hi sp2hari,
I unlocked my phone by its menu and I reloaded the default settings, but nothing:according to you, what do I still have to do to unlock my phone?
About the cable, I’m using a compatible nokia cable DKU-5. It is detected from OS as “pl2303 converter now attached to ttyUSB0″ and its ID is “067b:2303 Prolific Technology, Inc. PL2303 Serial Port.” and reading from Gnokii’s wiki ( http://wiki.gnokii.org/index.php/Cables) the modules seem to be right.
In the config file “/etc/gnokiirc” I used:
“1st trial”
port = /dev/ttyUSB0
model = AT
connection = serial
but gnokii is locked on the AT commands for the initialization of the device. About this configuration I tried to send AT commands to my 7250i by Hyper Terminal, but I looked that it didn’t respond to AT commands (In the last weeks I tried the same commands on the Nokia 6680, which responded to the handshake commands at least :-D. I had to dismiss 6680, because it don’t support the “send / receive SMS” by gnokii).
“2nd trial”
port = /dev/ttyUSB0
model = series40
connection = serial
but gnokii is locked on the same handshake messages, but in a different format respect the AT ones. I used model = series40, because other users changed AT into series40 (http://www.nabble.com/Problem-connecting-to-Nokia-2610-td17298595.html).
“3rd trial”
port = /dev/ttyUSB0
model = 6510
connection = serial
but gnokii reports the above results.
I tried to change the connection option in “dku5″, but nothing.
I am open to every tip.
Thanks a lot
Best Regards
DDF
March 3rd, 2009 at 8:48 am
P.S.
I’m forgotting that the time out is on the “Getting model” command:
SM_Block: exiting the retry loop
Message sent: 0×1b / 0×0006
00 01 00 07 01 00
………………….
Impossible unlock the device
Cheers
DDF
March 3rd, 2009 at 1:00 pm
Just read some other comments on your blog, and I agree with the general impression, your doing a great job!Keep it up!
March 4th, 2009 at 12:14 am
zyprexa
Excellent site. It was pleasant to me.
March 4th, 2009 at 10:30 am
hi. I have the same problem and i resolved giving a permission to usb port, like:
chmod 777 /dev/ttyUSB0
i think thats resolve the problem
March 4th, 2009 at 11:30 am
I agree with what others have wrote, your writing some great articles, keep it up!
March 5th, 2009 at 1:30 pm
That was an amazing post, and it earned you a new RSS subscriber. Keep up the good work!
March 6th, 2009 at 4:46 am
For Marcus:
Hi Marcus,
I tried your tip, but nothing.
For All:
today I have a news. Gnokii runned only yesterday.
I setted:
port = /dev/ttyUSB0
model = AT-HW
connection = serial
I runned gnokii, but nothing.
I installed xgnokii
I runned xgnokii, but nothing.
I inserted another SIM (It seems the same of mine …. same provider and same KB ….. )
I runned xgnokii and SURPRISE: my GW sms runned.
Today is a bad day, because Gnokii doesn’t work and I don’t have the working SIM to test it. Accordijng to you, is it a possible reason or it was a simple coincidence?
Thanks in advance for your support
Cheers
March 23rd, 2009 at 11:12 pm
Hi
How are you am fine . i wana know that how to change the length of the sms to be sent for 160 characrters to 320 means 2 sms. plz give me a reply as soon as possible
March 24th, 2009 at 6:00 am
Hi,
I think by default gnokii sends a message of length 320 characters in 2 messages. I’m not too sure about it. Been a long time since I worked on this. But in case if it doesn’t do so, you can always change the logic which performs the mysql_insert to do two inserts instead of one.
Hope it helps…
April 14th, 2009 at 9:01 am
Hi,
The subject is nicely described…but I have a little problem while running the smsd.
Whenever I try this:
#smsd -u -p -d -c localhost -m mysql
I got this error : lowlevel.c:461 error: 8, unknown error
Anybody understand that? If yes, help me to fix it, it really does bother me
May 16th, 2009 at 9:24 am
Nice & perfect guide! It works just fine at all, thanks!
June 16th, 2009 at 4:10 am
I am trying to setup gnokii on ubuntu 8.10 for Nokia 6030..
my settings are
model : 6510
port: /dev/ttyUSB0
connection : serial
but when I run gnokii –identify
the output is :
GNOKII Version 0.6.26
Gnokii serial_open: open: No such file or directory
Couldn’t open ATBUS device: No such file or directory
Telephone interface init failed: Command failed.
Quitting.
Cannot unlock device.
Command failed.
I tried earlier with Nokia E50 and was successful in sending sms but was unable to read them, hence I tried on 6030 but this one is not even identified by gnokii..please help me ..