DHT22 sending weird data after some time.

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: DHT22 sending weird data after some time.

Post by adafruit_support_carter »

In your callback function, you don't have any checks to make sure length never exceeds your msg buffer. What happens if length is greater than 16?

Also, it'd be a good idea to add some length specifiers to your sprintfs, something like:

Code: Select all

sprintf(hum,"analog_actuator=%6.1g",localHum);
just to make sure the auto formatting doesn't exceed your array bounds for the temp and hum buffers.

User avatar
z4nD4R
 
Posts: 20
Joined: Tue Jan 09, 2018 5:49 am

Re: DHT22 sending weird data after some time.

Post by z4nD4R »

I totaly agree with you that some length specificators woudl be usesull and I'm going to add them. Anyway the callback function is not called in my test demo, therefore I believe it is not a source of the problem.

Y

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: DHT22 sending weird data after some time.

Post by adafruit_support_carter »

Anyway the callback function is not called in my test demo
You don't call it explicitly, but you do set it up to be (potentially) called by the underlying library:

Code: Select all

client.setCallback(callback);

User avatar
z4nD4R
 
Posts: 20
Joined: Tue Jan 09, 2018 5:49 am

Re: DHT22 sending weird data after some time.

Post by z4nD4R »

That's true, but I can comment that line and problem will persists. All about the buffer controling is 100% true but I'm not sure if that's the source of the problem.

Y

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: DHT22 sending weird data after some time.

Post by adafruit_support_carter »

I'm still suspicious it's something with the string formatting, possibly with something also going on with the MQTT library. But the sensors are probably still reading OK. Try this, add both values to the output, change this:

Code: Select all

    sprintf(hum,"analog_actuator=%g",localHum);
    Serial.println(hum);
to this:

Code: Select all

    sprintf(hum,"analog_actuator=%g",localHum);
    Serial.print(localHum); Serial.print(", "); Serial.println(hum);
and see if both reported values get weird at the same time.

User avatar
z4nD4R
 
Posts: 20
Joined: Tue Jan 09, 2018 5:49 am

Re: DHT22 sending weird data after some time.

Post by z4nD4R »

Hello,

I've performed the proposed changes. It looks like both values started to be weird in the same time.

Code: Select all

Publishing to J
analog_actuator=51.3, 51.30
analog_actuator=25.7, 25.70
Publishing to J
analog_actuator=35.5, 35.50
analog_actuator=-25.2, -25.20
Publishing to J
analog_actuator=48.3, 48.30
analog_actuator=25.2, 25.20
Publishing to J
analog_actuator=48.3, 48.30
analog_actuator=25.2, 25.20
Publishing to J
analog_actuator=48.3, 48.30
analog_actuator=25.2, 25.20
Publishing to J
analog_actuator=48.3, 48.30
analog_actuator=25.2, 25.20
Publishing to J
analog_actuator=48.3, 48.30
analog_actuator=25.2, 25.20
Publishing to J
analog_actuator=36.1, 36.10
analog_actuator=25.2, 25.20
Publishing to J
analog_actuator=36.1, 36.10
analog_actuator=25.2, 25.20
Publishing to J
analog_actuator=36.1, 36.10
analog_actuator=12.4, 12.40
Publishing to J
analog_actuator=36.1, 36.10
analog_actuator=12.4, 12.40
Publishing to J
analog_actuator=36.1, 36.10
analog_actuator=12.4, 12.40

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: DHT22 sending weird data after some time.

Post by adafruit_support_carter »

Please post a photo of your setup showing all connections and hardware being used. Also, another BANNED link to the code you're currently running. I'm going to see if I can replicate this and what to make sure I match your HW setup and run the same SW.

User avatar
z4nD4R
 
Posts: 20
Joined: Tue Jan 09, 2018 5:49 am

Re: DHT22 sending weird data after some time.

Post by z4nD4R »

Hello,

no problem here you are.

code: https://BANNED.com/pBbZ61tc

Y
Attachments
Current setup.
Current setup.
IMG_20180204_210954.jpg (974.41 KiB) Viewed 554 times

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: DHT22 sending weird data after some time.

Post by adafruit_support_carter »

Just a heads up - I had to order some parts for this, so will be a little delayed waiting for mail. Will get back to you when I've got some results.

User avatar
z4nD4R
 
Posts: 20
Joined: Tue Jan 09, 2018 5:49 am

Re: DHT22 sending weird data after some time.

Post by z4nD4R »

Hello,

no problem take your time. Just let me know whenever you'll have any update.

Y

User avatar
z4nD4R
 
Posts: 20
Joined: Tue Jan 09, 2018 5:49 am

Re: DHT22 sending weird data after some time.

Post by z4nD4R »

Hello,

I'd like to ask you if there is some update on this issue? Meantime I've collected some statistic for you :)
Attachments
stats_iot.png
stats_iot.png (117.66 KiB) Viewed 478 times

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: DHT22 sending weird data after some time.

Post by adafruit_support_carter »

Sorry for the delay. I accidentally fried my DHT22 when I was doing the initial testing and had to get another one shipped. :(

I've got it now and have it running without any IO stuff to make sure I've got the same baseline as you. So far no glitches. Will try adding in IO next and see if I can repeat what you're seeing.

Also, a few more questions about your setup:
* How are you powering the DHT22? (5V or 3.3V?)
* Are you using the pull up resistor that came with it?

User avatar
z4nD4R
 
Posts: 20
Joined: Tue Jan 09, 2018 5:49 am

Re: DHT22 sending weird data after some time.

Post by z4nD4R »

Hello,

no problem. But tell, how did you manage to fried the DHT22? :) Could be interesting story anyway.

To answer your questions:

* How are you powering the DHT22? (5V or 3.3V?) - as you can see the on previous picture the DHT22 is powering from VCC port of the ESP board. ESP board is powering from microUSB.

* Are you using the pull up resistor that came with it? - afaik I'm not using any internal pull up resistor - chcek out my code. The only resistor attached is the on schema.

Y

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: DHT22 sending weird data after some time.

Post by adafruit_support_carter »

no problem. But tell, how did you manage to fried the DHT22? :) Could be interesting story anyway.
I just hooked it up backwards. I'm trying it out on different boards and when I was swapping back I flipped it so GND went to VCC and vice versa. It didn't like that. :(

I'm using an Arduino Uno as a sanity check and I'm noting much more stable readings with it than the ESP32. I'm just running the DHTtester sketch from the library examples in both cases. It's pretty solid on the Uno, but with the ESP32 I can get a lot of "Failed to reads" by simply breathing on it to cause a humidity/temperature spike. Previously you said you were getting solid performance (without MQTT in the mix). How about if you try what I'm doing? Just run the DHTtester sketch and then try breathing on the sensor. Does it still report OK?

User avatar
z4nD4R
 
Posts: 20
Joined: Tue Jan 09, 2018 5:49 am

Re: DHT22 sending weird data after some time.

Post by z4nD4R »

Hello,

well I believe also DHT22 didn't like that :)

Ok, I've performed your simple test with basic library. I didn't get any error when I tried to breath on the sensor. But on other hand the sensor didn't change the values. Sometimes it does but no rapidly. Anyway no issues with stability.

Y

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”