logo elektroda
logo elektroda
X
logo elektroda

ESP8266 (ESP-07), DHT22, web server - After some time, the page does not display.

sq9etc 2895 52
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 18567706
    sq9etc
    Level 12  
    I copied the program alive from this page:
    ESP8266 DHT11/DHT22 Temperature and Humidity Web Server with Arduino IDE .

    Unfortunately, after a long time (1 - 2 days) the web page stops displaying in the browser. You can see that the device is alive, as the blue LED on the board flashes when messages are sent to the serial port.
    Has anyone encountered a similar case and can make any suggestions?
    The circuit is connected as shown in this diagram:
    Link .
    Do you have a problem with Arduino? Ask question. Visit our forum Arduino.
  • ADVERTISEMENT
  • #2 18567857
    khoam
    Level 42  
    With which version of the ESP8266 board manager did you compile the program? The latest version is 2.6.3.
  • #3 18567925
    kaczakat
    Level 34  
    Check the performance of the site by sending some counter seconds. This will eliminate the hanging caused by DHT. Sometimes someone complains that every now and then the sensor can hang up and only unplugging the power supply helps. I haven't noticed this, but I haven't tested the operational stability for a long time. Such sensor can be powered from uC pin and if it stops responding do ON/OFF. But this needs to be handled somehow in code.
    Helpful post? Buy me a coffee.
  • #4 18568097
    khoam
    Level 42  
    sq9etc wrote:
    Unfortunately, after a longer time (1 - 2 days) the web page stops displaying in the browser.
    .
    In this program you provided a link to, the loop() does not check the current status of the WiFi client at all (the ESP is running in STA mode) - this could also be the cause of this behaviour. You can verify this by trying to unpin the ESP when the page stops displaying.
  • #5 18569011
    sq9etc
    Level 12  
    khoam wrote:
    With what version of the ESP8266 board manager did you compile this program? The latest version is 2.6.3.
    .
    Where can this be checked? Arduino IDE 1.8.12 As for the version of the ESP8266 support library that displays in the board manager, yes, it is version 2.6.3.
  • #6 18569026
    khoam
    Level 42  
    sq9etc wrote:
    When it comes to the version of the ESP8266 support library that displays in the board manager, yes, it is version 2.6.3.
    .
    Yes, that's what I meant. Try testing pinging to ESP when you can't access the site.
  • #7 18569030
    sq9etc
    Level 12  
    kaczakat wrote:
    Sometimes someone complains that every now and then the sensor can hang up and only unplugging the power supply helps.
    .
    I also have this problem. When I combined the linked program with this Network Time Protocol I had this effect. I added myself a date and time display on the page in addition to temperature and humidity. After a few tens of minutes, up to a few hours, the readings from the DHT would stop appearing and the time would change. I added something such that when 3 times the sensor would not return the correct values I would do an ESP.reset. Unfortunately this did not help. I had to switch the power to the circuit off and on. After that it worked for a while and then it was the same thing again. I had the module reset over and over again after every three failed attempts to read from the DHT.

    Added after 4 [minutes]: .

    khoam wrote:
    sq9etc wrote:
    When it comes to the version of the ESP8266 support library that displays in the board manager, yes, it is version 2.6.3.
    .
    Yes, that's what I meant. Try testing pinging to ESP when you don't have access to the site.

    I hadn't thought of that ping, that's a thought. If it happens I'll check it out. For now it has been working for almost two days.
  • ADVERTISEMENT
  • #9 18569192
    sq9etc
    Level 12  
    Possibly, maybe I'll check at some point. But this behaviour of the sensor suggests that it's not a software problem, well unless it's the sensor's firmware. After a reset I think everything should re-initialise and work normally.
  • #10 18586389
    sq9etc
    Level 12  
    sq9etc wrote:
    kaczakat wrote:
    Sometimes someone complains that every now and then the sensor can hang up and only unplugging the power helps.
    .
    I also have this problem. When I combined the linked program with this Network Time Protocol I had this effect. I added myself a date and time display on the page in addition to temperature and humidity. After a few tens of minutes, up to a few hours, the readings from the DHT would stop appearing and the time would change. I added something such that when 3 times the sensor would not return the correct values I would do an ESP.reset. Unfortunately this did not help. I had to switch the power to the circuit off and on. After that it worked for a while and then it was the same thing again. The module reset over and over again after every three failed attempts to read from the DHT.
    .
    This happened to me again today.
    This is what a snippet of a dump to a file from RealTerma looks like:
    ...
    Local time: 2020-04-03 07:20:49
    Temperature: 22.00ÂşC
    Humidity: 48.70%
    020-04-03 07:20:49
    
    
    Local time: 2020-04-03 07:20:59
    Temperature: 22.00ÂşC
    Humidity: 48.70%
    
    Soft WDT reset
    
    >>>stack>>>
    
    ctx: sys
    sp: 3fffed40 end: 3fffffb0 offset: 01b0
    3fffeef0:  40242a1c efd8a1fc 60000600 4021223d  
    3fffef00:  00000000 3ffed558 00000000 00000000  
    3fffef10:  40231530 3ffed558 3ffee510 60000600  
    ...
    3fffff90:  3fffdad0 00000000 3ffeed50 40100229  
    3fffffa0:  3fffdad0 00000000 3ffeed50 402088e5  
    <<<stack<<<
    
     ets Jan  8 2013,rst cause:2, boot mode:(3,7)
    
    load 0x4010f000, len 1392, room 16 
    tail 0
    chksum 0xd0
    csum 0xd0
    v3d128e5c
    ~ld
    Starting UDP
    Local port:	123
    
    Time server IP:	194.146.251.100
    
    Sending NTP request ...
    
    Sending NTP request ...
    NTP response:	1585898481
    
    Local time: 2020-04-03 07:21:21
    Failed to read from DHT sensor!
    Failed to read from DHT sensor!
    020-04-03 07:21:21
    
    NTP response:	1585898486
    
    Local time: 2020-04-03 07:21:26
    Failed to read from DHT sensor!
    Failed to read from DHT sensor!
    020-04-03 07:21:26
    
    NTP response:	1585898496
    
    Local time: 2020-04-03 07:21:36
    Failed to read from DHT sensor!
    Failed to read from DHT sensor!
    ˙
     ets Jan  8 2013,rst cause:2, boot mode:(3,7)
    
    load 0x4010f000, len 1392, room 16 
    tail 0
    chksum 0xd0
    csum 0xd0
    v3d128e5c
    ~ld
    Starting UDP
    Local port:	123
    
    Time server IP:	194.146.251.100
    
    Sending NTP request ...
    
    Sending NTP request ...
    NTP response:	1585898511
    
    Local time: 2020-04-03 07:21:51
    Failed to read from DHT sensor!
    Failed to read from DHT sensor!
    020-04-03 07:21:51
    
    NTP response:	1585898516
    
    Local time: 2020-04-03 07:21:56
    Failed to read from DHT sensor!
    Failed to read from DHT sensor!
    020-04-03 07:21:56
    
    NTP response:	1585898526
    
    Local time: 2020-04-03 07:22:06
    Failed to read from DHT sensor!
    Failed to read from DHT sensor!
    ˙
     ets Jan  8 2013,rst cause:2, boot mode:(3,7)
    ...
    
    .
    It looks like Watch Dog worked, but for what reason I don't know. Maybe there was a delayed response from the NTP server. However, this does not excuse the fact that after a reset the sensor can no longer get along.
  • #11 18586604
    khoam
    Level 42  
    sq9etc wrote:
    It seems that Watch Dog worked, but for what reason I don't know.

    This usually happens when a program simultaneously uses asynchronous web server together with another library running in synchronous mode after TCP or UDP.

    sq9etc wrote:
    When I connected the linked program to this Network Time Protocol I had this effect.
    .
    It would be good if you could show how you 'linked' this, particularly in the loop().

    sq9etc wrote:
    However, this does not excuse the fact that you can no longer get along with the sensor after a reset.

    Somewhat excuses it, given that after a Soft WDT Reset there is "rubbish" left in RAM.
  • #12 18587599
    oskar777

    Level 26  
    I had a similar problem with the DHT as for the ESP-7 I selected the wrong amount of memory. Sometimes it is also a power supply problem.
  • #13 18587948
    sq9etc
    Level 12  
    khoam wrote:
    .
    It would be good if you could show how you 'linked' this, particularly in the loop().

    Code:
    main.cpp
    Code: C / C++
    Log in, to see the code


    WiFi.h
    Code: C / C++
    Log in, to see the code


    WiFi.cpp
    Code: C / C++
    Log in, to see the code
    .
    khoam wrote:
    <br>
    sq9etc wrote:
    This, however, does not excuse the fact that after a reset you can no longer get along with the sensor.
    .
    A bit of an excuse, given that after a Soft WDT Reset there is "rubbish" left in RAM.

    I also do ESP.reset() there.
  • ADVERTISEMENT
  • #14 18589435
    khoam
    Level 42  
    I suggest the following modification in loop():
    Code: C / C++
    Log in, to see the code
    .
    sq9etc wrote:
    I also do ESP.reset() there.
    .
    Better to use ESP.restart() - "cleaner" form of restart, closes network connections correctly, leaves no "junk" in registers.

    What do the RAM occupancy statistics look like after compilation?
  • #15 18590612
    sq9etc
    Level 12  
    khoam wrote:
    What are the RAM occupancy statistics after compilation?
    .
    36 %. What can be done so that this compilation message window does not close by itself in Atom? It's difficult to see this memory occupation, because it closes immediately.

    Added after 9 [hours] 5 [minutes]: .

    yield() didn't help. I will still see with replacing ESP.reset() with ESP.restart().
  • ADVERTISEMENT
  • #16 18592493
    khoam
    Level 42  
    sq9etc wrote:
    yield() did not help.
    .
    Did the program crash and perform a Soft WTD Reset? Or did the program not resume correctly after forcing ESP.reset()? These are two different things.
  • #17 18592514
    sq9etc
    Level 12  
    khoam wrote:
    Has the program crashed and performed a Soft WTD Reset? Or did the program fail to resume correctly after forcing ESP.reset()? These are two different things.
    .
    I don't know that, because I didn't have the bug plugged in. The effect was that after a while it stopped reading DHT22 as before. I can only suspect that the cause was the same, i.e. Soft WDT Reset.
  • #18 18592528
    khoam
    Level 42  
    sq9etc wrote:
    This I don't know, as I didn't have a bug plugged in.
    .
    However, I suggest you do this. Otherwise solving this problem will be shooting blindly. Maybe it will work ;) .
  • #19 18595248
    sq9etc
    Level 12  
    After the changes:
    -adding yield() where you suggested,
    -replacing ESP.reset() to ESP.restart(),

    is the same, ie:
    -the soft WDT reset occurs,
    -after the above it is not possible to get along with the DHT22, ESP.restart() does not help for lack of communication with the sensor.
  • #20 18595375
    khoam
    Level 42  
    sq9etc wrote:
    it is the same, ie:
    -Soft WDT reset occurs,
    .
    Also after the last temperature and humidity values have been correctly displayed (vide post #10)?
    After what time did this Soft WDT Reset occur?
  • #21 18595416
    sq9etc
    Level 12  
    khoam wrote:
    sq9etc wrote:
    it is the same, ie:
    -Soft WDT reset occurs,
    .
    Also after the last temperature and humidity values have been correctly displayed (vide post #10)?
    .
    Exactly like this.
    khoam wrote:
    After what time did this Soft WDT Reset occur?
    .
    First time after 1h 18m of operation, second time after almost 4 hours of correct operation.
  • #22 18595472
    khoam
    Level 42  
    OK, that leaves one point to be clarified. I refer to the first code from post #13.
    What specifically did you want to achieve by using the variables dHTReadingErrorsCount and prevDHTReadingErrorsCount ? On what state of these variables did you want to make the circuit reset dependent and in what situation?
    What is in the code, I can see ;) .
  • #23 18597673
    sq9etc
    Level 12  
    khoam wrote:
    OK, that leaves one point to be clarified. I refer to the first code from post #13.
    What specifically did you want to achieve by using the variables dHTReadingErrorsCount and prevDHTReadingErrorsCount ? On what state of these variables did you want to make the circuit reset dependent and in what situation?
    What I see in the code is ;)
    .

    After three failed attempts to read the sensor, a reset is to be performed. With that said, if the temperature and humidity fail to be read in one cycle then I count this as one error. Therefore I entered two variables and incremented dHTReadingErrorsCount when reading the humidity, only when I failed to do so when reading the temperature. Hence the condition:
    Code: C / C++
    Log in, to see the code
    .
  • #24 18597882
    krzbor
    Level 27  
    I had a program on the ESP that sometimes rebooted (several times a day). The ESP was working with the SIM800. I decided that interference from GSM was the culprit. However, I had to tweak the program and the reboots were almost all the time. Eventually I determined that the problem was due to returning 'String' as the result of a function - it should work, but it didn't. I solved the problem by stopping the function returning the "String" value - the "String" is now passed to the function by reference and everything started working. There is a "processor" function in your code that returns a String. Perhaps the same problem as mine is also occurring?
  • #25 18598097
    khoam
    Level 42  
    sq9etc wrote:
    After three unsuccessful attempts to read the sensor, a reset is to be performed.

    Regardless of how long a period of time they occurred?

    krzbor wrote:
    I solved the problem by stopping the function returning the "String" value - the "String" is now passed to the function by reference and everything started working.

    Actually returning the entire String object through a function is not good practice. The problem is that the function send_P() requires a callback of type AwsTemplateProcessor :
    Code: C / C++
    Log in, to see the code
    Type AwsTemplateProcessor is defined as:
    Code: C / C++
    Log in, to see the code
    so you cannot "substitute" a callback function of a type other than String(const String&) .

    Multiple memory allocations for the String object returned by the function processor () can be avoided by defining a global variable of type String with a reservation of the appropriate buffer length using String.reserve() . This variable would be modified inside the processor() function and returned by that function - so no new String variable would be created each time for the send_P() function call.

    You could also use send() instead of send_P() and pass the String variable modified by processor() directly.
    Code: C / C++
    Log in, to see the code
    .
  • #26 18598668
    krzbor
    Level 27  
    Indeed, I hadn't noticed that the function was a callback. My experience with the String object was that if a function returns this object and it is assigned to a global variable, it is OK (this is how I have it in other projects). The problem arose when the result of a function returning a String was stored in another function in a local variable - in other words, stack handling came into play. Since we have a callback here, this situation also occurs.
  • #27 18598763
    khoam
    Level 42  
    @krzbor For me the best way to use the String class is to use the std::string class from the C++ standard library :) Fortunately in the case of the ESP8266 this library is available. The String class in the HAL for ESP8266 has been rewritten from the AVR version of the HAL and this is, in my opinion, a gigantic misunderstanding.
  • #28 18613509
    sq9etc
    Level 12  
    khoam wrote:
    sq9etc wrote:
    After three unsuccessful attempts to read the sensor, a reset is to be performed.

    Regardless of how long a period of time they occurred?
    .
    An apt point, although in my case when the sensor stopped reading, it was on amen.

    Added after 4 [minutes]: .
    I replaced Send_P with Send, but nothing changed, i.e. after tens of minutes the sensor stopped responding.
    I commented out the part of the code responsible for retrieving and converting the time to text. Instead, I display myself the number of readings since the module started. At the moment there are 5080 readings, which means everything has been working for more than 14 hours. I continue to have three variables displayed as I had. So that doesn't look like some kind of string problem to me.
  • #29 18613691
    khoam
    Level 42  
    sq9etc wrote:
    although in my case when the sensor stopped reading, it was already on amen.
    .
    This can happen, but I think such a meter should be reset after a certain period of time when there are no errors - erroneous readings can also be due to temporary disturbances beyond your control. On the other hand, when it actually stops reading the sensor, the next 3 erroneous readings will come out anyway.

    It would also be good to check if there are any memory leaks during operation. You can use the function getFreeHeap (), which returns (as a uint32_t) the amount of available memory on the heap.
    Using the function:
    Code: C / C++
    Log in, to see the code
    In loop() you can periodically send information to Serial.

    https://arduino-esp8266.readthedocs.io/en/latest/libraries.html#esp-specific-apis
  • #30 18627478
    sq9etc
    Level 12  
    I debugged a piece of code converting time from a uint32_t type variable to a text string, and in this form the program ran for over 3 days.
    In the original version, quickly put together from the two, which I presented on the listing, there was one uncool thing. Namely, the time server was queried as often as the sensor, i.e. every 10 seconds.
    I have now changed this so that the synchronisation occurs once a day after midnight according to winter time. So far it has worked since evening. I hope that this way it will already work stably for a long time. I wonder what the time divergence will be at the end of the day. I increment the time myself every sensor reading, i.e. every 10 s.

Topic summary

The discussion revolves around issues faced with an ESP8266 (ESP-07) web server setup using a DHT22 sensor, where the web page ceases to display after a period of 1-2 days. Users suggest various troubleshooting steps, including checking the ESP8266 board manager version (2.6.3), monitoring the DHT sensor's performance, and ensuring the WiFi client status is checked in the loop function. Recommendations include using the DHTesp library for better error diagnostics, implementing a reset mechanism after multiple failed sensor readings, and optimizing memory usage to prevent soft WDT resets. The conversation also touches on potential memory leaks and the importance of proper string handling in the code to avoid crashes.
Summary generated by the language model.
ADVERTISEMENT