-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_test.py
34 lines (26 loc) · 907 Bytes
/
new_test.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
import time
from datetime import datetime
from grovepi import grovepi
while True:
# define pin number for sensors here
dht = 4
light_sensor = 1
sound_sensor = 0
moist_sensor = 2
temp = grovepi.dht(dht,0)[0]
humidity = grovepi.dht(dht,0)[1]
lightlvl = grovepi.analogRead(light_sensor)
soundlvl = grovepi.analogRead(sound_sensor)
moistlvl = grovepi.analogRead(moist_sensor)
# timestamp is UTC, and UTC time shall be used across
myData={"d": {'temp':temp, 'humidity':humidity, 'lightlvl':lightlvl, 'soundlvl':soundlvl, 'moistlvl':moistlvl}, "ts": datetime.utcnow().isoformat()+"Z"}
print(myData)
time.sleep(1)
# def myCommandCallback(cmd):
# print("Command received: %s" % cmd.data)
# if cmd.command == "TurnOn":
# grovepi.digitalWrite(2,1)
# print("LED is now turned ON")
# elif cmd.command == "TurnOff":
# grovepi.digitalWrite(2,0)
# print("LED is now turned ON")