-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtemp.py
88 lines (69 loc) · 2.55 KB
/
temp.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import time
import sys
import datetime
#import Adafruit_BMP.BMP085 as BMP085
#import Adafruit_DHT
import MySQLdb
#sensor = BMP085.BMP085()
#sensor2 = Adafruit_DHT.DHT22
#pin = 24
db = MySQLdb.connect(
host = '192.168.1.151',
user = 'pi',
passwd = '10416232',
db = 'temp',
port = 3306)
curs=db.cursor()
try:
while True:
#---------------------------------------------------------------------------------------
#Waterproof Temperature Sensor
tfile = open("/sys/bus/w1/devices/28-00000608f21c/w1_slave")
text = tfile.read()
tfile.close()
secondLine = text.split("\n")[1]
temperaturedata = secondLine.split(" ")[9]
temperature = float(temperaturedata[2:])
temp = (temperature/1000.0) * (9/5) + 32
print (temp, 'A')
add_temp = ("INSERT INTO temprecord VALUES(%s, %s, %s, %s)")
curs.execute(add_temp, (temp, 'A', time.strftime("%Y/%m/%d"), time.strftime("%H:%M:%S")))
db.commit()
#-----------------------------------------------------------------------------------------
#Barometric Pressure Sensor
## temp2 = sensor.read_temperature() * (9/5) + 32
## print (temp2, 'B')
## curs.execute(add_temp, (temp2, 'B', time.strftime("%Y/%m/%d"), time.strftime("%H:%M:%S")))
## db.commit()
#-----------------------------------------------------------------------------------------
#DHT11 Temperature/Humidity Sensor
## humidity, temp3 = Adafruit_DHT.read_retry(sensor2, pin)
## temperature3 = temp3 / 10
## print(temperature3, humidity, 'C')
##
## curs.execute(add_temp, (temperature3, 'C', time.strftime("%Y/%m/%d"), time.strftime("%H:%M:%S")))
## db.commit()
## #--------------------------------------------------------------------------------------
##
## tfile2 = open("/sys/bus/w1/devices/28-0000060882e5/w1_slave")
## text2 = tfile2.read()
## tfile2.close()
##
## secondLine2 = text2.split("\n")[1]
##
## temperaturedata2 = secondLine2.split(" ")[9]
##
## temperature2 = float(temperaturedata2[2:])
## temp2 = (temperature2/1000.0) * (9/5) + 32
##
## print (temp2, 2)
##
## add_temp2 = ("INSERT INTO temprecord VALUES(%s, %s, %s, %s)")
##
## curs.execute(add_temp2, (temp2, 'B', time.strftime("%Y/%m/%d"), time.strftime("%H:%M:%S")))
## db.commit()
time.sleep(900)#900
except KeyboardInterrupt:
print "\nA keyboard interrupt has been noticed"
except:
print "An error or exception has occurred."