forked from tparenti/aquarium_monitor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp_logging.py
More file actions
58 lines (45 loc) · 1.38 KB
/
temp_logging.py
File metadata and controls
58 lines (45 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
import glob
import time
import sys
import datetime
import urllib2
import RPi_I2C_driver
from time import *
baseURL = "https://api.thingspeak.com/update?api_key=BCQOBOXNDHS4L81T"
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
base_dir = 'sys/bus/w1/devices/'
#beer temperature device location
beer_file = '/sys/bus/w1/devices/28-0414694e4eff/w1_slave'
#Determine beer temperature
def read_rawtemp_beer():
f = open(beer_file,'r')
lines = f.readlines()
f.close
return lines
def read_temp_beer():
lines = read_rawtemp_beer()
while lines[0].strip()[-3:] !='YES':
time.sleep(0.2)
lines = read_rawtemp_beer()
equals_pos = lines[1].find('t=')
if equals_pos !=-1:
temp_string = lines[1][equals_pos+2:]
temp_beer = float(temp_string)/1000.0
return temp_beer
while True: #Loop
#Send Beer Temperature to Thingspeak
beer_tempin = read_temp_beer()
beer_tempin = (beer_tempin * 1.8) + 32
#Pull results together
values = [datetime.datetime.now(), beer_tempin]
#Open Thingspeak channel and assign fields to temperatures
j = urllib2.urlopen(baseURL + "&field1=%s" % (beer_tempin))
mylcd = RPi_I2C_driver.lcd()
mylcd.lcd_clear()
# test 2
mylcd.lcd_display_string("RPi I2C test", 1)
mylcd.lcd_display_string(" Custom chars", 2)
#Time to next loop
time.sleep(600)