jump to navigation

Build your own Free SMS to Twitter gateway with open source tools and cheap hardware March 27, 2011

Posted by GuySoft in Crictor, diy, Electronics, Hamakor, IGF, ITU, linux, open source, programming, python.
Tags: , , , , , , , ,
SMS Twitter Gateway

SMS Twitter Gateway logo

Hey all,

I am releasing here set of instructions and source that will enable anyone to set up a phone number, that if you SMS it, will post your massage on to your own twitter account. This service is called “Twiter SMS Gate”. The service handles multiple users, and should be easily modified to support other services like statusnet (and with a bit more code maybe even other social networks). The SMS hardware required is any cheap cellphone that can work with gammu-smsd (mine is a fake Nokia from India). Twiter SMS Gate also lets users easily register to it with their own cellphone.

I hope that people that like this idea would start hosting more SMS gates, as we create a wide network of those around the world. SMS Twitter Gate-IL , The Israeli Gate, has been running for a few weeks now and even got covered in the local media here.

The source is written in Python, which includes the phone hardware hooks, webserver, twitter client and database access.

Here is the cellphone used to run my server, just to show you how simple it is to do this, no super-expensive hardware required! (server is also my personal Linux-running PC:

Fake Nokia Cellphone acting as a dedicated SMS server

Fake Nokia Cellphone acting as a dedicated SMS server

If you have any kind of difficulty setting this up, please give me feedback, so we can make it as easy as possible.


1. Tomer Cohen - March 27, 2011

Does it supports other social networks, such as identi.ca?

GuySoft - March 27, 2011

Its the same API, so it should work, but I did not test it. You are welcome to build and try, I’ll help you with all I can.

2. Rodrigues - March 31, 2011


I’m trying to set up your software tu run a twitter sms gateway but i’m facing some problems ๐Ÿ˜ฆ When the gammu daemon receives an sms it executes the smsd.sh script but it exits with error 127.

Here are the logs i got from gammu:

Thu 2011/03/31 01:46:44 gammu-smsd[27083]: Received message from +351917689028
Thu 2011/03/31 01:46:44 gammu-smsd[27083]: Received IN20110331_015429_00_+35191xxxxxxx_00.txt
Thu 2011/03/31 01:46:44 gammu-smsd[27104]: Starting run on receive: “/home/jowoo
d/guysoftSMSTwitterGate/gate_scripts/smsd.sh” IN20110331_015429_00_+35191xxxxxxx
Thu 2011/03/31 01:46:44 gammu-smsd[27083]: Process failed with exit status 127

(i edited the phone number)

i executed the script smsd.sh directly and this is the output i get:

Incoming SMS:
Traceback (most recent call last):
File “/home/jowood/guysoftSMSTwitterGate/gate_scripts/twitter-smsd.py”, line 240, in
a = SMSdeamon()
File “/home/jowood/guysoftSMSTwitterGate/gate_scripts/twitter-smsd.py”, line 102, in __init__
File “/usr/lib/python2.6/UserDict.py”, line 22, in __getitem__
raise KeyError(key)
eval: 1: : Permission denied

Can you help?

GuySoft - March 31, 2011

SMS_MESSAGES is an environment variable, when you run smsd it sets the message as an environment variable, so when your just execute the file it looks for the non-existent variable in the environment.
Try this as a test code:
export SMS_1_NUMBER=+9725012345678
export SMS_1_TEXT=hello
python twitter-smsd.py

Regarding the gammu-smsd log, it seems like twitter-smsd.py is retuning 127 for a different reason, with the environment variables set using the script above we might determine why

3. Rodrigues - March 31, 2011

Thanks for the answer.
I’ve run the commands you said and it ran well:

Incoming SMS:
checking if 9725012345678 in auth table
select * from auth where phone=?
Not Found 9725012345678 in auth table, testing in phonelist
im new
Closing db

Should i be running gammu-smsd as root or as normal user?

GuySoft - March 31, 2011

Thats a good response, it can’t find your number in the auth table (the one that has users authorized).
So it checks to see if there if the user sent a pin number to be authorized (like you do in the Twitter Gate-IL page )
You need to set up the webserver side, so you can get a token from your twitter app.

Gammu-smsd should run as root, its a service. But you can test as user that python script

4. Rodrigues - April 1, 2011

Thanks for the help.
The problem was the i’ve registred the number in the format 91XXXXXXX and when the sms arrives the number is presented with +35191XXXXXXX and due to that the number was never found in the DB.

I advanced a little more and now i’m having some trouble when trying to authenticate with the PIN in twitter (the log says Error! Failed to get access token.), but i will look at it tommorow.

GuySoft - April 1, 2011

Ok, please post if you get stuck here! And I’d value any kind of input you can give to make the setup easier for the next person. Also, there is a SMS Gate List you are welcome to fill out.

5. Rodrigues - April 29, 2011

Hi again ๐Ÿ™‚

I finally got time to get back to this!

All the problems i got with the python scripts and with the shell script are solved. If export tthe values to the env vars (SMS_MESSAGES, SMS_1_NUMBER and SMS_1_MESSAGE) and call the smsd.sh script i cant tweet.

The only problem i have now is that the gammu-smsd is not exporting the values to ENV…

Here’s what’s happening:

I start the gammu-smsd with this command:
$ sudo gammu-smsd

After that i send an sms to my number, the gammu-smsd correctly runs twitter-smsd.py but it stops after writing “Incoming SMS:” in the log.

I’ve tried to write the $SMS_MESSAGES to a file in the smsd.sh script but it writes nothing…

My gammu-smsdrc config file is similar to the example you provided, i only changed the port and the path to the python script.

Do you have any idea what might be wrong?

I am taking note of the problems i’ve encountered and how i solved them. If you want i can send you this after i have the gateway completely functional,

6. Rodrigues - April 29, 2011

Hi i finnaly got everything up and running ๐Ÿ™‚

The problem with them empty ENV vars was the gammu-smsd version. The version i had installed (1.26.x) didn’t have the functionality of writting the ENV vars. I installed 1.29.x and now everything works just great ๐Ÿ™‚

Do you want me to send you a resume of the problems i’ve found and the solutions?


GuySoft - April 30, 2011

Always, its good to hear other user experience. And it would help readers build their own gate if they have the same problems you do.
Also, is your gate usable by other people? Or just for you?

7. Rodrigues - April 30, 2011

For now it’s just for testing so it’s not available for public. Maybe in the future.

The biggest problems i had were with the gammu-smsd version and i had to modify the smsd.sh script. I had to enclose the PROGRAM path in “” like this:
PROGRAM=”python /path/to/twitter-smsd.py”.

I had some other problems but were all related to some missing python libraries.

Once again thanks for the help

8. Paolo - November 16, 2011

How can I set this up? I really can’t understand your instructions in GitHub. I’m still a senior high school student so I really am not that good in Python.

GuySoft - November 16, 2011

Hello Paolo,
First, the GitHub instructions donโ€™t mention python, you don’t need to know it in order to install the server.
What you do need, is a computer running Linux or Mac that can run gammu-smsd. If you are in high school, you might be able to find teachers or friends around you that might lend a hand. Many have read my instructions, but a few I know actually implemented them. So there might be a few parts in the documentation that are not so straightforward.
If you have a specific problem please give me the instruction number bullet and what you are finding hard to do, I will try and go in to more detail.

Paolo - November 24, 2011

Okay. Thanks! But can you create a code that can allow users to receive tweets from users that they’re following? Will that be possible?

9. Amadou - September 21, 2012

I’m trying to install the gateway but i would like to know in my twitter app what kind of “REQUEST SETTINGS” should i choose?

GuySoft - September 22, 2012

Hey, sorry I just saw this comment now.
Glad you got it working ๐Ÿ™‚

10. Ladonna - July 23, 2013

Howdy admin, I just wanted to give you a brief heads up that your Website
link: https://guysoft.wordpress.com/2011/03/27/smsgate/ is being flagged as a possibly harmful web page
in my internet browser opera. I’d highly recommend having someone look into it. You could possibly lose a lot of visitors due to this problem. Very best of Luck.

GuySoft - July 26, 2013

Can you link where? It works fine here…

11. christian - October 14, 2015

I have the same problem as Rodrigues, ie the empty environment vars (SMS_1_NUMBER, SMS_1_TEXT) by i have a more recent gammu smsd version than Rodrigues ie 1.29.x
By this doesn’t resolve the problem.
What’s wrong with the environment variables not set ?

12. christian - October 14, 2015

oh, execuse me but my version is higher, ie 1.31.x

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: