-
Notifications
You must be signed in to change notification settings - Fork 0
/
humidityModule.py
executable file
·37 lines (28 loc) · 957 Bytes
/
humidityModule.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
#!/usr/bin/env python3
import os, random
import Adafruit_DHT
import robomodules as rm
from messages import *
ADDRESS = os.environ.get("BIND_ADDRESS","localhost")
PORT = os.environ.get("BIND_PORT", 11297)
FREQUENCY = 10
SENSOR_PIN1 = 21
class HumidityModule(rm.ProtoModule):
def __init__(self, addr, port):
self.subscriptions = []
super().__init__(addr, port, message_buffers, MsgType, FREQUENCY)
self.sensor = Adafruit_DHT.DHT22
def msg_received(self, msg, msg_type):
return
def tick(self):
humidity, temperature = Adafruit_DHT.read_retry(self.sensor, SENSOR_PIN1)
if humidity is not None and temperature is not None:
msg = HumidityMsg()
msg.humidity = humidity
msg = msg.SerializeToString()
self.write(msg, MsgType.HUMIDITY_MSG)
def main():
module = HumidityModule(ADDRESS, PORT)
module.run()
if __name__ == "__main__":
main()