Thursday, March 21, 2013

Controlling Raspberry Pi via text message

This script enables you to control your computer via text message. Think of it almost as a version of SSH over text message.

It is designed to intelligently and quickly check unread Google voice messages. If certain parameters are passed, it runs the command you send and returns the result.
This is the third script in my AUI (Alternative User Interface) Series.
This requires curl and libboost1.50-regex. The setup script can install curl and boost regex. 

NOTE: This will work with any linux OS but I am using it on the Raspberry Pi so if you are using something else, you will have to compile it yourself (make sure to change the Makefile flags).

The stable version is on github here:

And the working copy source can be found here:
http://stevenhickson-code.googlecode.com/svn/trunk/AUI/TextCommand/


Google Voice unfortunately doesn't have an API available so I started writing my own.
I found this page and this page which were good references. Unfortunately, neither of these actually worked, so I wrote my own based off them. The script will install this and you are free to use it however you want as long as you cite me and follow GPLv3.

It works by using cron to run a script once every minute. The script checks your unread inbox messages and uses curl to make sure certain safety parameters are met. It is very important to check the unread inbox as it only pulls a 1-3 KB file rather than a 150+ KB file. This really adds up once a minute over time. If certain parameters are met, ie it has a valid phone number and command, then it runs the command you give it. The results of the command are then texted back to you. 
This will not work with interactive scripts like more or man



Installation Instructions

(this requires git)

sudo apt-get install git-core
git clone git://github.com/StevenHickson/PiAUISuite.git
cd PiAUISuite/Install/
./InstallAUISuite.sh

Update Instructions 

cd PiAUISuite
git pull
cd Install
sudo ./UpdateAUISuite.sh


There are other scripts in here that you can ignore. It will ask you the username details in the script.
This will be your Google voice username, password, key, and valid number.

Your Google voice username will be your e-mail. For example:
John.Doe@gmail.com
Your password is your Google voice password:
ThisIsntMyPassword
The key is the valid command-word that proceeds commands to the machine. For example, mine is Cmd. So I text:
Cmd ls
to have the pi text the results of the current directory back.
Your valid number is the phone number you want your google voice to receive commands from (Not your Google voice number!). You must put the country code but not the + sign. Ex:
15553332222

After that everything should work.
Note, I worked out a few major bugs with the install script and it is reposted now. So make sure to get the newest version.

Consider donating to further my tinkering


Places you can find me





4 comments:

  1. Have you considered Twilio? It would give you a completely documented way to interact with SMS, but it would cost a (trivial) amount.

    ReplyDelete
    Replies
    1. Twilio is less secure (their API uses http instead of https) and I like to be able to specify the code myself. It does have the advantage of working internationally though.

      Delete
  2. HI, I found your blog post while searching for Raspberry Pi and Google Voice. Since you know the code where could I modify it to read a text from any number? Looks like somewhere in gtextcommand.cpp? This is the problem I have now: http://arduino.cc/forum/index.php/topic,160036.0.html so I am thinking of porting over to the RPi.
    Thanks

    ReplyDelete
    Replies
    1. On line 49 of gtextcommand.cpp where the program calls CheckSMS, change the number string to an empty string ex:
      string tmp = "";
      r=gv.CheckSMS(results,tmp,keyword,true);

      You still need to send a valid number for SendSMS though.

      Delete