Sending and receiving an SMS with the Raspberry Pi

Processing SMS messages

SMSD moves received SMS messages to the inbox directory. Technically you could run regular searches for files, for example with a Cronjob, in the corresponding directory and then process these accordingly. The better way to proceed however, is to use the keyword RunOnReceive during configuration as a means of depositing a script for processing incoming messages (Listing 6, Line 26). The daemon calls the script synchronously and waits a maximum of two minutes for it to complete. Then it continues with its work.

Listing 7 provides a simple example of a script of this type. The environmental variables for the script include pieces of meta information as well as contents of SMS messages. The details are well documented. In practice, the script should at least check the sender's number, even if these numbers can be falsified.

Listing 7

Output RunOnReceive

#!/bin/bash
# Check sender
# if [ "$SMS_1_NUMBER" != "Number_OK" ] ; then
#   exit
# fi
# Output all physical reports to Syslog
for i in $(seq $SMS_MESSAGES) ; do
  logger -t smsd "SMS Teil: $i"
  eval logger -t smsd \"Sender: \${SMS_${i}_NUMBER}\"
  eval logger -t smsd \"Text: \${SMS_${i}_TEXT}\"
done

As an aside, it is possible just as with RunOnReceive, to deposit additional scripts for other events. This is done using RunOnSent or RunOnError.

Operating in parallel

Although operating Gammu and the server in parallel does not work due to the fact that both try to access the same device, there is no problem at all with transmitting and receiving SMS via UMTS while using a data connection. This works when Wvdial or PPPD use the first modem device of the stick. Typically this would be /dev/ttyUSB0. You can read details about configuring a stick for fast data connections in the article about 3G Hotspots published in a previous issue [1].

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content