Hi All,
This post will build on what I have learned from my previous post First Post - How to get a DHT11 running for longer than 6 hours
So basically with help of Ninja Shramik, I got the DHT11 working pretty sweet. So next up is to do some math and send that data to my dashboard as channel 3 (1 and 2 is for temperature and the humidity).
Hacking my previous code, this is what I have so far:
import paho.mqtt.client as mqtt
import time
import sys
import Adafruit_DHT
#Adding additional line for calculation - import math library
import math
time.sleep(30)
username = ββ
password = ββ
clientid = ββ
mqttc = mqtt.Client(client_id=clientid)
mqttc.username_pw_set(username, password=password)
mqttc.connect(βmqtt.mydevices.comβ, port=1883, keepalive=60)
mqttc.loop_start()
topic_dht11_temp = βv1/β + username + β/things/β + clientid + β/data/1β
topic_dht11_humidity = βv1/β + username + β/things/β + clientid + β/data/2β
#Adding additional line for calculating VPD
topic_dht11_vpd = βv1/β + username + β/things/β + clientid + β/data/3β
while True:
try: humidity11, temp11 = Adafruit_DHT.read_retry(11, 17) # 11 is the sensor type, 17 is the GPIO pin number #Adding additional line to zero all my variables: VPD = 0 if temp11 is not None: temp11 = "temp,c=" + str(temp11) mqttc.publish(topic_dht11_temp, payload=temp11, retain=True) #add temp variable for VPD T = temp11 if humidity11 is not None: humidity11 = "rel_hum,p=" + str(humidity11) mqttc.publish(topic_dht11_humidity, payload=humidity11, retain=True) #add humidity variable for VPD H = humidity11 #Adding additional if statements to the python script if VPD is not None: #Using the Magnus Equation to calculate vapour pressure defficiency (VPD) #VPD=((6.1078*EXP(17.08085*T in degC/(234.175+T in degC)))-(6.1078*EXP(17.08085*T in degC/(234.175+T in degC))*(Humidity in %/100)))/10. VPD =((6.1078*math.e**(17.08085*T/(234.175+T)))-(6.1078*math.e**(17.08085*T/(234.175+T))*(H/100)))/10 VPD = "vpd,kpa=" + str(VPD) mqttc.publish(topic_dht11_vpd, payload=VPD, retain=True) time.sleep(5) except (EOFError, SystemExit, KeyboardInterrupt): mqttc.disconnect() sys.exit()
The channel is showing up in the dashboard, but the value stays 0.
Regards
Jacques