Using Gnokii and a Nokia 6310i to post text-messages (SMS) to a weblog

preview of the functioning service

preview of the functioning service

Can I use a mobile phone to send a text-message (also known as SMS) to my weblog / website ? Yes, you can. Fairly easy as well. I’m using:

  • An old Nokia 6310i
  • Gnokii
  • My Mediacenter
  • A common BlueTooth stick I had laying around

Ofcourse, to receive the messages on the phone, it should be fit with a SIM card, preferably a dedicated one to the service.

The Set-up.

What we need, is in fact an SMS-Gateway. This is exactly where Gnokii comes into play:

gnokii provides tools and a user space driver for use with mobile phones under various operating systems…

Installing Gnokii was easy: since I was playing with my mediacenter running Ubuntu, all I needed was apt-get.

apt-get install gnokii gnokii-smsd gnokii-smsd-mysql

Connecting Ubuntu to the Nokia using Bluetooth.

I already had the BlueTooh libraries set up, since I once fiddled with the Wii-mote. Therefore I figured connecting the machine to the 6310i would be easy. Well, I was wrong: this part is what took me longest. The hard part was in pairing the Nokia an the computer. I started testing without pairing, so I had to authorize the computer for every action. After a while, this gets pretty annoying :)

Using the hcitool, I could not get the connection to work. Now, I’m not exactly sure how it works, but it does. The key was in editing /etc/bluetooth/hcid.conf.  A few things need to be set here: in the options section, i set:
autoinit yes;
security auto;
pairing multi;
passkey "0000";

I did use a different passkey, actually :) . Now head on to the device section. Mine looks like this:
name "%h-%d";
class 0x120104;
iscan enable; pscan enable;
discovto 0;
lm accept;
lp rswitch,hold,sniff,park;

The important part was in the class. This was originally set to 0×000100 and that’s exactly what kept the phone from pairing. The man page explains everything, I just copy-pasted it from developershome. This made the computer available to be paired with the 6310i.

Now start the BlueTooth services by typing

/etc/init.d/bluetooth start

… and find your phone’s BlueTooth address:

hcitool scan

Copy the default gnokiirc to your home directory:

cp /etc/gnokiirc ~/.gnokiirc

… and set the port to the BlueTooth address of your mobile phone.  Also, choose the appropriate model. For my phone, this was 6510. Set the program to use BlueTooth. When starting the tests, you might want to turn on all logging.

port = 00:02:EE:B3:03:0C
model = 6510
connection = bluetooth

Gnokii is set up, try it by typing

gnokii --identify

As soon as you don’t receive any error messages, your setup is done and you can now setup the smsd.

Setting up smsd to read the messages and store them in MySQL.

SMSD is the daemon that receives the messages from the phone and can then store them or at least handle them. I chose to store them in MySQL, so I could use the tool of my choice to read the database and handle the message in a flexible manner. The steps are quite easy: create a MySQL database and user and create the tables. I also created a logfile to use maximum logging capacities.

sudo touch /var/log/gnokii-smsd-log
sudo chmod 777 /var/log/gnokii-smsd-log
mysql -u root -p
create database gnokii;
grant all on gnokii.* to gnokii@localhost identified by 'password';
flush privileges;
exit;
mysql -u gnokii -p gnokii < /usr/share/doc/gnokii-smsd-mysql/sms.tables.mysql.sql

Now, to run the smsd i created a simple-to-remind script in my scripts directory saying:
/usr/sbin/smsd -u gnokii -p qwertyui -d gnokii -c localhost -m mysql -f /var/log/gnokii-smsd-log &

… and i ran it, ofcourse. On the first run, all existing messages are copied to the table inbox.  The developers have been nice and have created an extra column processed, which defaults to 0.  This makes it very easy to process the messages and then set processed to your value of choice.

Posting the messages to a website.

Now, to post the messages to a website, I created a simple script to extract the message, rewrite it to an accepted format ( I wouldn’t want the world to read all phone numbers ) and then use cURL to create a POST request on the website of choice. In this case, it’s a weblog where messages are put into the shoutbox, enabling readers or users to keep submitting their feedback. The service will be alive for a few days or weeks to test how reliable it is.

Resources.

  1. http://www.debian-administration.org/articles/419

    Whilst there are several sites where users can post questions and have answers contributed by other users there are no other sites on the web which are specifically targeted at distributing articles of interest to Debian administrators. This site is designed to fill that void, with content accepted from users.


  2. http://www.developershome.com/sms/smsLinux.asp

    Here you can learn various mobile technologies like WAP / WAP 2.0, WML, WMLScript, XHTML MP, WCSS / WAP CSS, UAProf and SMS through our free tutorials, articles and examples. This web site can help web programmers who wish to extend their knowledge to the wireless world. We will introduce to you the skills needed to develop and maintain sites and applications for wireless devices. Code examples provided in the tutorials and articles follow the standard of the corresponding technology. After reading our tutorials and articles, you will understand how to build your own mobile application using the latest technologies.

  3. http://www.gnokii.org/
    The Gnokii homepage
  4. http://linux.die.net/man/5/hcid.conf
    The man page for hcid.conf

Discussion.

Ofcourse, this is not the most reliable or fast way to post text messages onto a website. But i didn’t cost a cent and it’s a cool project to try-out.

Disadvantages:

  • maybe unreliable
  • an extra computer should be online,  just to post messages

Advantages:

  • Cheap
  • Flexible
  • Quick setup
  • Fun to play with

Future.

In the future, and when proven succesfull, I might extend this first flirt with gnokii to maybe adding keyword-binding or an automated response. Another possibility lies in creating profiles, so that users can format the way their shout is shown. Got any ideas? Feel free to comment!

Add to your favorites:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • StumbleUpon

This entry was posted on Saturday, November 15th, 2008 at 17:38 and is filed under Blog, BlueTooth, Commandline, Games, Gnokii, HTPC, Hardware, Logs, MacStuff, Mediacenter, MySQL, Nokia, PHP, Tech, Testing, Ubuntu, Unix general, apt-get, cURL. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response to “Using Gnokii and a Nokia 6310i to post text-messages (SMS) to a weblog”

Anup August 24th, 2009 at 21:39

Hi i was also trying to implement the same thing out.I was sucessful with gnokii part of it and now the problem is smsd is not sending out the messages.

Leave a Reply