A simple module for using DHT sensors in Mozilla WebThings
This module is a small wrapper (~500 bytes) around the node-dht-sensor made as simple as possible for the Mozilla WebThings Framework
With package manager:
$ npm install webthings-dht
# OR
$ yarn add webthings-dht
This example shows a zero config server:
import { WebThingServer } from 'webthing';
import WebThingDHT from 'webthings-dht';
const dhtSensor = new WebThingDHT();
const server = new WebThingServer(new SingleThing(dhtSensor), 8888);
server.start().catch(console.error);
The default config is:
const config = {
id: 'urn:dev:ops:dht-22-sensor',
name: 'DHT-22',
description: 'Ambient temperature & humidity sensor',
interval: 3000, // The invterval for fetching readings from the sensor (3s)
sensor: {
type: 22, // DHT sensor type. See node-dht-sensor (11 || 22)
pin: 4, // GPIO pin number
},
properties: {
temperature: {
'@type': 'TemperatureProperty',
title: 'Temperature',
type: 'number',
description: 'The ambient temperature measured in °C',
unit: 'degree celcius',
readOnly: true,
},
humidity: {
'@type': 'HumidityProperty',
title: 'Humidity',
type: 'number',
description: 'The current relative humidity in %',
minimum: 0,
maximum: 100,
unit: 'percent',
readOnly: true,
}
}
})
Contributions are welcome. Please open up an issue or create PR if you would like to help out.
Licensed under the MIT License.