node-red-contrib-periph-humidity 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -3
- package/examples/dht11/demo.json +8 -0
- package/nodes/dht11/dht11.html +74 -0
- package/nodes/dht11/dht11.js +50 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -2,15 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
Node-RED nodes for humidity sensor chips — part of the [Periph](https://github.com/tuhde/Periph) library.
|
|
4
4
|
|
|
5
|
-
> **Coming soon.** Nodes will be added as chips in this category are implemented.
|
|
6
|
-
|
|
7
5
|
## Install
|
|
8
6
|
|
|
7
|
+
Open Node-RED, go to **Manage Palette → Install** and search for `node-red-contrib-periph-humidity`.
|
|
8
|
+
|
|
9
|
+
Or from the command line in your Node-RED user directory:
|
|
10
|
+
|
|
9
11
|
```sh
|
|
10
12
|
npm install node-red-contrib-periph-humidity
|
|
11
13
|
```
|
|
12
14
|
|
|
15
|
+
## Nodes
|
|
16
|
+
|
|
17
|
+
| Node | Kind | Description |
|
|
18
|
+
|------|------|-------------|
|
|
19
|
+
| `dht11-device` | config | Bus configuration for a DHT11 |
|
|
20
|
+
| `dht11` | input | Reads temperature and humidity from a DHT11 sensor over a single GPIO data line. |
|
|
21
|
+
|
|
13
22
|
## Links
|
|
14
23
|
|
|
15
24
|
- [GitHub](https://github.com/tuhde/Periph)
|
|
16
|
-
- [
|
|
25
|
+
- [periph JS driver](https://www.npmjs.com/package/periph)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "dht11_demo_tab",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "DHT11 Demo",
|
|
6
|
+
"info": "Indoor comfort monitor using a DHT11 sensor.\n\nAn inject node fires every 5 seconds and triggers a `periph-dht11` read. The output connects to a debug node (logging the full payload) and two dashboard gauge nodes (node-red-dashboard): one for temperature in °C and one for humidity in %RH.\n\nConfigure the `dht11-device` config node with the GPIO pin number wired to the DHT11 DATA line (with a 4.7 kΩ pull-up to 3V3). Set the retry count to 3 to gracefully handle occasional checksum errors."
|
|
7
|
+
}
|
|
8
|
+
]
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('dht11-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
dataPin: { value: '4', required: true, validate: RED.validators.number() },
|
|
8
|
+
retries: { value: '3', required: true, validate: RED.validators.number() }
|
|
9
|
+
},
|
|
10
|
+
label: function() {
|
|
11
|
+
return this.name || ('DHT11 @ GPIO' + this.dataPin);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script type="text/html" data-template-name="dht11-device">
|
|
17
|
+
<div class="form-row">
|
|
18
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
19
|
+
<input type="text" id="node-config-input-name" placeholder="DHT11">
|
|
20
|
+
</div>
|
|
21
|
+
<div class="form-row">
|
|
22
|
+
<label for="node-config-input-dataPin"><i class="fa fa-microchip"></i> DATA GPIO</label>
|
|
23
|
+
<input type="number" id="node-config-input-dataPin" min="0" style="width:80px">
|
|
24
|
+
</div>
|
|
25
|
+
<div class="form-row">
|
|
26
|
+
<label for="node-config-input-retries">Retries</label>
|
|
27
|
+
<input type="number" id="node-config-input-retries" min="0" step="1" style="width:80px">
|
|
28
|
+
</div>
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<!-- Read node: trigger → measurements -->
|
|
32
|
+
<script type="text/javascript">
|
|
33
|
+
RED.nodes.registerType('dht11', {
|
|
34
|
+
category: 'Peripheral',
|
|
35
|
+
color: '#C084FC',
|
|
36
|
+
defaults: {
|
|
37
|
+
name: { value: '' },
|
|
38
|
+
device: { value: '', type: 'dht11-device', required: true }
|
|
39
|
+
},
|
|
40
|
+
inputs: 1,
|
|
41
|
+
outputs: 1,
|
|
42
|
+
icon: 'font-awesome/fa-tint',
|
|
43
|
+
label: function() { return this.name || 'DHT11'; },
|
|
44
|
+
paletteLabel: 'DHT11'
|
|
45
|
+
});
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<script type="text/html" data-template-name="dht11">
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
51
|
+
<input type="text" id="node-input-device">
|
|
52
|
+
</div>
|
|
53
|
+
<div class="form-row">
|
|
54
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
55
|
+
<input type="text" id="node-input-name" placeholder="DHT11">
|
|
56
|
+
</div>
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<script type="text/html" data-help-name="dht11">
|
|
60
|
+
<p>Reads temperature and humidity from a DHT11 sensor over a single GPIO data line.</p>
|
|
61
|
+
<p>Any input message triggers a measurement. The device is configured via a <b>dht11-device</b> config node.</p>
|
|
62
|
+
|
|
63
|
+
<h3>Output</h3>
|
|
64
|
+
<dl class="message-properties">
|
|
65
|
+
<dt>payload.temperature_c <span class="property-type">number</span></dt>
|
|
66
|
+
<dd>Temperature in degrees Celsius.</dd>
|
|
67
|
+
<dt>payload.humidity_rh <span class="property-type">number</span></dt>
|
|
68
|
+
<dd>Humidity in %RH.</dd>
|
|
69
|
+
</dl>
|
|
70
|
+
|
|
71
|
+
<h3>Details</h3>
|
|
72
|
+
<p>Configure the DATA GPIO pin and the retry count in the device config node. The driver uses the
|
|
73
|
+
DHTxx single-wire connection; a 4.7 kΩ pull-up resistor to VCC must be present on the data line.</p>
|
|
74
|
+
</script>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { DHTxxConnection } = require('periph/src/connection/dhtxx');
|
|
5
|
+
const { DHT11Full } = require('periph/src/chips/humidity/dht11');
|
|
6
|
+
|
|
7
|
+
function DHT11DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new DHTxxConnection(parseInt(config.dataPin, 10));
|
|
12
|
+
const retries = parseInt(config.retries, 10) || 3;
|
|
13
|
+
node.driver = new DHT11Full(connection, retries);
|
|
14
|
+
node.connection = connection;
|
|
15
|
+
} catch (e) {
|
|
16
|
+
node.error('DHT11 init failed: ' + e.message);
|
|
17
|
+
}
|
|
18
|
+
node.on('close', function() {
|
|
19
|
+
if (node.connection) node.connection.close();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
RED.nodes.registerType('dht11-device', DHT11DeviceNode);
|
|
23
|
+
|
|
24
|
+
function DHT11ReadNode(config) {
|
|
25
|
+
RED.nodes.createNode(this, config);
|
|
26
|
+
const node = this;
|
|
27
|
+
node.device = RED.nodes.getNode(config.device);
|
|
28
|
+
|
|
29
|
+
node.on('input', function(msg, send, done) {
|
|
30
|
+
if (!node.device || !node.device.driver) {
|
|
31
|
+
node.error('No DHT11 device configured', msg);
|
|
32
|
+
done();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const d = node.device.driver;
|
|
37
|
+
const r = d.read();
|
|
38
|
+
msg.payload = {
|
|
39
|
+
temperature_c: r.temperature,
|
|
40
|
+
humidity_rh: r.humidity
|
|
41
|
+
};
|
|
42
|
+
send(msg);
|
|
43
|
+
done();
|
|
44
|
+
} catch (e) {
|
|
45
|
+
done(e);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
RED.nodes.registerType('dht11', DHT11ReadNode);
|
|
50
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-humidity",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Node-RED nodes for humidity sensor chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
"peripheral"
|
|
12
12
|
],
|
|
13
13
|
"node-red": {
|
|
14
|
-
"nodes": {
|
|
14
|
+
"nodes": {
|
|
15
|
+
"dht11": "nodes/dht11/dht11.js"
|
|
16
|
+
}
|
|
15
17
|
},
|
|
16
18
|
"dependencies": {
|
|
17
19
|
"periph": "*"
|