Last active
February 25, 2019 15:19
-
-
Save li2hub/71f6be020907d10a72bdd8649928c0c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Adafruit_DHT | |
import paho.mqtt.client as paho | |
broker="192.168.xx.xxx" | |
sensor = Adafruit_DHT.DHT11 | |
pin = 4 | |
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) | |
def hum_temp(): | |
if humidity is not None and temperature is not None: | |
return 'Temp={0:0.1f}* Humidity={1:0.1f}%'.format(temperature, humidity) | |
else: | |
return 'Failed to get reading. Try again!' | |
client= paho.Client("control-001") | |
client.hum_temp=hum_temp | |
client.connect(broker) | |
client.publish("sensor_data",hum_temp()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment