in Aquarium, Raspberry pi

Raspberry Pi tweet temperature


I wrote a small python script to tweet my aquariums temperature so that i can monitor it as I raise the temperature slowly to 86°F to fight an ich outbreak 🙁 .

Updated the code, had to add the temperature tuple in a new variable using srt(temp). Code is now working and running on my Raspberry pi.

Tutorials used to write this Raspberry twitter tutorialDS1820B tutorial

[cc lang=’python’ ]

#!/usr/bin/env python
import os
import sys
import tweepy
import glob
import time
CONSUMER_KEY = ‘secret’
ACCESS_KEY = ‘secret’
ACCESS_SECRET = ‘secret’
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)

cmd = ‘/opt/vc/bin/vcgencmd measure_temp’
line = os.popen(cmd).readline().strip()
temp = line.split(‘=’)[1].split(“‘”)[0]
os.system(‘modprobe w1-gpio’)
os.system(‘modprobe w1-therm’)

base_dir = ‘/sys/bus/w1/devices/’
device_folder = glob.glob(base_dir + ’28*’)[0]
device_file = device_folder + ‘/w1_slave’

def read_temp_raw():
f = open(device_file, ‘r’)
lines = f.readlines()
return lines

def read_temp():
lines = read_temp_raw()
while lines[0].strip()[-3:] != ‘YES’:
lines = read_temp_raw()
equals_pos = lines[1].find(‘t=’)
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.0 / 5.0 + 32.0
return temp_c, temp_f

while True:
localtime = time.asctime( time.localtime(time.time()) )
tempvar= str(read_temp())
tweetmytemp = tempvar+” “+localtime+” @sebastienb”


#tweets Time, temp and @myuser every hour