Yes, you are very close. Try the code below for your python code, it should spit out some values if it can actually read the sensor. keep in mind you should comment out the lines for the sensor you are not using or youll get a lot of could not read sensor prints. I have a feeling that there is an issue with the sensor or the wiring. Note that in the original post I had in the code that it is using GPIO pins 17 and 18. That is actually physical pin 11 and 12 (I have updated the post to reflect).
import paho.mqtt.client as mqtt
time.sleep(30) #Sleep to allow wireless to connect before starting MQTT
mqttc = mqtt.Client(client_id="")
mqttc.connect("mqtt.mydevices.com", port=1883, keepalive=60)
topic_dht11_temp = "v1/username/things/clientid/data/1"
topic_dht11_humidity = "v1/username/things/clientid/data/2"
topic_dht22_temp = "v1/username/things/clientid/data/3"
topic_dht22_humidity = "v1/username/things/clientid/data/4"
humidity11, temp11 = Adafruit_DHT.read_retry(11, 17) #11 is the sensor type, 17 is the GPIO pin number (physical pin 11)
humidity22, temp22 = Adafruit_DHT.read_retry(22, 18) #22 is the sensor type, 18 is the GPIO pin number (physical pin 12)
if temp11 is not None:
temp11 = "temp,c=" + str(temp11)
mqttc.publish(topic_dht11_temp, payload=temp11, retain=True)
print "DHT11 Temp not read"
if humidity11 is not None:
humidity11 = "rel_hum,p=" + str(humidity11)
mqttc.publish(topic_dht11_humidity, payload=humidity11, retain=True)
print "DHT11 Humidity not read"
if temp22 is not None:
temp22 = "temp,c=" + str(temp22)
mqttc.publish(topic_dht22_temp, payload=temp22, retain=True)
print "DHT22 Temp not read"
if humidity22 is not None:
humidity22 = "rel_hum,p=" + str(humidity22)
mqttc.publish(topic_dht22_humidity, payload=humidity22, retain=True)
print "DHT22 Humidity not read"
except (EOFError, SystemExit, KeyboardInterrupt):