Hi,
I am using Nodemcu broad (ESP12E) to develop my DHT 11 sensor app. Here is my code :
load("api_dht.js");
print('Hello');
let dht = DHT.create(5, DHT.DHT11);
print('Temperature:', dht.getTemp());
I connect my the data port of DHT11 sensor to D1 (GPIO05). The VCC is 3.3v.
I will see the log from "mos tool ui console".
[Aug 26 15:53:40.432] mg_rpc_channel_mqtt 0x3fff106c esp8266_2BCC89/rpc/#
[Aug 26 15:53:40.438] mg_rpc_channel_uart 0x3fff1334 UART0
[Aug 26 15:53:40.443] mgos_init Init done, RAM: 52328 total, 44116 free, 43584 min free
_[Aug 26 15:53:40.524] Hello
[Aug 26 15:53:40.536] Temperature: 9223372036854775807 _
[Aug 26 15:53:40.543] mongoose_poll New heap free LWM: 41304
[Aug 26 15:53:40.548] mgos_net_on_change_c WiFi STA: connecting
[Aug 26 15:53:42.555] scandone
You can see that the Temperature is not correct.
I use the same H/W configuration to test the DHT11 sensor on Arduino IDE. The Temperature is correct. Can anyone tell me how can I solve it ?
Thanks.
Paul Wang
Comments
I suggest to add these:
Hi Michael,
I modified my code:
let dht11 = DHT.create(5, DHT.DHT11);
if (dht11 === null) {
print('DHT sensor not detected.');
} else {
print ('DHT sensor detected!');
print('Temperature:', dht11.getTemp());
}
Then I get the following result.
[Aug 28 10:45:29.268] DHT sensor detected!
[Aug 28 10:45:29.294] Temperature: 9223372036854775807
It is a strange thing. If I disconnected DHT11 sensor with ESP12E (Nodemcu board) , I still get the same output message. Do you have any other suggestion ?
Regards,
Paul Wang
Hi,
I solve my issue. "My mos tool" version is "latest".
I use another library "api_arduino_dht.js".
I don't understand why "api_dht.js" can not work. I hope someone can show me how to use "api_dht.js" correctly.
Here is my code for "init.js".
Here is the code for my "mos.yml".
Regards,
Paul Wang
Mongoose OS is still evolving rapidly, so I am not surprised that old code does not work anymore.
@renleh, dht lib was fixed for DHT11 sensor. Please check, if this is still relevant.