#!/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) print("connected") client.loop_start() while True: humidity, temperature = Adafruit_DHT.read_retry(sensor_type, sensor_pin) print(client_id+"/temperature: "+ str(temperature)) print(client_id+"/humidity: "+ str(humidity)) client.publish(client_id+"/temperature", str(temperature)) client.publish(client_id+"/humidity", str(humidity)) time.sleep(2)