If you just want to receive messages all you need to do is install Gammu, type sudo gammu getallsms and Gammu will list all messages on the sim card. If you just want just a few messages use sudo gammu getsms 0 1 where zero is the start position and one is how many messages you want to see.

It works, but it’s not really useful.

The best way to do things automatically is by using the Gammu daemon. The daemon can, when a message is received, run a program or shell script. First install the daemon, sudo apt-get install gammu-smsd and update the config file which is by default located in /etc/.Type sudo nano /etc/gammu-smsdrc and add RunOnReceive = PATH_TO_SCRIPT under [smds]. Now just type sudo gammu-smsd to start the daemon. Remember, the shell script must have execute permissions.Add this with chmod u+rwx PATH_TO_FILE. Also remember that this can, depending on what the script does, mess with your Pi. So use with caution.

Basic example

This script will return the string “Hello world!” to the number from which you sent the message to the Raspberry.

Ping pong

You might want the script to do different things depending on the message. In this case, if we text “Ping” the script will return “Pong!”.

Shutdown

We can do pretty much what ever a shell script is allowed to do, like shutting down the Pi.

Redirect SMS

I recently got a new phone number and to make sure people don’t send messages to my old number I wrote the script below to redirect their messages to my new number. If the message is too long it will cut it short but it will still send the important part, their phone number and a part of what they wanted to tell me.

Wrap up

As you see it’s not very hard to receive messages and do things with them. This was a very basic "start here, learn more later"-tutorial but I hope it will help you learn as much as I did writing it.