smsd-command howto

This howto is a guide to let you control your PC from your mobile phone. Specifically:
  1. When the phone receives a SMS, the PC runs a shell command;
    example: if the SMS we sent containts the string reboot apache the PC will run the command /etc/init.d/apache2 restart.
  2. The PC runs periodic commands and when the output of a command contains a give string it sends a SMS to a telephone number;
    example: the PC runs every 180 seconds ping -c 3 www.pioz.it and when the output of command contains the string unknown host it sends a SMS to the number +393331234567 that contains pioz.it is offline!.
All the actions can be configured in a XML file.
This system runs under GNU/Linux, in particular the tests described in this howto were carried out on a Debian testing.
Let's see what we need:
  1. A Nokia mobile phone
  2. A means to connect the phone to the PC
  3. A software to handle this connection
  4. A deamon to handle the SMS
In this howto we employ:
  1. Nokia 7110
  2. Nokia serial cable
  3. Gnokii 0.6.18
  4. Smsd 1.4 with command module

Connecting the phone to PC

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!

Configuring smsd

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.
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!

Valid XHTML 1.1! Last modified 09 September 2009 | Maintained by Pioz