node-red-contrib-periph-humidity 1.5.3 → 1.6.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 CHANGED
@@ -1,8 +1,8 @@
1
1
  # node-red-contrib-periph-humidity
2
2
 
3
- Node-RED nodes for humidity sensor chips: DHT11, HDC1008, HDC1080, HS30XX, HS40XX, HTU21DF, SHT31, SI7021 — part of the [Periph](https://github.com/tuhde/Periph) library.
3
+ Node-RED nodes for humidity sensor chips: DHT11, HDC1008, HDC1080, HS30XX, HS40XX, HTS221, HTU21DF, HTU31D, SHT31, SHTC3, SI7021 — part of the [Periph](https://github.com/tuhde/Periph) library.
4
4
 
5
- **Supported chips (8):** DHT11, HDC1008, HDC1080, HS30XX, HS40XX, HTU21DF, SHT31, SI7021.
5
+ **Supported chips (11):** DHT11, HDC1008, HDC1080, HS30XX, HS40XX, HTS221, HTU21DF, HTU31D, SHT31, SHTC3, SI7021.
6
6
 
7
7
  Each chip has a sensor/actuator node plus a shared `-device` config node that holds the bus settings. Importable example flows are in [`examples/`](https://github.com/tuhde/Periph/tree/main/nodejs/packages/node-red-contrib-periph-humidity/examples).
8
8
 
@@ -30,10 +30,16 @@ npm install node-red-contrib-periph-humidity
30
30
  | `hs30xx` | input | Reads temperature and relative humidity from a Renesas HS3001, HS3002 or HS3003 (the HS30xx family, one protocol) over I²C (fixed address 0x44) with one measurement per message. |
31
31
  | `hs40xx-device` | config | I²C bus and address for a HS40XX |
32
32
  | `hs40xx` | input | Reads temperature and relative humidity from a Renesas HS4001 or HS4003 (the HS40xx family, one protocol) over I²C (fixed address 0x54) with one no-hold measurement per message. HS4002 and the HS401x variants are physically different versions of the same part and are not offered separately. |
33
+ | `hts221-device` | config | I²C bus and address for a HTS221 |
34
+ | `hts221` | input | Reads temperature and relative humidity from an STMicroelectronics HTS221 over I²C (address 0x5F) with one factory-calibrated one-shot measurement per message. |
33
35
  | `htu21df-device` | config | I²C bus and address for a HTU21DF |
34
36
  | `htu21df` | input | Reads temperature and relative humidity from a Measurement Specialties HTU21D-F over I²C (fixed address 0x40) with one temperature and one humidity measurement per message. The CRC of both results is verified. |
37
+ | `htu31d-device` | config | I²C bus and address for a HTU31D |
38
+ | `htu31d` | input | Reads temperature and relative humidity from a TE Connectivity HTU31D over I²C (address 0x40 or 0x41) with one CRC-checked conversion per message. |
35
39
  | `sht31-device` | config | I²C bus and address for a SHT31 |
36
40
  | `sht31` | input | Reads temperature and relative humidity from a Sensirion SHT31 over I²C (0x44 with ADDR low, 0x45 with ADDR high) with one single-shot measurement per message. Both CRC bytes are verified. |
41
+ | `shtc3-device` | config | I²C bus and address for a SHTC3 |
42
+ | `shtc3` | input | Reads temperature and relative humidity from a Sensirion SHTC3 over I²C (address 0x70). Each message wakes the sensor, runs one CRC-checked measurement and puts it back to sleep. |
37
43
  | `si7021-device` | config | I²C bus and address for a SI7021 |
38
44
  | `si7021` | input | Reads relative humidity and temperature from a Silicon Labs Si7021 over I²C (fixed address 0x40) with one relative-humidity measurement per message; the temperature comes from the same conversion. The CRC of the humidity result is verified. |
39
45
 
@@ -0,0 +1,93 @@
1
+ [
2
+ {
3
+ "id": "hts221-tab",
4
+ "type": "tab",
5
+ "label": "HTS221 hygrometer",
6
+ "disabled": false,
7
+ "info": "Reads temperature and relative humidity from an HTS221 every 5 s and formats them as \"25.0 °C / 45.0 %RH\". The sensor is factory calibrated and measured one-shot per message; change the averaging in the HTS221 device node to trade noise against conversion time."
8
+ },
9
+ {
10
+ "id": "hts221-inject",
11
+ "type": "inject",
12
+ "z": "hts221-tab",
13
+ "name": "5 s timer",
14
+ "props": [
15
+ {
16
+ "p": "payload"
17
+ }
18
+ ],
19
+ "repeat": "5",
20
+ "crontab": "",
21
+ "once": false,
22
+ "onceDelay": 0.1,
23
+ "topic": "",
24
+ "payloadType": "date",
25
+ "x": 160,
26
+ "y": 160,
27
+ "wires": [
28
+ [
29
+ "hts221-node"
30
+ ]
31
+ ]
32
+ },
33
+ {
34
+ "id": "hts221-device-1",
35
+ "type": "hts221-device",
36
+ "name": "HTS221",
37
+ "bus": "1",
38
+ "address": "0x5F",
39
+ "temperatureSamples": "16",
40
+ "humiditySamples": "32",
41
+ "heater": false
42
+ },
43
+ {
44
+ "id": "hts221-node",
45
+ "type": "hts221",
46
+ "z": "hts221-tab",
47
+ "name": "HTS221",
48
+ "x": 380,
49
+ "y": 160,
50
+ "wires": [
51
+ [
52
+ "hts221-format"
53
+ ]
54
+ ],
55
+ "device": "hts221-device-1"
56
+ },
57
+ {
58
+ "id": "hts221-format",
59
+ "type": "function",
60
+ "z": "hts221-tab",
61
+ "name": "Format",
62
+ "func": "msg.payload = msg.payload.temperature_c.toFixed(1) + ' °C / ' + msg.payload.humidity_pct.toFixed(1) + ' %RH';\nreturn msg;",
63
+ "outputs": 1,
64
+ "noerr": 0,
65
+ "initialize": "",
66
+ "finalize": "",
67
+ "libs": [],
68
+ "x": 600,
69
+ "y": 160,
70
+ "wires": [
71
+ [
72
+ "hts221-debug"
73
+ ]
74
+ ]
75
+ },
76
+ {
77
+ "id": "hts221-debug",
78
+ "type": "debug",
79
+ "z": "hts221-tab",
80
+ "name": "Reading",
81
+ "active": true,
82
+ "tosidebar": true,
83
+ "console": false,
84
+ "tostatus": false,
85
+ "complete": "payload",
86
+ "targetType": "msg",
87
+ "statusVal": "",
88
+ "statusType": "auto",
89
+ "x": 800,
90
+ "y": 160,
91
+ "wires": []
92
+ }
93
+ ]
@@ -0,0 +1,93 @@
1
+ [
2
+ {
3
+ "id": "htu31d-tab",
4
+ "type": "tab",
5
+ "label": "HTU31D hygrometer",
6
+ "disabled": false,
7
+ "info": "Reads temperature and relative humidity from an HTU31D every 5 s and formats them as \"25.0 °C / 45.0 %RH\". Each message triggers one CRC-checked conversion; change the oversampling (OSR 0-3) in the HTU31D device node to trade resolution against conversion time."
8
+ },
9
+ {
10
+ "id": "htu31d-inject",
11
+ "type": "inject",
12
+ "z": "htu31d-tab",
13
+ "name": "5 s timer",
14
+ "props": [
15
+ {
16
+ "p": "payload"
17
+ }
18
+ ],
19
+ "repeat": "5",
20
+ "crontab": "",
21
+ "once": false,
22
+ "onceDelay": 0.1,
23
+ "topic": "",
24
+ "payloadType": "date",
25
+ "x": 160,
26
+ "y": 160,
27
+ "wires": [
28
+ [
29
+ "htu31d-node"
30
+ ]
31
+ ]
32
+ },
33
+ {
34
+ "id": "htu31d-device-1",
35
+ "type": "htu31d-device",
36
+ "name": "HTU31D",
37
+ "bus": "1",
38
+ "address": "0x40",
39
+ "osrRh": "3",
40
+ "osrT": "3",
41
+ "heater": false
42
+ },
43
+ {
44
+ "id": "htu31d-node",
45
+ "type": "htu31d",
46
+ "z": "htu31d-tab",
47
+ "name": "HTU31D",
48
+ "x": 380,
49
+ "y": 160,
50
+ "wires": [
51
+ [
52
+ "htu31d-format"
53
+ ]
54
+ ],
55
+ "device": "htu31d-device-1"
56
+ },
57
+ {
58
+ "id": "htu31d-format",
59
+ "type": "function",
60
+ "z": "htu31d-tab",
61
+ "name": "Format",
62
+ "func": "msg.payload = msg.payload.temperature_c.toFixed(1) + ' °C / ' + msg.payload.humidity_pct.toFixed(1) + ' %RH';\nreturn msg;",
63
+ "outputs": 1,
64
+ "noerr": 0,
65
+ "initialize": "",
66
+ "finalize": "",
67
+ "libs": [],
68
+ "x": 600,
69
+ "y": 160,
70
+ "wires": [
71
+ [
72
+ "htu31d-debug"
73
+ ]
74
+ ]
75
+ },
76
+ {
77
+ "id": "htu31d-debug",
78
+ "type": "debug",
79
+ "z": "htu31d-tab",
80
+ "name": "Reading",
81
+ "active": true,
82
+ "tosidebar": true,
83
+ "console": false,
84
+ "tostatus": false,
85
+ "complete": "payload",
86
+ "targetType": "msg",
87
+ "statusVal": "",
88
+ "statusType": "auto",
89
+ "x": 800,
90
+ "y": 160,
91
+ "wires": []
92
+ }
93
+ ]
@@ -0,0 +1,91 @@
1
+ [
2
+ {
3
+ "id": "shtc3-tab",
4
+ "type": "tab",
5
+ "label": "SHTC3 hygrometer",
6
+ "disabled": false,
7
+ "info": "Reads temperature and relative humidity from an SHTC3 every 5 s and formats them as \"25.0 °C / 45.0 %RH\". Each message triggers one CRC-checked measurement; the sensor sleeps between messages. Set msg.low_power = true on an inject node, or tick low-power mode in the SHTC3 device node, for 0.7 ms measurements."
8
+ },
9
+ {
10
+ "id": "shtc3-inject",
11
+ "type": "inject",
12
+ "z": "shtc3-tab",
13
+ "name": "5 s timer",
14
+ "props": [
15
+ {
16
+ "p": "payload"
17
+ }
18
+ ],
19
+ "repeat": "5",
20
+ "crontab": "",
21
+ "once": false,
22
+ "onceDelay": 0.1,
23
+ "topic": "",
24
+ "payloadType": "date",
25
+ "x": 160,
26
+ "y": 160,
27
+ "wires": [
28
+ [
29
+ "shtc3-node"
30
+ ]
31
+ ]
32
+ },
33
+ {
34
+ "id": "shtc3-device-1",
35
+ "type": "shtc3-device",
36
+ "name": "SHTC3",
37
+ "bus": "1",
38
+ "address": "0x70",
39
+ "lowPower": false
40
+ },
41
+ {
42
+ "id": "shtc3-node",
43
+ "type": "shtc3",
44
+ "z": "shtc3-tab",
45
+ "name": "SHTC3",
46
+ "x": 380,
47
+ "y": 160,
48
+ "wires": [
49
+ [
50
+ "shtc3-format"
51
+ ]
52
+ ],
53
+ "device": "shtc3-device-1"
54
+ },
55
+ {
56
+ "id": "shtc3-format",
57
+ "type": "function",
58
+ "z": "shtc3-tab",
59
+ "name": "Format",
60
+ "func": "msg.payload = msg.payload.temperature_c.toFixed(1) + ' °C / ' + msg.payload.humidity_pct.toFixed(1) + ' %RH';\nreturn msg;",
61
+ "outputs": 1,
62
+ "noerr": 0,
63
+ "initialize": "",
64
+ "finalize": "",
65
+ "libs": [],
66
+ "x": 600,
67
+ "y": 160,
68
+ "wires": [
69
+ [
70
+ "shtc3-debug"
71
+ ]
72
+ ]
73
+ },
74
+ {
75
+ "id": "shtc3-debug",
76
+ "type": "debug",
77
+ "z": "shtc3-tab",
78
+ "name": "Reading",
79
+ "active": true,
80
+ "tosidebar": true,
81
+ "console": false,
82
+ "tostatus": false,
83
+ "complete": "payload",
84
+ "targetType": "msg",
85
+ "statusVal": "",
86
+ "statusType": "auto",
87
+ "x": 800,
88
+ "y": 160,
89
+ "wires": []
90
+ }
91
+ ]
@@ -0,0 +1,110 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('hts221-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x5F' },
9
+ temperatureSamples: { value: '16' },
10
+ humiditySamples: { value: '32' },
11
+ heater: { value: false }
12
+ },
13
+ label: function() {
14
+ return this.name || ('HTS221 @ ' + this.address + ' (bus ' + this.bus + ')');
15
+ }
16
+ });
17
+ </script>
18
+
19
+ <script type="text/html" data-template-name="hts221-device">
20
+ <div class="form-row">
21
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
22
+ <input type="text" id="node-config-input-name" placeholder="HTS221">
23
+ </div>
24
+ <div class="form-row">
25
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
26
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
27
+ </div>
28
+ <div class="form-row">
29
+ <label for="node-config-input-address"><i class="fa fa-microchip"></i> I²C address</label>
30
+ <input type="text" id="node-config-input-address" style="width:80px" placeholder="0x5F"> &nbsp;(fixed 0x5F)
31
+ </div>
32
+ <div class="form-row">
33
+ <label for="node-config-input-temperatureSamples"><i class="fa fa-cog"></i> Temperature averaging</label>
34
+ <select id="node-config-input-temperatureSamples" style="width:120px">
35
+ <option value="2">2 samples</option>
36
+ <option value="4">4 samples</option>
37
+ <option value="8">8 samples</option>
38
+ <option value="16" selected>16 samples</option>
39
+ <option value="32">32 samples</option>
40
+ <option value="64">64 samples</option>
41
+ <option value="128">128 samples</option>
42
+ <option value="256">256 samples</option>
43
+ </select>
44
+ </div>
45
+ <div class="form-row">
46
+ <label for="node-config-input-humiditySamples"><i class="fa fa-cog"></i> Humidity averaging</label>
47
+ <select id="node-config-input-humiditySamples" style="width:120px">
48
+ <option value="4">4 samples</option>
49
+ <option value="8">8 samples</option>
50
+ <option value="16">16 samples</option>
51
+ <option value="32" selected>32 samples</option>
52
+ <option value="64">64 samples</option>
53
+ <option value="128">128 samples</option>
54
+ <option value="256">256 samples</option>
55
+ <option value="512">512 samples</option>
56
+ </select>
57
+ </div>
58
+ <div class="form-row">
59
+ <label for="node-config-input-heater"><i class="fa fa-fire"></i> Heater</label>
60
+ <input type="checkbox" id="node-config-input-heater" style="width:auto"> &nbsp;on (do not measure while heating)
61
+ </div>
62
+ </script>
63
+
64
+ <!-- Read node -->
65
+ <script type="text/javascript">
66
+ RED.nodes.registerType('hts221', {
67
+ category: 'Peripheral',
68
+ color: '#C084FC',
69
+ defaults: {
70
+ name: { value: '' },
71
+ device: { value: '', type: 'hts221-device', required: true }
72
+ },
73
+ inputs: 1,
74
+ outputs: 1,
75
+ icon: 'bridge.svg',
76
+ label: function() { return this.name || 'HTS221'; },
77
+ paletteLabel: 'HTS221'
78
+ });
79
+ </script>
80
+
81
+ <script type="text/html" data-template-name="hts221">
82
+ <div class="form-row">
83
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
84
+ <input type="text" id="node-input-name" placeholder="HTS221">
85
+ </div>
86
+ <div class="form-row">
87
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
88
+ <input type="text" id="node-input-device">
89
+ </div>
90
+ </script>
91
+
92
+ <script type="text/html" data-help-name="hts221">
93
+ <p>Reads temperature and relative humidity from an STMicroelectronics HTS221 over I²C (address 0x5F)
94
+ with one factory-calibrated one-shot measurement per message.</p>
95
+ <h3>Inputs</h3>
96
+ <dl class="message-properties">
97
+ <dt>payload <span class="property-type">any</span></dt>
98
+ <dd>Any incoming message triggers one measurement.</dd>
99
+ </dl>
100
+ <h3>Outputs</h3>
101
+ <dl class="message-properties">
102
+ <dt>payload.temperature_c <span class="property-type">number</span></dt>
103
+ <dd>Temperature in °C.</dd>
104
+ <dt>payload.humidity_pct <span class="property-type">number</span></dt>
105
+ <dd>Relative humidity in %rH (0 to 100).</dd>
106
+ </dl>
107
+ <h3>Configuration</h3>
108
+ <p>I²C bus number, I²C address (0x5F), the temperature and humidity averaging (number of samples) and the
109
+ internal heater, set in the <b>hts221-device</b> config node.</p>
110
+ </script>
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { HTS221Full } = require('periph/src/chips/humidity/hts221');
6
+
7
+ function HTS221DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const address = parseInt(config.address, 16) || 0x5F;
12
+ const connection = new I2CConnection(parseInt(config.bus), address);
13
+ node.connection = connection;
14
+ node.driver = new HTS221Full(connection);
15
+ node.ready = (async () => {
16
+ await node.driver.init();
17
+ const t = parseInt(config.temperatureSamples) || 16;
18
+ const h = parseInt(config.humiditySamples) || 32;
19
+ await node.driver.setAveraging(t, h);
20
+ await node.driver.setHeater(config.heater === true || config.heater === 'true');
21
+ })();
22
+ node.ready.catch((e) => {
23
+ node.error('HTS221 init failed: ' + e.message);
24
+ });
25
+ } catch (e) {
26
+ node.error('HTS221 init failed: ' + e.message);
27
+ }
28
+
29
+ node.on('close', function() {
30
+ if (node.connection) node.connection.close();
31
+ });
32
+ }
33
+ RED.nodes.registerType('hts221-device', HTS221DeviceNode);
34
+
35
+ function HTS221ReadNode(config) {
36
+ RED.nodes.createNode(this, config);
37
+ const node = this;
38
+ const deviceNode = RED.nodes.getNode(config.device) || {};
39
+
40
+ node.on('input', async function(msg, send, done) {
41
+ if (!deviceNode.driver) {
42
+ node.error('HTS221 not initialised', msg);
43
+ done();
44
+ return;
45
+ }
46
+ try {
47
+ await deviceNode.ready;
48
+ const { temperature_c, humidity_pct } = await deviceNode.driver.read();
49
+ msg.payload = { temperature_c, humidity_pct };
50
+ send(msg);
51
+ done();
52
+ } catch (e) {
53
+ done(e);
54
+ }
55
+ });
56
+ }
57
+ RED.nodes.registerType('hts221', HTS221ReadNode);
58
+ };
@@ -0,0 +1,102 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('htu31d-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x40' },
9
+ osrRh: { value: '3' },
10
+ osrT: { value: '3' },
11
+ heater: { value: false }
12
+ },
13
+ label: function() {
14
+ return this.name || ('HTU31D @ ' + this.address + ' (bus ' + this.bus + ')');
15
+ }
16
+ });
17
+ </script>
18
+
19
+ <script type="text/html" data-template-name="htu31d-device">
20
+ <div class="form-row">
21
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
22
+ <input type="text" id="node-config-input-name" placeholder="HTU31D">
23
+ </div>
24
+ <div class="form-row">
25
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
26
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
27
+ </div>
28
+ <div class="form-row">
29
+ <label for="node-config-input-address"><i class="fa fa-microchip"></i> I²C address</label>
30
+ <input type="text" id="node-config-input-address" style="width:80px" placeholder="0x40"> &nbsp;(0x40 or 0x41, IC_Add pin)
31
+ </div>
32
+ <div class="form-row">
33
+ <label for="node-config-input-osrRh"><i class="fa fa-cog"></i> Humidity oversampling</label>
34
+ <select id="node-config-input-osrRh" style="width:120px">
35
+ <option value="0">OSR 0</option>
36
+ <option value="1">OSR 1</option>
37
+ <option value="2">OSR 2</option>
38
+ <option value="3" selected>OSR 3</option>
39
+ </select>
40
+ </div>
41
+ <div class="form-row">
42
+ <label for="node-config-input-osrT"><i class="fa fa-cog"></i> Temperature oversampling</label>
43
+ <select id="node-config-input-osrT" style="width:120px">
44
+ <option value="0">OSR 0</option>
45
+ <option value="1">OSR 1</option>
46
+ <option value="2">OSR 2</option>
47
+ <option value="3" selected>OSR 3</option>
48
+ </select>
49
+ </div>
50
+ <div class="form-row">
51
+ <label for="node-config-input-heater"><i class="fa fa-fire"></i> Heater</label>
52
+ <input type="checkbox" id="node-config-input-heater" style="width:auto"> &nbsp;on (do not measure while heating)
53
+ </div>
54
+ </script>
55
+
56
+ <!-- Read node -->
57
+ <script type="text/javascript">
58
+ RED.nodes.registerType('htu31d', {
59
+ category: 'Peripheral',
60
+ color: '#C084FC',
61
+ defaults: {
62
+ name: { value: '' },
63
+ device: { value: '', type: 'htu31d-device', required: true }
64
+ },
65
+ inputs: 1,
66
+ outputs: 1,
67
+ icon: 'bridge.svg',
68
+ label: function() { return this.name || 'HTU31D'; },
69
+ paletteLabel: 'HTU31D'
70
+ });
71
+ </script>
72
+
73
+ <script type="text/html" data-template-name="htu31d">
74
+ <div class="form-row">
75
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
76
+ <input type="text" id="node-input-name" placeholder="HTU31D">
77
+ </div>
78
+ <div class="form-row">
79
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
80
+ <input type="text" id="node-input-device">
81
+ </div>
82
+ </script>
83
+
84
+ <script type="text/html" data-help-name="htu31d">
85
+ <p>Reads temperature and relative humidity from a TE Connectivity HTU31D over I²C (address 0x40 or 0x41)
86
+ with one CRC-checked conversion per message.</p>
87
+ <h3>Inputs</h3>
88
+ <dl class="message-properties">
89
+ <dt>payload <span class="property-type">any</span></dt>
90
+ <dd>Any incoming message triggers one measurement.</dd>
91
+ </dl>
92
+ <h3>Outputs</h3>
93
+ <dl class="message-properties">
94
+ <dt>payload.temperature_c <span class="property-type">number</span></dt>
95
+ <dd>Temperature in °C.</dd>
96
+ <dt>payload.humidity_pct <span class="property-type">number</span></dt>
97
+ <dd>Relative humidity in %RH (0 to 100).</dd>
98
+ </dl>
99
+ <h3>Configuration</h3>
100
+ <p>I²C bus number, I²C address (0x40 or 0x41), the humidity and temperature oversampling (OSR 0 to 3) and the
101
+ internal heater, set in the <b>htu31d-device</b> config node.</p>
102
+ </script>
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { HTU31DFull } = require('periph/src/chips/humidity/htu31d');
6
+
7
+ function HTU31DDeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const address = parseInt(config.address, 16) || 0x40;
12
+ const connection = new I2CConnection(parseInt(config.bus), address);
13
+ node.connection = connection;
14
+ node.driver = new HTU31DFull(connection);
15
+ node.ready = (async () => {
16
+ await node.driver.init();
17
+ const rh = parseInt(config.osrRh);
18
+ const t = parseInt(config.osrT);
19
+ node.driver.setResolution(isNaN(rh) ? 3 : rh, isNaN(t) ? 3 : t);
20
+ await node.driver.setHeater(config.heater === true || config.heater === 'true');
21
+ })();
22
+ node.ready.catch((e) => {
23
+ node.error('HTU31D init failed: ' + e.message);
24
+ });
25
+ } catch (e) {
26
+ node.error('HTU31D init failed: ' + e.message);
27
+ }
28
+
29
+ node.on('close', function() {
30
+ if (node.connection) node.connection.close();
31
+ });
32
+ }
33
+ RED.nodes.registerType('htu31d-device', HTU31DDeviceNode);
34
+
35
+ function HTU31DReadNode(config) {
36
+ RED.nodes.createNode(this, config);
37
+ const node = this;
38
+ const deviceNode = RED.nodes.getNode(config.device) || {};
39
+
40
+ node.on('input', async function(msg, send, done) {
41
+ if (!deviceNode.driver) {
42
+ node.error('HTU31D not initialised', msg);
43
+ done();
44
+ return;
45
+ }
46
+ try {
47
+ await deviceNode.ready;
48
+ const { temperature_c, humidity_pct } = await deviceNode.driver.read();
49
+ msg.payload = { temperature_c, humidity_pct };
50
+ send(msg);
51
+ done();
52
+ } catch (e) {
53
+ done(e);
54
+ }
55
+ });
56
+ }
57
+ RED.nodes.registerType('htu31d', HTU31DReadNode);
58
+ };
@@ -0,0 +1,83 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('shtc3-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x70' },
9
+ lowPower: { value: false }
10
+ },
11
+ label: function() {
12
+ return this.name || ('SHTC3 @ ' + this.address + ' (bus ' + this.bus + ')');
13
+ }
14
+ });
15
+ </script>
16
+
17
+ <script type="text/html" data-template-name="shtc3-device">
18
+ <div class="form-row">
19
+ <label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
20
+ <input type="text" id="node-config-input-name" placeholder="SHTC3">
21
+ </div>
22
+ <div class="form-row">
23
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
24
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
25
+ </div>
26
+ <div class="form-row">
27
+ <label for="node-config-input-address"><i class="fa fa-microchip"></i> I²C address</label>
28
+ <input type="text" id="node-config-input-address" style="width:80px" placeholder="0x70"> &nbsp;(fixed 0x70)
29
+ </div>
30
+ <div class="form-row">
31
+ <label for="node-config-input-lowPower"><i class="fa fa-cog"></i> Low-power mode</label>
32
+ <input type="checkbox" id="node-config-input-lowPower" style="width:auto"> &nbsp;0.7 ms measurement instead of 10.8 ms (slightly noisier)
33
+ </div>
34
+ </script>
35
+
36
+ <!-- Read node -->
37
+ <script type="text/javascript">
38
+ RED.nodes.registerType('shtc3', {
39
+ category: 'Peripheral',
40
+ color: '#C084FC',
41
+ defaults: {
42
+ name: { value: '' },
43
+ device: { value: '', type: 'shtc3-device', required: true }
44
+ },
45
+ inputs: 1,
46
+ outputs: 1,
47
+ icon: 'bridge.svg',
48
+ label: function() { return this.name || 'SHTC3'; },
49
+ paletteLabel: 'SHTC3'
50
+ });
51
+ </script>
52
+
53
+ <script type="text/html" data-template-name="shtc3">
54
+ <div class="form-row">
55
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
56
+ <input type="text" id="node-input-name" placeholder="SHTC3">
57
+ </div>
58
+ <div class="form-row">
59
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
60
+ <input type="text" id="node-input-device">
61
+ </div>
62
+ </script>
63
+
64
+ <script type="text/html" data-help-name="shtc3">
65
+ <p>Reads temperature and relative humidity from a Sensirion SHTC3 over I²C (address 0x70). Each message wakes the
66
+ sensor, runs one CRC-checked measurement and puts it back to sleep.</p>
67
+ <h3>Inputs</h3>
68
+ <dl class="message-properties">
69
+ <dt>payload <span class="property-type">any</span></dt>
70
+ <dd>Any incoming message triggers one measurement.</dd>
71
+ <dt>low_power <span class="property-type">boolean</span></dt>
72
+ <dd>Optional. Overrides the configured measurement mode for this reading.</dd>
73
+ </dl>
74
+ <h3>Outputs</h3>
75
+ <dl class="message-properties">
76
+ <dt>payload.temperature_c <span class="property-type">number</span></dt>
77
+ <dd>Temperature in °C.</dd>
78
+ <dt>payload.humidity_pct <span class="property-type">number</span></dt>
79
+ <dd>Relative humidity in %RH (0 to 100).</dd>
80
+ </dl>
81
+ <h3>Configuration</h3>
82
+ <p>I²C bus number, I²C address (0x70) and the low-power mode, set in the <b>shtc3-device</b> config node.</p>
83
+ </script>
@@ -0,0 +1,57 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { SHTC3Full } = require('periph/src/chips/humidity/shtc3');
6
+
7
+ function SHTC3DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const address = parseInt(config.address, 16) || 0x70;
12
+ const connection = new I2CConnection(parseInt(config.bus), address);
13
+ node.connection = connection;
14
+ node.driver = new SHTC3Full(connection);
15
+ node.ready = (async () => {
16
+ await node.driver.init();
17
+ node.lowPower = config.lowPower === true || config.lowPower === 'true';
18
+ })();
19
+ node.ready.catch((e) => {
20
+ node.error('SHTC3 init failed: ' + e.message);
21
+ });
22
+ } catch (e) {
23
+ node.error('SHTC3 init failed: ' + e.message);
24
+ }
25
+
26
+ node.on('close', function() {
27
+ if (node.connection) node.connection.close();
28
+ });
29
+ }
30
+ RED.nodes.registerType('shtc3-device', SHTC3DeviceNode);
31
+
32
+ function SHTC3ReadNode(config) {
33
+ RED.nodes.createNode(this, config);
34
+ const node = this;
35
+ const deviceNode = RED.nodes.getNode(config.device) || {};
36
+
37
+ node.on('input', async function(msg, send, done) {
38
+ if (!deviceNode.driver) {
39
+ node.error('SHTC3 not initialised', msg);
40
+ done();
41
+ return;
42
+ }
43
+ try {
44
+ await deviceNode.ready;
45
+ const lowPower = typeof msg.low_power === 'boolean' ? msg.low_power : deviceNode.lowPower === true;
46
+ deviceNode.driver.setLowPower(lowPower);
47
+ const { temperature_c, humidity_pct } = await deviceNode.driver.read();
48
+ msg.payload = { temperature_c, humidity_pct };
49
+ send(msg);
50
+ done();
51
+ } catch (e) {
52
+ done(e);
53
+ }
54
+ });
55
+ }
56
+ RED.nodes.registerType('shtc3', SHTC3ReadNode);
57
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-humidity",
3
- "version": "1.5.3",
4
- "description": "Node-RED nodes for humidity sensor chips: DHT11, HDC1008, HDC1080, HS30XX, HS40XX, HTU21DF, SHT31, SI7021",
3
+ "version": "1.6.0",
4
+ "description": "Node-RED nodes for humidity sensor chips: DHT11, HDC1008, HDC1080, HS30XX, HS40XX, HTS221, HTU21DF, HTU31D, SHT31, SHTC3, SI7021",
5
5
  "keywords": [
6
6
  "node-red",
7
7
  "humidity",
@@ -15,8 +15,11 @@
15
15
  "hdc1080",
16
16
  "hs30xx",
17
17
  "hs40xx",
18
+ "hts221",
18
19
  "htu21df",
20
+ "htu31d",
19
21
  "sht31",
22
+ "shtc3",
20
23
  "si7021"
21
24
  ],
22
25
  "node-red": {
@@ -27,13 +30,28 @@
27
30
  "hdc1080": "nodes/hdc1080/hdc1080.js",
28
31
  "hs30xx": "nodes/hs30xx/hs30xx.js",
29
32
  "hs40xx": "nodes/hs40xx/hs40xx.js",
33
+ "hts221": "nodes/hts221/hts221.js",
30
34
  "htu21df": "nodes/htu21df/htu21df.js",
35
+ "htu31d": "nodes/htu31d/htu31d.js",
31
36
  "sht31": "nodes/sht31/sht31.js",
37
+ "shtc3": "nodes/shtc3/shtc3.js",
32
38
  "si7021": "nodes/si7021/si7021.js"
33
39
  }
34
40
  },
35
41
  "dependencies": {
36
42
  "periph": "*"
37
43
  },
38
- "license": "MIT"
44
+ "license": "MIT",
45
+ "engines": {
46
+ "node": ">=18"
47
+ },
48
+ "bugs": {
49
+ "url": "https://github.com/tuhde/Periph/issues"
50
+ },
51
+ "homepage": "https://github.com/tuhde/Periph/tree/main/nodejs/packages/node-red-contrib-periph-humidity#readme",
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/tuhde/Periph.git",
55
+ "directory": "nodejs/packages/node-red-contrib-periph-humidity"
56
+ }
39
57
  }