Quote:
Originally Posted by opiesche
As requested
Adventures in home improvement: Temperature Logging
I'll update this with some more pictures and information, and finally code, this week. Just to show how simple it really was, here's the script that reads the sensors and outputs the values to a .csv file. I'll eventually make this prettier and more flexible as well (right now it's hardcoded for my particular sensors and setup).
Code:
#!/usr/bin/python
import os
import datetime
def extract_temp(filename):
temp = 0.0
lines = open(filename, 'r').readlines()
line = lines[1]
tempstr = line[29:34]
temp = float(tempstr)
temp = temp/1000.0
return temp
# read the sensors and stick their output to a temporary file
os.system("cat /sys/bus/w1/devices/w1_bus_master1/28-000003742037/w1_slave > /tmp/curtemp1.txt")
os.system("cat /sys/bus/w1/devices/w1_bus_master1/28-0000040df025/w1_slave > /tmp/curtemp2.txt")
# grab the temperature only from the file (there's other data in the sensor output)
temp1 = extract_temp("/tmp/curtemp1.txt")
temp2 = extract_temp("/tmp/curtemp2.txt")
# now log to file with timestamp
date_str = str(datetime.datetime.today())[0:10]
time_str = str(datetime.datetime.now())[11:19]
strn = time_str+", "+str(temp1)+", "+str(temp2)
filename = "/home/raspbian/"+date_str+".csv"
with open(filename, "a") as outfile:
outfile.write( strn+"\r\n" )
print strn
I'll keep tinkering and adding to this. The source code and build instructions will likely end up on github when I'm done.
The cool thing about doing this with the Raspberry Pi is, that it's network accessible (I grab the plot images from a webserver running on it) and that I can program it remotely via SSH. It can sit in its current location running (at about 1W, by the way!), and I can tweak it, tune it, and grab the data and plots from it without ever touching the physical machine
|
This useful post will get lost very soon. You should start separate thread with name like "automated control system, code..." or whatever you think it should be . It is a really a big deal for most people to get sophisticated control system especially one that you can control from your computer....
I found many not expensive mini boards on eBay but they all require some sort of programming.