First of all, install Gnokii:
# apt-get install gnokii
Now we must configure Gnokii editing the configuration file
/etc/gnokiirc as below:
[global]
port = /dev/ttyS0
model = 7110
initlength = default
connection = dau9p
use_locking = yes
serial_baudrate = 19200
smsc_timeout = 30
[gnokiid]
bindir = /usr/sbin/
[logging]
debug = off
rlpdebug = off
xdebug = off
To read a complete explanation of these options see the default Gnokii configuration file.
Now we can connect the phone (in this howto Nokia 7110) to the PC, and we can test the connection trying this command:
# gnokii --identify
We should see:
GNOKII Versione 0.6.18
IMEI : 498495122677123
Marca : Nokia
Modello : 7110
Nome prodotto: NSE-5
Revisione : 04.94
If we get this output we can go on, the phone is now connected to Debian!
Now we must install and configuring smsd deamon. Install it:
# apt-get install gnokii-smsd
smsd is a deamon developed by Gnokii team and able to read and write SMS on a mobile phone, but for our purposes we need an extra module not included in smsd package (by now). This module is called
command (written by me). You can download it from
here.
When the download is completed install the new module running:
# tar -zxvf smsd-command.tar.gz
# cd smsd-command/
# make
# su
# make install
The first command unpack the archive.
The second one enters the folder containing the unpacked files.
The third compile the module.
The fourth one gives root power, required to install files.
The fifth one install all files in your system.
To uninstall the module use
make uninstall as root.
Let's see now how this deamon with module
command run, glancing its configuration file
/etc/smsd/command.xml. You can see below the example configuration file that you have just downloaded:
<?xml version="1.0"?>
<!DOCTYPE smsd SYSTEM "command.dtd">
<smsd module="command">
<allowedNumbers>
<number>3331234567</number>
<number>3337654321</number>
</allowedNumbers>
<receive>
<command text="hello world" run="echo Hello!"/>
<command text="foo" run="~/script/foo.sh"/>
</receive>
<send to="3331234567">
<sm run="ping -c 3 www.pioz.it" output="unknown host" text="pioz.it is down!" to="3337654321" sec="180"/>
<sm run="cat /proc/mdstat" output="U_" text="Raid arrays are broken!"/>
</send>
</smsd>
This XML file has tree main tags:
allowedNumbers,
receive,
send.
allowedNumbers: this tag allow you to define those telephone numbers allowed to make the PC run some command. The international prefix (Italy +39) is not mandatory, if you do not specify it all international prefixes are allowed.
receive: this tag set those commands run when incoming a SMS. To understand we look the sample configuration file: if from an allowed number (those contained in allowedNumebers tag) incoming a SMS that contains exatly "hello world" (attribute text) then the PC run the command echo Hello! (attribute run).
send: this tag allow you to define periodic command to run and when the output of this command contains a specific string it sends a SM to a telephone number. To understand we look the sample configuration file: the PC run every 180 seconds (attribute sec) the command ping -c www.pioz.it (attribute run) and if its output contains unknown host (attribute output) the connected phone sends a SMS to 3337654321 (attribute to). I remeber you that the attributes to and sec are not mandatory: if the first is omitted the SMS will be sent to the default number, that specify from to attribute of the send tag; if the second is omitted the periodic command will be run every 3 seconds. More over the sec attribute tell that the command will be run with at least x seconds of interval.
The XML configuration file will be validated using its
DTD, that must be in the same directory of configuration file. If the DTD not exist, this check will be omitted.
Another important thing to know: if the PC sends a SMS defined in
send tag, it will be disabled and the periodic command will be not run. To re-enable this perioc command you must restart the smsd deamon.
Ok, now you should edit the configuration file according to your purposes and then start
as root smsd deamon with the command
# /etc/init.d/smsd start
To stop smsd use
# /etc/init.d/smsd stop
and to restart it use
# /etc/init.d/smsd restart
To show the std output of smsd, you can run the smsd deamon also with the command
# smsd -m command [-c path/to/configfile.xml]
A log file will be generated in
/var/log/smsd.
That's all folks. If you have some questions, send me a
mail!