-
Notifications
You must be signed in to change notification settings - Fork 73
Open
Description
I have searched a lot in this repository but unfortunately I couldn't find a solution for the problem I am facing.
I constantly get an error reading data from the sensor: Error: failed to read sensor
First off
- Using the Adafruit example script returns the values I am expecting - so it seems that its not a wiring issue
- I am using a DHT22 sensor (as module) without a pull up resistor
Raspberry Model B V2.0/npm -v: 6.14.8/node -v: v9.11.1- I have installed the package with the verbose flag
npm install node-dht-sensor --dht_verbose=true
If I run that simple script (taken from the examples) it returns an error. The logfile just says
start sensor read (type=22, pin=14).
*** timeout #2
sensor = require("node-dht-sensor");
var usage =
"USAGE: node async-explicit.js [sensorType] [gpioPin] <repeats>\n" +
" sensorType:\n" +
" 11: For DHT11 sensor.\n" +
" 22: For DHT22 or AM2302 sensors.\n\n" +
" gpipPin:\n" +
" Pin number where the sensor is physically connected to.\n\n" +
" repeats:\n" +
" How many times the read operation will be performed, default: 10\n";
if (process.argv.length < 4) {
console.warn(usage);
process.exit(1);
}
var sensorType = parseInt(process.argv[2], 10);
var gpioPin = parseInt(process.argv[3], 10);
var repeats = parseInt(process.argv[4] || "10", 10);
var count = 0;
var start = 0;
var end = 0;
var iid = setInterval(function() {
if (++count >= repeats) {
clearInterval(iid);
}
start = new Date().getTime();
sensor.read(sensorType, gpioPin, function(err, temperature, humidity) {
end = new Date().getTime();
if (err) {
console.warn("" + err);
} else {
console.log(
"temperature: %s°C, humidity: %s%%, time: %dms",
temperature.toFixed(1),
humidity.toFixed(1),
end - start
);
}
});
}, 3000);
Results in:
node index.js 22 14 1
(node:5316) Warning: N-API is an experimental feature and could change at any time.
BCM2835 initialized.
Error: failed to read sensor
If I run the same script but with type 11 it returns completely wrong values, but it returns at least something
node index.js 11 14 1
(node:5326) Warning: N-API is an experimental feature and could change at any time.
BCM2835 initialized.
temperature = 0, humidity = 2
temperature: 0.0°C, humidity: 2.0%, time: 52ms
To me this looks like an issue with the DHT22 type of sensor. Any hints are welcome. I am happy to provide more information if needed
JulianWowra
Metadata
Metadata
Assignees
Labels
No labels