Temperature Twitter Bot

Twitter is an interesting thing. Share whatever you want, whenever you want. Twitter is cool and all but I don’t find much use for it until now.

I came across this project http://www.scottcutler.net/catpoop/catpoop.html as you can see pretty weird but the idea itself is cool - automated twitter posts.

I took my Raspberry Pi and installed necessary files.

For my project I wanted to tweet my temperature, humidity, and air pressure. The main magic is done by the RbPi. The Arduino is connected via USB cable, meaning we have serial connection. The python script on the RbPi reads the data from serial and then tweets it. And it is as simple as that.

I needed to install couple of extra packages for python: pyserial and Twython.

Couple of lines of python and done.

To get the necessary authorizations: LINK

My code
import sys
import serial
import os
import time
from twython import Twython
CONSUMER_KEY = 'SECRET'
CONSUMER_SECRET = 'SECRET'
ACCESS_KEY = 'SECRET'
ACCESS_SECRET = 'SECRET'

api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
ser = serial.Serial('/dev/ttyUSB0',9600)
while True:
cmd = '/opt/vc/bin/vcgencmd measure_temp'
line = os.popen(cmd).readline().strip()
temp = line.split('=')[1].split("'")[0]
posttemp = ('CPU temperatuur on '+temp+' C. ')

vaartused = (ser.readline().strip()+' C. '+ser.readline().strip()+'%. '+ser.readline().strip()+' mBar. ')

api.update_status(status=posttemp+vaartused)


time.sleep(1800)

 

Comments

Popular posts from this blog

My take on the PA0RDT Mini Whip antenna.

My take on a nixie clock

RFID experiments