{"id":32515092,"url":"https://github.com/momenso/node-dht-sensor","last_synced_at":"2026-04-29T22:03:19.429Z","repository":{"id":11295127,"uuid":"13708508","full_name":"momenso/node-dht-sensor","owner":"momenso","description":"Node.js Humidity and Temperature sensor addon","archived":false,"fork":false,"pushed_at":"2026-04-18T20:18:30.000Z","size":379,"stargazers_count":316,"open_issues_count":3,"forks_count":73,"subscribers_count":18,"default_branch":"master","last_synced_at":"2026-04-18T22:18:18.882Z","etag":null,"topics":["dht11","dht22","nodejs","raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/momenso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2013-10-19T20:47:50.000Z","updated_at":"2026-04-18T21:29:45.000Z","dependencies_parsed_at":"2025-10-28T00:19:51.616Z","dependency_job_id":"38d242ad-65f4-4a2f-9139-6ae2788565c4","html_url":"https://github.com/momenso/node-dht-sensor","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/momenso/node-dht-sensor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/momenso%2Fnode-dht-sensor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/momenso%2Fnode-dht-sensor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/momenso%2Fnode-dht-sensor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/momenso%2Fnode-dht-sensor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/momenso","download_url":"https://codeload.github.com/momenso/node-dht-sensor/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/momenso%2Fnode-dht-sensor/sbom","scorecard":{"id":657909,"data":{"date":"2025-08-11","repo":{"name":"github.com/momenso/node-dht-sensor","commit":"dd910b6fa83186c81db5c08f0dffda74915a33f1"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.7,"checks":[{"name":"Code-Review","score":2,"reason":"Found 2/8 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":3,"reason":"dependency not pinned by hash detected -- score normalized to 3","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/momenso/node-dht-sensor/nodejs.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/momenso/node-dht-sensor/nodejs.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/momenso/node-dht-sensor/npm-publish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm-publish.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/momenso/node-dht-sensor/npm-publish.yml/master?enable=pin","Info:   0 out of   4 GitHub-owned GitHubAction dependencies pinned","Info:   2 out of   2 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1","Warn: no topLevel permission defined: .github/workflows/npm-publish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: GNU Lesser General Public License v3.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 27 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":5,"reason":"5 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-21T15:11:18.327Z","repository_id":11295127,"created_at":"2025-08-21T15:11:18.327Z","updated_at":"2025-08-21T15:11:18.327Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32445555,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T20:22:27.477Z","status":"ssl_error","status_checked_at":"2026-04-29T20:22:26.507Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dht11","dht22","nodejs","raspberry-pi"],"created_at":"2025-10-28T00:19:23.389Z","updated_at":"2026-04-29T22:03:19.424Z","avatar_url":"https://github.com/momenso.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-dht-sensor\n\nA simple node.js module for reading temperature and relative humidity using a compatible DHT sensor.\n\n![](https://github.com/momenso/node-dht-sensor/workflows/Node.js%20CI/badge.svg)\n[![npm](https://img.shields.io/npm/v/node-dht-sensor.svg?label=npm%20package)](https://www.npmjs.com/package/node-dht-sensor)\n[![npm](https://img.shields.io/npm/dm/node-dht-sensor.svg)](https://www.npmjs.com/package/node-dht-sensor)\n[![LICENSE](https://img.shields.io/github/license/momenso/node-dht-sensor.svg)](https://github.com/momenso/node-dht-sensor/blob/master/LICENSE)\n\n## Installation \u0026 Hardware Requirements\n\nFor most standard Linux systems and older Raspberry Pi models (Pi 1 through 4), you can install the module directly via npm:\n\n```sh\nnpm install node-dht-sensor\n```\n\n### Modern Raspberry Pi (Pi 5 / Debian 12+) — libgpiod\n\nWhen running `node-dht-sensor` on a modern architecture like the Raspberry Pi 5, the legacy BCM2835 library is physically incompatible with the new RP1 southbridge chip. You **must** compile the module using `libgpiod`.\n\n**`libgpiod` v2 is the highly preferred library.** The v2 API allows this module to use an `OPEN_DRAIN` configuration, enabling fast, user-space polling of the sensor.\n\nBefore installing the module, you must install the `libgpiod` development headers and `pkg-config`. Our build system uses `pkg-config` to auto-detect whether your OS provides `libgpiod` v1 or v2 at build time and compiles the correct C++ code paths automatically.\n\nFor Debian-based systems (like Raspberry Pi OS):\n\n```sh\nsudo apt-get update\nsudo apt-get install -y libgpiod-dev pkg-config\n```\n\nThen, explicitly tell npm to use the libgpiod API during installation:\n\n```sh\nnpm install node-dht-sensor --use_libgpiod=true\n```\n\n### Older Raspberry Pi (Pi 1 through Pi 4) — BCM2835\n\nIf you omit the `--use_libgpiod=true` flag, `node-dht-sensor` defaults to using the direct-memory BCM2835 library. This bypasses the Linux kernel entirely for nanosecond-level read speeds and is highly recommended for older boards where the CPU manages the GPIO pins directly.\n\n## Usage\n\nTo initialize the sensor, you have to specify the sensor type and the [GPIO pin](https://www.raspberrypi.org/documentation/usage/gpio/) where the sensor is connected to. It should work for DHT11, DHT22 and AM2302 sensors.\n\nYou should use sensorType value to match the sensor as follows:\n\n| Sensor          | sensorType value |\n| --------------- | :--------------: |\n| DHT11           |        11        |\n| DHT22 or AM2302 |        22        |\n\nIf the initialization succeeds when you can call the read function to obtain the latest readout from the sensor. Readout values contains a temperature and a humidity property.\n\n### First Example\n\n![example1](https://cloud.githubusercontent.com/assets/420851/20246902/1a03bafc-a9a8-11e6-8158-d68928b2e79f.png)\n\nThis sample queries a DHT11 sensor connected to the GPIO 4 and prints out the result on the console.\n\n```javascript\nvar sensor = require(\"node-dht-sensor\");\n\nsensor.read(11, 4, function (err, temperature, humidity) {\n  if (!err) {\n    console.log(`temp: ${temperature}°C, humidity: ${humidity}%`);\n  }\n});\n```\n\n### Multiple Sensors Example\n\n![example2](https://cloud.githubusercontent.com/assets/420851/20246914/554d72c4-a9a8-11e6-9162-ae51ecdf4212.png)\n\nThe following example shows a method for querying multiple sensors connected to the same Raspberry Pi. For this example, we have two sensors:\n\n1. A DHT11 sensor connected to GPIO 17\n2. High-resolution DHT22 sensor connected to GPIO 4\n\n```javascript\nvar sensorLib = require(\"node-dht-sensor\");\n\nvar app = {\n  sensors: [\n    {\n      name: \"Indoor\",\n      type: 11,\n      pin: 17,\n    },\n    {\n      name: \"Outdoor\",\n      type: 22,\n      pin: 4,\n    },\n  ],\n  read: function () {\n    for (var sensor in this.sensors) {\n      var readout = sensorLib.read(\n        this.sensors[sensor].type,\n        this.sensors[sensor].pin,\n      );\n      console.log(\n        `[${this.sensors[sensor].name}] ` +\n          `temperature: ${readout.temperature.toFixed(1)}°C, ` +\n          `humidity: ${readout.humidity.toFixed(1)}%`,\n      );\n    }\n    setTimeout(function () {\n      app.read();\n    }, 2000);\n  },\n};\n\napp.read();\n```\n\n### Promises API\n\nPromises 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`.\n\n```javascript\nvar sensor = require(\"node-dht-sensor\").promises;\n\n// You can use `initialize` and `setMaxTries` just like before\nsensor.setMaxRetries(10);\nsensor.initialize(22, 17);\n\n// You can still use the synchronous version of `read`:\n// var readout = sensor.readSync(22, 4);\n\nsensor.read(22, 17).then(\n  function (res) {\n    console.log(\n      `temp: ${res.temperature.toFixed(1)}°C, ` +\n        `humidity: ${res.humidity.toFixed(1)}%`,\n    );\n  },\n  function (err) {\n    console.error(\"Failed to read sensor data:\", err);\n  },\n);\n```\n\nUsing `async/await`:\n\n```javascript\nconst sensor = require(\"node-dht-sensor\").promises;\n\nasync function exec() {\n  try {\n    const res = await sensor.read(22, 4);\n    console.log(\n      `temp: ${res.temperature.toFixed(1)}°C, ` +\n        `humidity: ${res.humidity.toFixed(1)}%`,\n    );\n  } catch (err) {\n    console.error(\"Failed to read sensor data:\", err);\n  }\n}\n\nexec();\n```\n\n### Test mode\n\nA _test mode_ of operation is available since version `0.2.0`. In this mode of operation, the library does not communicate with the sensor hardware via the **GPIO** but instead it returns a pre-configured readout value. You can use the test mode during development without the need to have an actual sensor connected.\n\nTo enable the _test mode_, fake values must be defined at initialization. In the example below we specify fixed values for temperature equal to 21\u0026deg;C and humidity equal to 60%.\n\n```javascript\nsensor.initialize({\n  test: {\n    fake: {\n      temperature: 21,\n      humidity: 60,\n    },\n  },\n});\n```\n\nAfter initialization, we can call the `read` method as usual.\n\n```javascript\nsensor.read(22, 4, function (err, temperature, humidity) {\n  if (!err) {\n    console.log(\n      `temp: ${temperature.toFixed(1)}°C, ` +\n        `humidity: ${humidity.toFixed(1)}%`,\n    );\n  }\n});\n```\n\nAnd the result will always be the configured readout value defined at initialization.\n\n```sh\nnode examples/fake-test.js\ntemp: 21.0°C, humidity: 60.0%\nnode examples/fake-test.js\ntemp: 21.0°C, humidity: 60.0%\n```\n\nYou can find a complete source code example in [examples/fake-test.js](https://github.com/momenso/node-dht-sensor/blob/master/examples/fake-test.js).\n\n## Manual Compilation \u0026 Debugging\n\nStandard node-gyp commands are used to build the module. So, just make sure you have `node` and `node-gyp`, and the appropriate C++ libraries (`bcm2835` or `libgpiod-dev`) to build the project.\n\n1. In case you don't have node-gyp, install it first:\n\n   ```sh\n   sudo npm install -g node-gyp\n   ```\n\n2. To configure and build the component manually with libgpiod auto-detection enabled:\n\n   ```sh\n   node-gyp configure --use_libgpiod=true\n   node-gyp build\n   ```\n\n## Tracing and Debugging\n\nVerbose output from the module can be enabled by specifying the `--dht_verbose=true` flag when installing the node via npm.\n\n```sh\nnpm install node-dht-sensor --dht_verbose=true\n```\n\nIf you are interested in enabling trace when building directly from source you can enable the `-Ddht_verbose` flag when running node-gyp configure.\n\n```sh\nnode-gyp configure -- -Ddht_verbose=true\n```\n\n## Appendix A: Quick Node.js installation guide\n\nThere are many ways you can get Node.js installed on your Raspberry Pi. For modern installations (including Raspberry Pi 5), the officially recommended approach is using the NodeSource package repository.\n\n```sh\ncurl -fsSL [https://deb.nodesource.com/setup_20.x](https://deb.nodesource.com/setup_20.x) | sudo -E bash -\nsudo apt-get install -y nodejs\n```\n\n_(This automatically installs the correct architecture build (e.g., `arm64`/`aarch64` for Pi 5 or `armhf` for older models) and includes npm)._\n\n## References\n\n[1]: Node.js download - https://nodejs.org/en/download/\n\n[2]: BCM2835 - http://www.airspayce.com/mikem/bcm2835/\n\n[3]: libgpiod - https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/\n\n[4]: Node.js native addon build tool - https://github.com/TooTallNate/node-gyp\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomenso%2Fnode-dht-sensor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmomenso%2Fnode-dht-sensor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmomenso%2Fnode-dht-sensor/lists"}