Skip to content

Instantly share code, notes, and snippets.

@hussanhijazi
Last active November 16, 2018 12:20
Show Gist options
  • Save hussanhijazi/e8a20d0807678183dd5ffc2e788f7661 to your computer and use it in GitHub Desktop.
Save hussanhijazi/e8a20d0807678183dd5ffc2e788f7661 to your computer and use it in GitHub Desktop.
Publish temperature/humidity
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