Last active
November 16, 2018 12:20
-
-
Save hussanhijazi/e8a20d0807678183dd5ffc2e788f7661 to your computer and use it in GitHub Desktop.
Publish temperature/humidity
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 paho.mqtt.client as mqtt | |
import time | |
import Adafruit_DHT as dht | |
from variables import * | |
def mqtt_client_connect(): | |
print("connected to: ", broker_url) | |
client.connect(broker_url) | |
client.loop_start() | |
client = mqtt.Client("client_name") | |
mqtt_client_connect() | |
while True: | |
humidity, temperature = dht.read_retry(dht.DHT11, 4) | |
print('Sending... Temperature: {} Humidity: {}'.format(temperature, humidity)) | |
client.publish(temperature_topic, temperature) | |
client.publish(humidity_topic, humidity) | |
time.sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment