Skip to content

Instantly share code, notes, and snippets.

@tolgahancepel
Created May 13, 2022 18:28
Show Gist options
  • Select an option

  • Save tolgahancepel/ab20966f7ec04d24474ca66da52586cf to your computer and use it in GitHub Desktop.

Select an option

Save tolgahancepel/ab20966f7ec04d24474ca66da52586cf to your computer and use it in GitHub Desktop.
import time
import paho.mqtt.client as mqtt
import Adafruit_DHT
# MQTT Client
mqttc = mqtt.Client()
mqttc.connect("mqtt.eclipseprojects.io", 1883, 60)
# DHT11 sensor data
dht11_sensor = Adafruit_DHT
gpio = 23
# Main function
if __name__ == "__main__":
print("Publishing...")
while True:
humidity, temperature = Adafruit_DHT.read_retry(dht11_sensor, gpio)
mqttc.publish("myroom/temperature", temperature)
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment