node-red-contrib-periph-environmental 1.5.0 → 1.5.1

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
@@ -16,9 +16,14 @@ npm install node-red-contrib-periph-environmental
16
16
 
17
17
  | Node | Kind | Description |
18
18
  |------|------|-------------|
19
+ | `aht10-device` | config | I²C bus and address for an AHT10 |
20
+ | `aht10` | input | Reads temperature and humidity from an AHT10 environmental sensor over I²C. |
21
+ | `aht20-device` | config | I²C bus and address for an AHT20 |
22
+ | `aht20` | input | Reads temperature and humidity from an AHT20 environmental sensor over I²C. |
19
23
  | `aht21-device` | config | I²C bus and address for an AHT21 |
20
24
  | `aht21` | input | Reads temperature and humidity from an AHT21 environmental sensor over I²C. |
21
25
  | `periph-am2315` | input | Reads temperature and relative humidity from an Aosong AM2315 over I²C (fixed address 0x5C). The sensor sleeps between transactions and returns the result of the previous measurement; the node keeps transactions at least 2 s apart, so a message arriving earlier is answered after the remaining delay. Every response is CRC-16 checked. |
26
+ | `periph-am2320` | input | Reads temperature and relative humidity from an Aosong AM2320 over I²C (fixed address 0x5C). The sensor sleeps between transactions and returns the result of the previous measurement; the node keeps transactions at least 2 s apart, so a message arriving earlier is answered after the remaining delay. Every response is CRC-16 checked. |
22
27
  | `bme280-device` | config | Bus configuration for a BME280 |
23
28
  | `periph-bme280` | input | Reads temperature, pressure, humidity, altitude, and dew point from a BME280 combined humidity + pressure + temperature sensor. |
24
29
  | `bme680-device` | config | Bus configuration for a BME680 |
@@ -0,0 +1,121 @@
1
+ [
2
+ {
3
+ "id": "tab-aht10-demo",
4
+ "type": "tab",
5
+ "label": "AHT10 Weather Station",
6
+ "disabled": false,
7
+ "info": "Reads temperature and humidity from an AHT10 every 5 seconds and displays a formatted string in the debug panel. A second branch feeds two Gauge dashboard widgets for live visual monitoring of temperature and humidity."
8
+ },
9
+ {
10
+ "id": "cfg-aht10",
11
+ "type": "aht10-device",
12
+ "name": "AHT10",
13
+ "bus": "1",
14
+ "address": "38"
15
+ },
16
+ {
17
+ "id": "inj-tick",
18
+ "type": "inject",
19
+ "name": "every 5 s",
20
+ "repeat": "5",
21
+ "crontab": "",
22
+ "once": true,
23
+ "onceDelay": 0.1,
24
+ "topic": "",
25
+ "payload": "",
26
+ "payloadType": "date",
27
+ "z": "tab-aht10-demo",
28
+ "x": 120,
29
+ "y": 160,
30
+ "wires": [["read-aht10"]]
31
+ },
32
+ {
33
+ "id": "read-aht10",
34
+ "type": "aht10",
35
+ "name": "AHT10",
36
+ "device": "cfg-aht10",
37
+ "z": "tab-aht10-demo",
38
+ "x": 300,
39
+ "y": 160,
40
+ "wires": [["fmt-readings", "gauge-temp", "gauge-hum"]]
41
+ },
42
+ {
43
+ "id": "fmt-readings",
44
+ "type": "function",
45
+ "name": "format",
46
+ "func": "const p = msg.payload;\nmsg.payload = p.temperature_c.toFixed(1) + ' °C / ' + p.humidity_pct.toFixed(1) + ' %RH';\nreturn msg;",
47
+ "outputs": 1,
48
+ "noerr": 0,
49
+ "initialize": "",
50
+ "finalize": "",
51
+ "libs": [],
52
+ "z": "tab-aht10-demo",
53
+ "x": 480,
54
+ "y": 160,
55
+ "wires": [["dbg-readings"]]
56
+ },
57
+ {
58
+ "id": "dbg-readings",
59
+ "type": "debug",
60
+ "name": "",
61
+ "active": true,
62
+ "tosidebar": true,
63
+ "console": false,
64
+ "tostatus": true,
65
+ "complete": "payload",
66
+ "targetType": "msg",
67
+ "statusVal": "payload",
68
+ "statusType": "auto",
69
+ "z": "tab-aht10-demo",
70
+ "x": 650,
71
+ "y": 160,
72
+ "wires": []
73
+ },
74
+ {
75
+ "id": "gauge-temp",
76
+ "type": "ui_gauge",
77
+ "name": "Temperature",
78
+ "group": "grp-aht10",
79
+ "order": 1,
80
+ "width": 6,
81
+ "height": 4,
82
+ "gtype": "gage",
83
+ "title": "Temperature",
84
+ "label": "°C",
85
+ "format": "{{value | number:1}}",
86
+ "min": -10,
87
+ "max": 50,
88
+ "z": "tab-aht10-demo",
89
+ "x": 490,
90
+ "y": 220,
91
+ "wires": []
92
+ },
93
+ {
94
+ "id": "gauge-hum",
95
+ "type": "ui_gauge",
96
+ "name": "Humidity",
97
+ "group": "grp-aht10",
98
+ "order": 2,
99
+ "width": 6,
100
+ "height": 4,
101
+ "gtype": "gage",
102
+ "title": "Humidity",
103
+ "label": "%RH",
104
+ "format": "{{value | number:1}}",
105
+ "min": 0,
106
+ "max": 100,
107
+ "z": "tab-aht10-demo",
108
+ "x": 480,
109
+ "y": 280,
110
+ "wires": []
111
+ },
112
+ {
113
+ "id": "grp-aht10",
114
+ "type": "ui_group",
115
+ "name": "AHT10",
116
+ "tab": "tab-aht10-demo",
117
+ "order": 1,
118
+ "disp": true,
119
+ "width": 12
120
+ }
121
+ ]
@@ -0,0 +1,121 @@
1
+ [
2
+ {
3
+ "id": "tab-aht20-demo",
4
+ "type": "tab",
5
+ "label": "AHT20 Weather Station",
6
+ "disabled": false,
7
+ "info": "Reads temperature and humidity from an AHT20 every 5 seconds and displays a formatted string in the debug panel. A second branch feeds two Gauge dashboard widgets for live visual monitoring of temperature and humidity."
8
+ },
9
+ {
10
+ "id": "cfg-aht20",
11
+ "type": "aht20-device",
12
+ "name": "AHT20",
13
+ "bus": "1",
14
+ "address": "38"
15
+ },
16
+ {
17
+ "id": "inj-tick",
18
+ "type": "inject",
19
+ "name": "every 5 s",
20
+ "repeat": "5",
21
+ "crontab": "",
22
+ "once": true,
23
+ "onceDelay": 0.1,
24
+ "topic": "",
25
+ "payload": "",
26
+ "payloadType": "date",
27
+ "z": "tab-aht20-demo",
28
+ "x": 120,
29
+ "y": 160,
30
+ "wires": [["read-aht20"]]
31
+ },
32
+ {
33
+ "id": "read-aht20",
34
+ "type": "aht20",
35
+ "name": "AHT20",
36
+ "device": "cfg-aht20",
37
+ "z": "tab-aht20-demo",
38
+ "x": 300,
39
+ "y": 160,
40
+ "wires": [["fmt-readings", "gauge-temp", "gauge-hum"]]
41
+ },
42
+ {
43
+ "id": "fmt-readings",
44
+ "type": "function",
45
+ "name": "format",
46
+ "func": "const p = msg.payload;\nmsg.payload = p.temperature_c.toFixed(1) + ' °C / ' + p.humidity_pct.toFixed(1) + ' %RH';\nreturn msg;",
47
+ "outputs": 1,
48
+ "noerr": 0,
49
+ "initialize": "",
50
+ "finalize": "",
51
+ "libs": [],
52
+ "z": "tab-aht20-demo",
53
+ "x": 480,
54
+ "y": 160,
55
+ "wires": [["dbg-readings"]]
56
+ },
57
+ {
58
+ "id": "dbg-readings",
59
+ "type": "debug",
60
+ "name": "",
61
+ "active": true,
62
+ "tosidebar": true,
63
+ "console": false,
64
+ "tostatus": true,
65
+ "complete": "payload",
66
+ "targetType": "msg",
67
+ "statusVal": "payload",
68
+ "statusType": "auto",
69
+ "z": "tab-aht20-demo",
70
+ "x": 650,
71
+ "y": 160,
72
+ "wires": []
73
+ },
74
+ {
75
+ "id": "gauge-temp",
76
+ "type": "ui_gauge",
77
+ "name": "Temperature",
78
+ "group": "grp-aht20",
79
+ "order": 1,
80
+ "width": 6,
81
+ "height": 4,
82
+ "gtype": "gage",
83
+ "title": "Temperature",
84
+ "label": "°C",
85
+ "format": "{{value | number:1}}",
86
+ "min": -10,
87
+ "max": 50,
88
+ "z": "tab-aht20-demo",
89
+ "x": 490,
90
+ "y": 220,
91
+ "wires": []
92
+ },
93
+ {
94
+ "id": "gauge-hum",
95
+ "type": "ui_gauge",
96
+ "name": "Humidity",
97
+ "group": "grp-aht20",
98
+ "order": 2,
99
+ "width": 6,
100
+ "height": 4,
101
+ "gtype": "gage",
102
+ "title": "Humidity",
103
+ "label": "%RH",
104
+ "format": "{{value | number:1}}",
105
+ "min": 0,
106
+ "max": 100,
107
+ "z": "tab-aht20-demo",
108
+ "x": 480,
109
+ "y": 280,
110
+ "wires": []
111
+ },
112
+ {
113
+ "id": "grp-aht20",
114
+ "type": "ui_group",
115
+ "name": "AHT20",
116
+ "tab": "tab-aht20-demo",
117
+ "order": 1,
118
+ "disp": true,
119
+ "width": 12
120
+ }
121
+ ]
@@ -0,0 +1,84 @@
1
+ [
2
+ {
3
+ "id": "am2320-tab",
4
+ "type": "tab",
5
+ "label": "AM2320 humidity logger",
6
+ "disabled": false,
7
+ "info": "Reads temperature and relative humidity from an AM2320 every 5 s and formats them. The sensor returns the previous measurement on every read and needs at least 2 s between transactions; each response is CRC-16 checked."
8
+ },
9
+ {
10
+ "id": "am2320-inject",
11
+ "type": "inject",
12
+ "z": "am2320-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
+ "am2320-node"
30
+ ]
31
+ ]
32
+ },
33
+ {
34
+ "id": "am2320-node",
35
+ "type": "periph-am2320",
36
+ "z": "am2320-tab",
37
+ "name": "AM2320",
38
+ "bus": "1",
39
+ "address": "0x5C",
40
+ "x": 380,
41
+ "y": 160,
42
+ "wires": [
43
+ [
44
+ "am2320-format"
45
+ ]
46
+ ]
47
+ },
48
+ {
49
+ "id": "am2320-format",
50
+ "type": "function",
51
+ "z": "am2320-tab",
52
+ "name": "Format",
53
+ "func": "msg.payload = msg.payload.temperature_c.toFixed(1) + ' °C / ' + msg.payload.humidity_pct.toFixed(1) + ' %RH';\nreturn msg;",
54
+ "outputs": 1,
55
+ "noerr": 0,
56
+ "initialize": "",
57
+ "finalize": "",
58
+ "libs": [],
59
+ "x": 600,
60
+ "y": 160,
61
+ "wires": [
62
+ [
63
+ "am2320-debug"
64
+ ]
65
+ ]
66
+ },
67
+ {
68
+ "id": "am2320-debug",
69
+ "type": "debug",
70
+ "z": "am2320-tab",
71
+ "name": "Reading",
72
+ "active": true,
73
+ "tosidebar": true,
74
+ "console": false,
75
+ "tostatus": false,
76
+ "complete": "payload",
77
+ "targetType": "msg",
78
+ "statusVal": "",
79
+ "statusType": "auto",
80
+ "x": 800,
81
+ "y": 160,
82
+ "wires": []
83
+ }
84
+ ]
@@ -0,0 +1,75 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('aht10-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '38', required: true }
9
+ },
10
+ label: function() {
11
+ return this.name || ('AHT10 @ 0x' + this.address + ' (bus ' + this.bus + ')');
12
+ }
13
+ });
14
+ </script>
15
+
16
+ <script type="text/html" data-template-name="aht10-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="AHT10">
20
+ </div>
21
+ <div class="form-row">
22
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
23
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-config-input-address">Address (hex)</label>
27
+ <input type="text" id="node-config-input-address" placeholder="38" style="width:80px"> &nbsp;default: 38 (0x38)
28
+ </div>
29
+ </script>
30
+
31
+ <!-- Read node: trigger → measurements -->
32
+ <script type="text/javascript">
33
+ RED.nodes.registerType('aht10', {
34
+ category: 'Peripheral',
35
+ color: '#C084FC',
36
+ defaults: {
37
+ name: { value: '' },
38
+ device: { value: '', type: 'aht10-device', required: true }
39
+ },
40
+ inputs: 1,
41
+ outputs: 1,
42
+ icon: 'font-awesome/fa-thermometer-half',
43
+ label: function() { return this.name || 'AHT10'; },
44
+ paletteLabel: 'AHT10'
45
+ });
46
+ </script>
47
+
48
+ <script type="text/html" data-template-name="aht10">
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="AHT10">
56
+ </div>
57
+ </script>
58
+
59
+ <script type="text/html" data-help-name="aht10">
60
+ <p>Reads temperature and humidity from an AHT10 environmental sensor over I²C.</p>
61
+ <p>Any input message triggers a measurement. The device is configured via an <b>aht10-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_pct <span class="property-type">number</span></dt>
68
+ <dd>Relative humidity in percent.</dd>
69
+ </dl>
70
+
71
+ <h3>Details</h3>
72
+ <p>Configure the I²C bus number and the chip's fixed address (default <code>0x38</code>)
73
+ in the device config node. Only one AHT10
74
+ can be on a single I²C bus.</p>
75
+ </script>
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { AHT10Full } = require('periph/src/chips/environmental/aht10');
6
+
7
+ function AHT10DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
12
+ node.driver = new AHT10Full(connection);
13
+ node.connection = connection;
14
+ } catch (e) {
15
+ node.error('AHT10 init failed: ' + e.message);
16
+ }
17
+ node.on('close', function() {
18
+ if (node.connection) node.connection.close();
19
+ });
20
+ }
21
+ RED.nodes.registerType('aht10-device', AHT10DeviceNode);
22
+
23
+ function AHT10ReadNode(config) {
24
+ RED.nodes.createNode(this, config);
25
+ const node = this;
26
+ node.device = RED.nodes.getNode(config.device);
27
+
28
+ node.on('input', async function(msg, send, done) {
29
+ if (!node.device || !node.device.driver) {
30
+ node.error('No AHT10 device configured', msg);
31
+ done();
32
+ return;
33
+ }
34
+ try {
35
+ const d = node.device.driver;
36
+ const r = await d.read();
37
+ msg.payload = {
38
+ temperature_c: r.temperature_c,
39
+ humidity_pct: r.humidity_pct
40
+ };
41
+ send(msg);
42
+ done();
43
+ } catch (e) {
44
+ done(e);
45
+ }
46
+ });
47
+ }
48
+ RED.nodes.registerType('aht10', AHT10ReadNode);
49
+ };
@@ -0,0 +1,75 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('aht20-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '38', required: true }
9
+ },
10
+ label: function() {
11
+ return this.name || ('AHT20 @ 0x' + this.address + ' (bus ' + this.bus + ')');
12
+ }
13
+ });
14
+ </script>
15
+
16
+ <script type="text/html" data-template-name="aht20-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="AHT20">
20
+ </div>
21
+ <div class="form-row">
22
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
23
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-config-input-address">Address (hex)</label>
27
+ <input type="text" id="node-config-input-address" placeholder="38" style="width:80px"> &nbsp;default: 38 (0x38)
28
+ </div>
29
+ </script>
30
+
31
+ <!-- Read node: trigger → measurements -->
32
+ <script type="text/javascript">
33
+ RED.nodes.registerType('aht20', {
34
+ category: 'Peripheral',
35
+ color: '#C084FC',
36
+ defaults: {
37
+ name: { value: '' },
38
+ device: { value: '', type: 'aht20-device', required: true }
39
+ },
40
+ inputs: 1,
41
+ outputs: 1,
42
+ icon: 'font-awesome/fa-thermometer-half',
43
+ label: function() { return this.name || 'AHT20'; },
44
+ paletteLabel: 'AHT20'
45
+ });
46
+ </script>
47
+
48
+ <script type="text/html" data-template-name="aht20">
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="AHT20">
56
+ </div>
57
+ </script>
58
+
59
+ <script type="text/html" data-help-name="aht20">
60
+ <p>Reads temperature and humidity from an AHT20 environmental sensor over I²C.</p>
61
+ <p>Any input message triggers a measurement. The device is configured via an <b>aht20-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_pct <span class="property-type">number</span></dt>
68
+ <dd>Relative humidity in percent.</dd>
69
+ </dl>
70
+
71
+ <h3>Details</h3>
72
+ <p>Configure the I²C bus number and the chip's fixed address (default <code>0x38</code>)
73
+ in the device config node. Only one AHT20
74
+ can be on a single I²C bus.</p>
75
+ </script>
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { AHT20Full } = require('periph/src/chips/environmental/aht20');
6
+
7
+ function AHT20DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
12
+ node.driver = new AHT20Full(connection);
13
+ node.connection = connection;
14
+ } catch (e) {
15
+ node.error('AHT20 init failed: ' + e.message);
16
+ }
17
+ node.on('close', function() {
18
+ if (node.connection) node.connection.close();
19
+ });
20
+ }
21
+ RED.nodes.registerType('aht20-device', AHT20DeviceNode);
22
+
23
+ function AHT20ReadNode(config) {
24
+ RED.nodes.createNode(this, config);
25
+ const node = this;
26
+ node.device = RED.nodes.getNode(config.device);
27
+
28
+ node.on('input', async function(msg, send, done) {
29
+ if (!node.device || !node.device.driver) {
30
+ node.error('No AHT20 device configured', msg);
31
+ done();
32
+ return;
33
+ }
34
+ try {
35
+ const d = node.device.driver;
36
+ const r = await d.read();
37
+ msg.payload = {
38
+ temperature_c: r.temperature_c,
39
+ humidity_pct: r.humidity_pct
40
+ };
41
+ send(msg);
42
+ done();
43
+ } catch (e) {
44
+ done(e);
45
+ }
46
+ });
47
+ }
48
+ RED.nodes.registerType('aht20', AHT20ReadNode);
49
+ };
@@ -0,0 +1,53 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-am2320', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x5C' }
9
+ },
10
+ inputs: 1,
11
+ outputs: 1,
12
+ icon: 'bridge.svg',
13
+ label: function() {
14
+ return this.name || ('AM2320 @ ' + this.address + ' (bus ' + this.bus + ')');
15
+ }
16
+ });
17
+ </script>
18
+
19
+ <script type="text/html" data-template-name="periph-am2320">
20
+ <div class="form-row">
21
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
22
+ <input type="text" id="node-input-name" placeholder="AM2320">
23
+ </div>
24
+ <div class="form-row">
25
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
26
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N, standard mode)
27
+ </div>
28
+ <div class="form-row">
29
+ <label for="node-input-address"><i class="fa fa-microchip"></i> I²C address</label>
30
+ <input type="text" id="node-input-address" style="width:80px" placeholder="0x5C"> &nbsp;(fixed, 0x5C)
31
+ </div>
32
+ </script>
33
+
34
+ <script type="text/html" data-help-name="periph-am2320">
35
+ <p>Reads temperature and relative humidity from an Aosong AM2320 over I²C (fixed address 0x5C). The sensor
36
+ sleeps between transactions and returns the result of the <em>previous</em> measurement; the node keeps
37
+ transactions at least 2 s apart, so a message arriving earlier is answered after the remaining delay.
38
+ Every response is CRC-16 checked.</p>
39
+ <h3>Inputs</h3>
40
+ <dl class="message-properties">
41
+ <dt>payload <span class="property-type">any</span></dt>
42
+ <dd>Any incoming message triggers one reading.</dd>
43
+ </dl>
44
+ <h3>Outputs</h3>
45
+ <dl class="message-properties">
46
+ <dt>payload.temperature_c <span class="property-type">number</span></dt>
47
+ <dd>Temperature in °C (−40 to 125).</dd>
48
+ <dt>payload.humidity_pct <span class="property-type">number</span></dt>
49
+ <dd>Relative humidity in %RH (0 to 99.9).</dd>
50
+ </dl>
51
+ <h3>Configuration</h3>
52
+ <p>I²C bus number and I²C address (0x5C). The bus must run at 100 kHz or less.</p>
53
+ </script>
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { AM2320Full } = require('periph/src/chips/environmental/am2320');
6
+
7
+ function AM2320Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const address = parseInt(config.address, 16) || 0x5C;
12
+ const connection = new I2CConnection(parseInt(config.bus), address);
13
+ node.connection = connection;
14
+ node.driver = new AM2320Full(connection);
15
+ } catch (e) {
16
+ node.error('AM2320 init failed: ' + e.message);
17
+ }
18
+
19
+ // Messages are handled one at a time; the driver itself waits the >= 2 s between transactions.
20
+ let queue = Promise.resolve();
21
+ node.on('input', function(msg, send, done) {
22
+ if (!node.driver) {
23
+ node.error('AM2320 not initialised', msg);
24
+ done();
25
+ return;
26
+ }
27
+ queue = queue.then(async () => {
28
+ try {
29
+ msg.payload = await node.driver.read();
30
+ send(msg);
31
+ done();
32
+ } catch (e) {
33
+ done(e);
34
+ }
35
+ });
36
+ });
37
+
38
+ node.on('close', function() {
39
+ if (node.connection) node.connection.close();
40
+ });
41
+ }
42
+ RED.nodes.registerType('periph-am2320', AM2320Node);
43
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-environmental",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Node-RED nodes for environmental sensor chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -13,8 +13,11 @@
13
13
  "main": "index.js",
14
14
  "node-red": {
15
15
  "nodes": {
16
+ "aht10": "nodes/aht10/aht10.js",
17
+ "aht20": "nodes/aht20/aht20.js",
16
18
  "aht21": "nodes/aht21/aht21.js",
17
19
  "am2315": "nodes/am2315/am2315.js",
20
+ "am2320": "nodes/am2320/am2320.js",
18
21
  "bme280": "nodes/bme280/bme280.js",
19
22
  "bme680": "nodes/bme680/bme680.js"
20
23
  }