#!/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) }