Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 and DHT22 low memory #1687

Closed
linyx-omg opened this issue Aug 14, 2019 · 8 comments
Closed

ESP32 and DHT22 low memory #1687

linyx-omg opened this issue Aug 14, 2019 · 8 comments
Labels
ESP32 This is only a problem on ESP32-based devices

Comments

@linyx-omg
Copy link

Hi. I'm use esp32-wroom-32 and DHT22 sensor with DHT22.js script.

I call the read function every 5 seconds and every time I get less and less memory, the log below as it was at the beginning of work was 1917, and after a while it was already 1887 and so on until there is an error.

What my problem?

My code:

setInterval(function() {
   this.dht.read((response) => {
     console.log(response)
     console.log(process.memory())
   });
 }, 5000);

My logs:

____                 _
|  __|___ ___ ___ _ _|_|___ ___
|  __|_ -| . |  _| | | |   | . |
|____|___|  _|_| |___|_|_|_|___|
        |_| espruino.com
2v04 (c) 2019 G.Williams
Espruino is Open Source. Our work is supported
only by sales of official boards and donations:
http://espruino.com/Donate
{
 "raw": "100000010001011010000000011100001000100001",
 "rh": 111.4, "temp": 45 }
{ "free": 1917, "usage": 383, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.989 }
{
 "raw": "010000001000101100000000001110000100001111",
 "rh": 55.6, "temp": 22.5 }
{ "free": 1929, "usage": 371, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.954 }
{
 "raw": "010000001000110010000000001110000100010101",
 "rh": 56.2, "temp": 22.5 }
{ "free": 1926, "usage": 374, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.96 }
{
 "raw": "010000001000110100000000001110000100010111",
 "rh": 56.4, "temp": 22.5 }
{ "free": 1922, "usage": 378, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.956 }
{
 "raw": "010000001000110001000000001110001000010101",
 "rh": 56.1, "temp": 22.6 }
{ "free": 1919, "usage": 381, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.965 }
{
 "raw": "010000001000101000000000001110001000001100",
 "rh": 55.2, "temp": 22.6 }
{ "free": 1915, "usage": 385, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.958 }
{
 "raw": "010000001000101000000000001110001000001100",
 "rh": 55.2, "temp": 22.6 }
{ "free": 1912, "usage": 388, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.96 }
{
 "raw": "010000001000110001000000001110001000010101",
 "rh": 56.1, "temp": 22.6 }
{ "free": 1908, "usage": 392, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.964 }
{
 "raw": "010000001001010011000000001110001000110111",
 "rh": 59.5, "temp": 22.6 }
{ "free": 1905, "usage": 395, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.961 }
{
 "raw": "010000001001010111000000001110001000111011",
 "rh": 59.9, "temp": 22.6 }
{ "free": 1901, "usage": 399, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.967 }
{
 "raw": "010000001001010011000000001110001000110111",
 "rh": 59.5, "temp": 22.6 }
{ "free": 1898, "usage": 402, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.963 }
{
 "raw": "010000001001001001000000001110001000101101",
 "rh": 58.5, "temp": 22.6 }
{ "free": 1894, "usage": 406, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.969 }
{
 "raw": "010000001000111011000000001110001000011111",
 "rh": 57.1, "temp": 22.6 }
{ "free": 1887, "usage": 413, "total": 2300, "history": 179,
 "gc": 0, "gctime": 1.966 }
@MaBecker
Copy link
Contributor

use a simple code like this to reproduce the memory leak:

var dht = require("DHT22").connect(<used pin>);

setInterval(function() {
    dht.read(function (response) {
        console.log(response)
        console.log(process.memory());
});}, 5000);

@MaBecker MaBecker added the ESP32 This is only a problem on ESP32-based devices label Aug 16, 2019
@linyx-omg
Copy link
Author

Create thread on the forum:
http://forum.espruino.com/conversations/337313/

@MaBecker, me use this simple code and memory low after some time

@MaBecker
Copy link
Contributor

ok, just check the module with a ESP8266 without memory leaks.

The module is using some calls like

digitalWrite(ht.pin, 0);

pinMode(ht.pin,"output");

pinMode(ht.pin,'input_pullup');

pinMode(ht.pin);

which use ESP32 specific code.

So please test the interval with digitalWrite and pinMode and share the results.

@MaBecker
Copy link
Contributor

run test by test and share your results

// 1. test
setInterval(function() {
        digitalWrite(<your pin>, 0);
        console.log(process.memory());
});}, 1000);
// 2. test
setInterval(function() {
        pinMode(<your pin>, "output");
        console.log(process.memory());
});}, 1000);
// 3. test
setInterval(function() {
        pinMode(<your pin>, "input_pullup");
        console.log(process.memory());
});}, 1000);
// 4. test
setInterval(function() {
        pinMode(<your pin>);
        console.log(process.memory());
});}, 1000);

@linyx-omg
Copy link
Author

Test 1:

{ "free": 4038, "usage": 62, "total": 4100, "history": 23,
  "gc": 0, "gctime": 3.158 }

Test 2:

{ "free": 4038, "usage": 62, "total": 4100, "history": 22,
  "gc": 0, "gctime": 3.158 }

Test 3:

{ "free": 4038, "usage": 62, "total": 4100, "history": 23,
  "gc": 0, "gctime": 3.151 }

Test 4:

{ "free": 4039, "usage": 61, "total": 4100, "history": 21,
  "gc": 0, "gctime": 3.144 }

repeated without changes

@linyx-omg
Copy link
Author

If me use read() function once: rh = -1, err = true, checksumError = false every time

if call two read()

this.dht.read(function (a) {});
this.dht.read(function (a) {});

next call read() get normal rh

memory leak in d virable

this.watch = setWatch(function(t) {
    d+=0|(t.time-t.lastTime>0.00005);
  }, ht.pin, {edge:'falling',repeat:true} );

For example:

d = 10000001001111001000000001101000001001011111000000101000010100000000110100000101011111100000010100100110000000011010000011001011110000001010011001000000001101000001101011110000001010011001000000001100111101101010
010000001010011001000000001100111101101010 ...

if add conditional to setWatch function:

  this.watch = setWatch(function(t) {
    if(d.length > 41){
      d = d.slice(1)
      d+=0|(t.time-t.lastTime>0.00005);
    } else {
      d+=0|(t.time-t.lastTime>0.00005);
    }
  }, ht.pin, {edge:'falling',repeat:true} );

me get normal rh without memory leak.

I need a temp fix, is this true or is there a mistake?

 ____                 _
|  __|___ ___ ___ _ _|_|___ ___
|  __|_ -| . |  _| | | |   | . |
|____|___|  _|_| |___|_|_|_|___|
         |_| espruino.com
 2v04 (c) 2019 G.Williams
Espruino is Open Source. Our work is supported
only by sales of official boards and donations:
http://espruino.com/Donate
>
{
  "raw": "010000001001110110000000001101011001001110",
  "rh": 63, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.253 }
_____
{
  "raw": "010000001001110101000000001101011101001110",
  "rh": 62.9, "temp": 21.5 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.243 }
_____
{
  "raw": "010000001001101110000000001101011001000110",
  "rh": 62.2, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.249 }
_____
{
  "raw": "010000001001101011000000001101011001000011",
  "rh": 61.9, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110110000000001101011001001110",
  "rh": 63, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____
{
  "raw": "010000001001110100000000001101011001001100",
  "rh": 62.8, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.245 }
_____
{
  "raw": "010000001001110110000000001101011101001111",
  "rh": 63, "temp": 21.5 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110001000000001101011001001001",
  "rh": 62.5, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.248 }
_____
{
  "raw": "010000001001110010000000001101011001001010",
  "rh": 62.6, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____
{
  "raw": "010000001001110011000000001101011001001011",
  "rh": 62.7, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110010000000001101011001001010",
  "rh": 62.6, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110011000000001101011001001011",
  "rh": 62.7, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001101001000000001101011101000010",
  "rh": 61.7, "temp": 21.5 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001101101000000001101011101000110",
  "rh": 62.1, "temp": 21.5 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110010000000001101011001001010",
  "rh": 62.6, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.554 }
_____
{
  "raw": "010000001001110001000000001101011001001001",
  "rh": 62.5, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110010000000001101011001001010",
  "rh": 62.6, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110001000000001101011001001001",
  "rh": 62.5, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001101011000000001101011001000011",
  "rh": 61.9, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.241 }
_____
{
  "raw": "010000001001110001000000001101011001001001",
  "rh": 62.5, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.248 }
_____
{
  "raw": "010000001001110011000000001101011001001011",
  "rh": 62.7, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____
{
  "raw": "010000001001110100000000001101011001001100",
  "rh": 62.8, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.248 }
_____
{
  "raw": "010000001001110011000000001101011001001011",
  "rh": 62.7, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110100000000001101011001001100",
  "rh": 62.8, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110010000000001101010101001001",
  "rh": 62.6, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110010000000001101011001001010",
  "rh": 62.6, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____
{
  "raw": "010000001001110010000000001101010101001001",
  "rh": 62.6, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110100000000001101010101001011",
  "rh": 62.8, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001101011000000001101011001000011",
  "rh": 61.9, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.241 }
_____
{
  "raw": "010000001001101111000000001101010101000110",
  "rh": 62.3, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110100000000001101011001001100",
  "rh": 62.8, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.559 }
_____
{
  "raw": "110000001001110100000000001101011001001100",
  "rh": 62.8, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.245 }
_____
{
  "raw": "010000001001101001000000001101011001000001",
  "rh": 61.7, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110100000000001101010101001011",
  "rh": 62.8, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.241 }
_____
{
  "raw": "010000001001101100000000001101010101000011",
  "rh": 62, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "110000001001110101000000001101010101001100",
  "rh": 62.9, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001101010000000001101010101000001",
  "rh": 61.8, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____
{
  "raw": "010000001001110110000000001101010101001101",
  "rh": 63, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110101000000001101010101001100",
  "rh": 62.9, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.241 }
_____
{
  "raw": "010000001001110010000000001101010101001001",
  "rh": 62.6, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001101001000000001101010101000000",
  "rh": 61.7, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____
{
  "raw": "010000001001101100000000001101010101000011",
  "rh": 62, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001010001011000000001101010101100010",
  "rh": 65.1, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____
{
  "raw": "010000001001111000000000001101010101001111",
  "rh": 63.2, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.248 }
_____
{
  "raw": "010000001001111010000000001101010101010001",
  "rh": 63.4, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____
{
  "raw": "010000001001110011000000001101010101001010",
  "rh": 62.7, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001111000000000001101011001010000",
  "rh": 63.2, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.246 }
_____
{
  "raw": "010000001001111000000000001101010101001111",
  "rh": 63.2, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001111000000000001101010101001111",
  "rh": 63.2, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____
{
  "raw": "010000001001110111000000001101011001001111",
  "rh": 63.1, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.244 }
_____
{
  "raw": "010000001001110000000000001101011001001000",
  "rh": 62.4, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____
{
  "raw": "010000001001110110000000001101011001001110",
  "rh": 63, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.245 }
_____
{
  "raw": "010000001001110100000000001101011001001100",
  "rh": 62.8, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____
{
  "raw": "010000001001110100000000001101011001001100",
  "rh": 62.8, "temp": 21.4 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.25 }
_____
{
  "raw": "010000001001110011000000001101010101001010",
  "rh": 62.7, "temp": 21.3 }
{ "free": 3729, "usage": 371, "total": 4100, "history": 162,
  "gc": 0, "gctime": 3.24 }
_____

@maze1980
Copy link

Not related to ESP32, it's the script has a bug.
http://forum.espruino.com/conversations/337313/

@gfwilliams
Copy link
Member

Thanks!

mkroehnert added a commit to mkroehnert/EspruinoDocs that referenced this issue Mar 23, 2022
Update DHT22.js module as per discussion in http://forum.espruino.com/comments/14870784/ 

see also espruino/Espruino#1687
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ESP32 This is only a problem on ESP32-based devices
Projects
None yet
Development

No branches or pull requests

4 participants