Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ npm-debug.log
node_modules

.vscode/
*.tgz
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
# node-dht-sensor
# node-dht-sensor-rp5

A simple node.js module for reading temperature and relative humidity using a compatible DHT sensor.

![](https://github.com/momenso/node-dht-sensor/workflows/Node.js%20CI/badge.svg)
[![npm](https://img.shields.io/npm/v/node-dht-sensor.svg?label=npm%20package)](https://www.npmjs.com/package/node-dht-sensor)
[![npm](https://img.shields.io/npm/dm/node-dht-sensor.svg)](https://www.npmjs.com/package/node-dht-sensor)
[![LICENSE](https://img.shields.io/github/license/momenso/node-dht-sensor.svg)](https://github.com/momenso/node-dht-sensor/blob/master/LICENSE)
[![npm](https://img.shields.io/npm/v/node-dht-sensor-rp5.svg?label=npm%20package)](https://www.npmjs.com/package/node-dht-sensor-rp5)
[![npm](https://img.shields.io/npm/dm/node-dht-sensor-rp5.svg)](https://www.npmjs.com/package/node-dht-sensor-rp5)
[![LICENSE](https://img.shields.io/github/license/kshetline/node-dht-sensor-rp5.svg)](https://github.com/kshetline/node-dht-sensor-rp5/blob/master/LICENSE)

> Please note that this library is a spin-off of David Momenso's **node-dht-sensor**, designed to deal with the new GPIO issues which have come along with the advent of the Raspberry Pi 5.

## Installation

```shell session
$ npm install node-dht-sensor
$ npm install node-dht-sensor-rp5 --use_libgpiod=true
```

Please note that differently from versions 0.0.x there's no need to pre-install the BCM2835 library [2].
Although this fork of **node-dht-sensor** exists for the purpose of supporting the Raspberry Pi 5 (and presumably future versions of the Pi using the same new architecture), the dependency on libgpiod can be avoided by omitting the
`‑‑use_libgpiod=true` parameter, resulting in a installation still capable of working on the Raspberry Pi 4 and earlier without the extra dependency.

```shell session
$ npm install node-dht-sensor-rp5
```

## Usage

Expand All @@ -35,7 +41,7 @@ If the initialization succeeds when you can call the read function to obtain the
This sample queries a DHT11 sensor connected to the GPIO 4 and prints out the result on the console.

```javascript
var sensor = require("node-dht-sensor");
var sensor = require("node-dht-sensor-rp5");

sensor.read(11, 4, function(err, temperature, humidity) {
if (!err) {
Expand All @@ -54,7 +60,7 @@ The following example shows a method for querying multiple sensors connected to
2. High-resolution DHT22 sensor connected to GPIO 4

```javascript
var sensorLib = require("node-dht-sensor");
var sensorLib = require("node-dht-sensor-rp5");

var app = {
sensors: [
Expand Down Expand Up @@ -92,10 +98,10 @@ app.read();

### Promises API

Promises API provides an alternative `read` method that returns a Promise object rather than using a callback. The API is accessible via `require('node-dht-sensor').promises`.
Promises API provides an alternative `read` method that returns a Promise object rather than using a callback. The API is accessible via `require('node-dht-sensor-rp5').promises`.

```javascript
var sensor = require("node-dht-sensor").promises;
var sensor = require("node-dht-sensor-rp5").promises;

// You can use `initialize` and `setMaxTries` just like before
sensor.setMaxRetries(10);
Expand All @@ -120,7 +126,7 @@ sensor.read(22, 17).then(
Using `async/await`:

```javascript
const sensor = require("node-dht-sensor").promises;
const sensor = require("node-dht-sensor-rp5").promises;

async function exec() {
try {
Expand Down Expand Up @@ -205,7 +211,7 @@ Standard node-gyp commands are used to build the module. So, just make sure you
Verbose output from the module can be enabled by by specifying the `--dht_verbose=true` flag when installing the node via npm.

```shell session
$ npm install node-dht-sensor --dht_verbose=true
$ npm install node-dht-sensor-rp5 --use_libgpiod --dht_verbose=true
```

if you are interested in enabling trace when building directly from source you can enable the `-Ddht_verbose` flag when running node-gyp configure.
Expand Down
12 changes: 10 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
"targets": [
{
"variables": {
"dht_verbose%": "false"
"dht_verbose%": "false",
"use_libgpiod%" : "false"
},
"target_name": "node_dht_sensor",
"sources": [
"src/bcm2835/bcm2835.c",
"src/node-dht-sensor.cpp",
"src/dht-sensor.cpp",
"src/util.cpp"
"src/util.cpp",
"src/abstract-gpio.cpp",
],
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")"
Expand All @@ -21,6 +23,12 @@
"conditions": [
["dht_verbose=='true'", {
"defines": [ "VERBOSE" ]
}],
["use_libgpiod=='true'", {
"defines": [ "USE_LIBGPIOD" ],
'libraries': [
'-lgpiod'
]
}]
]
}
Expand Down
Loading