DHT11/DHT22 with Raspberry Pi

Same problem here. After 6-7 hours of working, DHT11 sensor stops. Then I reboot and again it is working some time and then again goes in offline mode.

I seem to be having a similar issue. I will test and see if I can find the problem. @doerek @ognqn.chikov are you able to run the python script in the terminal to see if you get any errors?

I was run the python script in terminal and more than 10 hours it is working. I will wait 10 more hours to confirm that it is working without issues.

Same issue with termination after some hours…

I believe the problem is related the the growing memory bug here >95% memory usage after one day consistantly Hopefully there is a fix pushed sooner rather than later. If the memory fix does not solve the problem I will investigate further.

Hi @adam
The last 48h my DHT22 stayed Online. (No changes on my side)
Was there a fix?


Sry, false Alarm …my browser was loading the Dashboard from cache…

Hi @doerek,

No changes to the Raspberry Pi agent software just yet, I’ll say that’s probably just better luck on your side. When we do make a change I’ll post it in a pinned thread on this forum.

Nevermind…my browser was loading the Dashboard from cache…

Thanks very much.

I have several issues.

When I registered with cayenne , I only filled name surname, password and email.

No specific question for username. I was not given the client I’d talked about in the code.

How do I resolve these issues. Because I couldn’t just continue since I really don’t know what specific is required in those spaces.

Finally, to get the unique channel talked about in your direction, do you mean I should run this command on my terminal :
cd /sys/bus/w1/devices

And then copy the unique code? If yes, is it all the code or the first 8 digit.

Please, I would appreciate if your directory is a little more detail, many of us here are new bies.


Anticipating your positive reply.


The username, password, and client ID are all generated when you go to the dashboard and click Add new>Device/widget then click the blue Bring Your Own Thing button. This username/password is not your Cayenne username/password.

As far as the channel, you just need to make sure you aren’t using the same channel for anything else. Generally I start at 1 and just work my way up. There is no limit in the docs for the channel value so I’m assuming you can pretty much use any number you can think of.

Thank you for your code but shouldn’t it be:

Your code will probably work fine as it is. But my problem was the following:
If you send a sensor value first as channel 3, then channel 1 and last channel 2. Then the sensor at channel 2 won’t show after a while. This might be a beginners problem (second day here)…

Now it works fine:)

You are correct, typo on my part. I just fixed it.

I didn’t loop the sensor with a waittime for 5 sec. Instead I run the script every minute. So if things go south (program error) I’ll get another shot (crontab value is set to 1 min).
Is it possible to pass some kind of timestamp or avoiding the offline message that I haven’t update my sensor since the dinosaurs was walking on earth?

Except for the message it works fine!

Maybe I will try to do your approach, but instead of running the script everyminute, I will try to send everyminute the real data, and then every other frame to be some fake data stream, zeros or empty stream.

What do you think?

Please give it a shoot.
If I understand you. You should use the 5 second loop, but only the 20th time (5 sec X 20 = 1 min), you’ll get sensor data and send it. All other times (19) you just send the last measured data.

Its interesting to know if it’s the sensor that makes it crash. However my solution works so far, execept for the ugly offline message.

I did NOT try it yet, because I have another problem.

When I open the device, the measurements looks ok:

But after that the measurements are showing:

and when I refresh again, they looks normal. Any Ideas?

Here is the graphic chart. Sometime it is normal, and most of the time the measurements are unreal:

I get the same insane numbers sometimes and also before I started with Cayenne.
I believe the problem is the cheap DHT11 sensor (I bought mine from china).
If I manufactured a humidity sensor I would put a maximum limit for output to 100%…

I’ve now ordered a DHT22 and I hope to get better result

Sorry for my miscalculation before: 5 sec X 20 IS NOT 1 min. I ment 12x5…

I try everything, and it seems to work when I test it. Now I just solder the wires and put it on place. I hate the cheap china shits…

I will try in the weekend with the script, no matter what kind of result I get, I will try and post here if I have interesting solution.

Thank you!

Thanks Adams,

Everything working fine now

1 Like

My problem is that i have done the thing all correctly but when i run my code nothing show nor the widgets nor the readings… code

import paho.mqtt.client as mqtt
import time
import sys
import Adafruit_DHT

time.sleep(30) #Sleep to allow wireless to connect before starting MQTT

mqttc = mqtt.Client(client_id="")
mqttc.username_pw_set("", password="")
mqttc.connect("mqtt.mydevices.com", port=1883, keepalive=60)

topic_dht11_temp = "v1//things//data/1"
topic_dht11_humidity = "v1//things//data/2"

while True:
        humidity11, temp11 = Adafruit_DHT.read_retry(11, 27) #11 is the sensor type, 27 is the GPIO pin number
        if temp11 is not None:
            temp11 = "temp,c=" + str(temp11)
            mqttc.publish(topic_dht11_temp, payload=temp11, retain=True)
        if humidity11 is not None:
            humidity11 = "rel_hum,rel_hum=" + str(humidity11)
            mqttc.publish(topic_dht11_humidity, payload=humidity11, retain=True)
    except (EOFError, SystemExit, KeyboardInterrupt):