-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensor.py
More file actions
38 lines (34 loc) · 1.17 KB
/
sensor.py
File metadata and controls
38 lines (34 loc) · 1.17 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
#!/usr/bin/python3
from time import sleep
import RPi.GPIO as GPIO
from pi_sht1x import SHT1x
from hackeriet.mqtt import MQTT
def main():
mqtt = MQTT()
mode = GPIO.BCM
with SHT1x(12, 8, vdd="5V") as sensor_one:
temp = sensor_one.read_temperature()
humidity = sensor_one.read_humidity(temp)
sensor_one.calculate_dew_point(temp, humidity)
print(sensor_one)
mqtt("hackeriet/plant1/temperature", temp)
mqtt("hackeriet/plant1/humidity", humidity)
f = open("/home/pi/plant_mon/plant1", "w")
f.write("%s," % str(temp))
f.write("%s\n" % str(humidity))
f.close()
sleep(2)
with SHT1x(18, 16, vdd="5V") as sensor_two:
temp = sensor_two.read_temperature()
humidity = sensor_two.read_humidity(temp)
sensor_two.calculate_dew_point(temp, humidity)
mqtt("hackeriet/plant0/temperature", temp)
mqtt("hackeriet/plant0/humidity", humidity)
f = open("/home/pi/plant_mon/plant0", "w")
f.write("%s," % str(temp))
f.write("%s\n" % str(humidity))
f.close()
print(sensor_two)
sleep(2)
if __name__ == "__main__":
main()