diff options
-rw-r--r-- | fruitfly.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/fruitfly.py b/fruitfly.py new file mode 100644 index 0000000..bf4a534 --- /dev/null +++ b/fruitfly.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 + +import sys +import time +import paho.mqtt.client as paho +import Adafruit_DHT + +broker = "192.168.0.59" +client_id = "mercury" +sensor_type = Adafruit_DHT.DHT22 +sensor_pin = 17 + +client = paho.Client(client_id) + +print("connecting to broker " + broker) +client.connect(broker) +client.loop_start() + +while True { + humidity, temperature = Adafruit_DHT.read_retry(sensor_type, sensor_pin) + + client.publish(client_id+"/temperature", temperature) + client.publish(client_id+"/humidity", humidity) + + time.sleep(2) +} |