-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProject_1stTest.py
More file actions
79 lines (62 loc) · 1.83 KB
/
Project_1stTest.py
File metadata and controls
79 lines (62 loc) · 1.83 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#Play this first source env/bin/activate
from datetime import datetime
import time
import board
import datetime
import adafruit_dht
import adafruit_bh1750
import pyrebase
import random
config = {
"apiKey": "AIzaSyClrDU_Jg7LpYZl4V0rQji5Q0-aHXEEyqg",
"authDomain":"project-test1-f190d.firebaseapp.com",
"databaseURL": "https://project-test1-f190d-default-rtdb.firebaseio.com",
"storageBucket": "project-test1-f190d.appspot.com"
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
dhtDevice = adafruit_dht.DHT11(board.D18)
i2c = board.I2C()
sensor = adafruit_bh1750.BH1750(i2c)
sensor = adafruit_bh1750.BH1750(i2c)
while True:
time.sleep(5)
t = datetime.datetime.now()
ti = t.min
if t.hour >= 12:
break
while True:
try:
# Print the values to the serial port
temperature_c = dhtDevice.temperature
humidity = dhtDevice.humidity
intensity = sensor.lux
c_time = datetime.datetime.now()
date = c_time.timestamp()
print(c_time)
print(
"Temp: {:.1f} C Humidity: {}% ".format(
temperature_c, humidity
)
)
print("%.2f Lux" % intensity)
data = {
"Temperature" : temperature_c,
"Humidity" : humidity,
"Light Intensity" : intensity,
"Date" : date
}
db.child("More Data Points").push(data)
print("Sent to firebase")
except RuntimeError as error:
# Errors happen fairly often, DHT's are hard to read, just keep going
print(error.args[0])
time.sleep(2.0)
continue
except Exception as error:
dhtDevice.exit()
raise error
if t.hour >= 17:
break
time.sleep(599)
print("Done")