Created
May 13, 2022 18:28
-
-
Save tolgahancepel/ab20966f7ec04d24474ca66da52586cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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