Gnokii + smsd

This page describes how to send, receive and store SMS messages automatically using a MySQL database.

aptitude install gnokii gnokii-smsd gnokii-smsd-mysql

Enable bluetooth on your mobile phone, and set it to be discoverable (eg. not hidden). Run the following command to find the phone's hardware address:

hcitool scan

Run the following command as root:

rfcomm bind /dev/rfcomm0 xx:xx:xx:xx:xx:xx

Replace the x's with the hardware address found earlier.

Create a file called .gnokiirc in your home directory:

model = 6021
# connection = bluetooth
# port = xx:xx:xx:xx:xx:xx
connection = serial
port = /dev/rfcomm0

In my case the model was the Nokia 6021. For generic AT command support, use "AT" as model. The lines commented out are for using direct bluetooth, but I found rfcomm more useful when the bluetooth connection breaks. When you turn off & on bluetooth on your phone, smsd (which we will use later on) will never succeed retrying when using direct bluetooth support, while with rfcomm, smsd just fails and exits, so you can detect this and restart smsd in a loop.

You can try communicating with you phone using a terminal program like minicom. Use /dev/rfcomm0 as serial port with these settings: 9600 bps, no parity, no flow control.

Before starting smsd for the first time, we should create the database needed for smsd. Using phpmyadmin, go to privileges, add a new user, and on the same page, choose the option to create a database with the same name as the user. Next, use the import tab to import the file "/usr/share/doc/gnokii-smsd-mysql/sms.tables.mysql.sql".

Also before starting smsd, please note that all SMS messages in the inbox of your phone are automatically transferred to the database and deleted from your phone, so you should take precautions if you want to keep messages on your phone.

Start smsd like this:

smsd --module mysql -u user -p password -d databasename

Incoming SMS messages will be placed in the inbox table. Create a record in the outbox table, with the processed flag to "0", to send an SMS. The processed flag will turn to "1" if the message was sent. You can use the processed flag of the inbox for your own use. It is set to "0" initially.