node-red-contrib-periph-gas 1.5.4 → 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 +6 -2
- package/examples/ccs811/demo.json +136 -0
- package/examples/rrh46410/demo.json +136 -0
- package/nodes/ccs811/ccs811.html +105 -0
- package/nodes/ccs811/ccs811.js +59 -0
- package/nodes/rrh46410/rrh46410.html +108 -0
- package/nodes/rrh46410/rrh46410.js +61 -0
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# node-red-contrib-periph-gas
|
|
2
2
|
|
|
3
|
-
Node-RED nodes for gas sensor chips: ENS160 — part of the [Periph](https://github.com/tuhde/Periph) library.
|
|
3
|
+
Node-RED nodes for gas sensor chips: CCS811, ENS160, RRH46410 — part of the [Periph](https://github.com/tuhde/Periph) library.
|
|
4
4
|
|
|
5
|
-
**Supported chips (
|
|
5
|
+
**Supported chips (3):** CCS811, ENS160, RRH46410.
|
|
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-gas/examples).
|
|
8
8
|
|
|
@@ -20,8 +20,12 @@ npm install node-red-contrib-periph-gas
|
|
|
20
20
|
|
|
21
21
|
| Node | Kind | Description |
|
|
22
22
|
|------|------|-------------|
|
|
23
|
+
| `ccs811-device` | config | I²C bus and address for a CCS811 |
|
|
24
|
+
| `ccs811` | input | Reads equivalent CO₂ (eCO₂) and total VOC (TVOC) from a ScioSense CCS811 over I²C (address 0x5A or 0x5B), one sample per message. |
|
|
23
25
|
| `ens160-device` | config | Bus configuration for an ENS160 |
|
|
24
26
|
| `ens160` | input | Reads air quality (AQI, TVOC, eCO2) from an ENS160 digital multi-gas sensor. |
|
|
27
|
+
| `rrh46410-device` | config | Bus configuration for a RRH46410 |
|
|
28
|
+
| `rrh46410` | input | Reads the indoor air quality (IAQ index, TVOC, ethanol equivalent, eCO₂ and relative IAQ) from a Renesas RRH46410 gas sensor module over I²C (address 0x38), one result per message. |
|
|
25
29
|
|
|
26
30
|
## Links
|
|
27
31
|
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "ccs811-tab",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "CCS811 air quality",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Indoor air-quality monitor with a CCS811. An inject node fires every 5 s and asks for the latest eCO2 and TVOC sample (the node waits for the next one if none is ready). A function node classifies the eCO2 level (good below 1000 ppm, fair up to 1500 ppm, poor above 1500 ppm) and feeds a dashboard gauge; the debug node shows the full reading in ppm and ppb. Feed msg.humidity and msg.temperature from another sensor to improve the compensation."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "ccs811-inject",
|
|
11
|
+
"type": "inject",
|
|
12
|
+
"z": "ccs811-tab",
|
|
13
|
+
"name": "every 5 s",
|
|
14
|
+
"props": [
|
|
15
|
+
{
|
|
16
|
+
"p": "payload"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"repeat": "5",
|
|
20
|
+
"crontab": "",
|
|
21
|
+
"once": true,
|
|
22
|
+
"onceDelay": 1,
|
|
23
|
+
"topic": "",
|
|
24
|
+
"payloadType": "date",
|
|
25
|
+
"x": 150,
|
|
26
|
+
"y": 160,
|
|
27
|
+
"wires": [
|
|
28
|
+
[
|
|
29
|
+
"ccs811-node"
|
|
30
|
+
]
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "ccs811-device-1",
|
|
35
|
+
"type": "ccs811-device",
|
|
36
|
+
"name": "CCS811",
|
|
37
|
+
"bus": "1",
|
|
38
|
+
"address": "0x5A",
|
|
39
|
+
"mode": "1"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "ccs811-node",
|
|
43
|
+
"type": "ccs811",
|
|
44
|
+
"z": "ccs811-tab",
|
|
45
|
+
"name": "CCS811",
|
|
46
|
+
"device": "ccs811-device-1",
|
|
47
|
+
"x": 340,
|
|
48
|
+
"y": 160,
|
|
49
|
+
"wires": [
|
|
50
|
+
[
|
|
51
|
+
"ccs811-classify"
|
|
52
|
+
]
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"id": "ccs811-classify",
|
|
57
|
+
"type": "function",
|
|
58
|
+
"z": "ccs811-tab",
|
|
59
|
+
"name": "Classify eCO2",
|
|
60
|
+
"func": "const eco2 = msg.payload.eco2_ppm;\nmsg.payload.quality = eco2 < 1000 ? 'good' : (eco2 <= 1500 ? 'fair' : 'poor');\nreturn [msg, { payload: eco2 }];",
|
|
61
|
+
"outputs": 2,
|
|
62
|
+
"noerr": 0,
|
|
63
|
+
"initialize": "",
|
|
64
|
+
"finalize": "",
|
|
65
|
+
"libs": [],
|
|
66
|
+
"x": 540,
|
|
67
|
+
"y": 160,
|
|
68
|
+
"wires": [
|
|
69
|
+
[
|
|
70
|
+
"ccs811-debug"
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
"ccs811-gauge"
|
|
74
|
+
]
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"id": "ccs811-debug",
|
|
79
|
+
"type": "debug",
|
|
80
|
+
"z": "ccs811-tab",
|
|
81
|
+
"name": "Reading",
|
|
82
|
+
"active": true,
|
|
83
|
+
"tosidebar": true,
|
|
84
|
+
"console": false,
|
|
85
|
+
"tostatus": false,
|
|
86
|
+
"complete": "payload",
|
|
87
|
+
"targetType": "msg",
|
|
88
|
+
"statusVal": "",
|
|
89
|
+
"statusType": "auto",
|
|
90
|
+
"x": 750,
|
|
91
|
+
"y": 120,
|
|
92
|
+
"wires": []
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"id": "ccs811-gauge",
|
|
96
|
+
"type": "ui_gauge",
|
|
97
|
+
"z": "ccs811-tab",
|
|
98
|
+
"name": "eCO2 gauge",
|
|
99
|
+
"group": "ccs811-group-1",
|
|
100
|
+
"order": 1,
|
|
101
|
+
"width": 6,
|
|
102
|
+
"height": 4,
|
|
103
|
+
"gtype": "gage",
|
|
104
|
+
"title": "eCO2",
|
|
105
|
+
"label": "ppm",
|
|
106
|
+
"format": "{{value}}",
|
|
107
|
+
"min": 400,
|
|
108
|
+
"max": 2500,
|
|
109
|
+
"colors": [
|
|
110
|
+
"#00b500",
|
|
111
|
+
"#e6e600",
|
|
112
|
+
"#ca3838"
|
|
113
|
+
],
|
|
114
|
+
"seg1": "1000",
|
|
115
|
+
"seg2": "1500",
|
|
116
|
+
"x": 750,
|
|
117
|
+
"y": 200,
|
|
118
|
+
"wires": []
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"id": "ccs811-group-1",
|
|
122
|
+
"type": "ui_group",
|
|
123
|
+
"name": "CCS811 Air Quality",
|
|
124
|
+
"tab": "ccs811-ui-tab-1",
|
|
125
|
+
"order": 1,
|
|
126
|
+
"disp": true,
|
|
127
|
+
"width": 6
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"id": "ccs811-ui-tab-1",
|
|
131
|
+
"type": "ui_tab",
|
|
132
|
+
"name": "CCS811 Demo",
|
|
133
|
+
"icon": "dashboard",
|
|
134
|
+
"order": 1
|
|
135
|
+
}
|
|
136
|
+
]
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "rrh46410-tab",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "RRH46410 air quality",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Indoor air-quality monitor with a Renesas RRH46410. An inject node fires every 3 s (the IAQ 2nd Gen sample period) and asks for the latest sample. A function node maps the IAQ index to the UBA rating (very good below 2.0, good, medium, poor, bad from 5.0) and feeds a dashboard gauge; the debug node shows IAQ, TVOC in mg/m3, ethanol equivalent and eCO2 in ppm, relative IAQ and whether the 5-minute warm-up is over. Feed msg.humidity from a humidity sensor to improve the compensation."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "rrh46410-inject",
|
|
11
|
+
"type": "inject",
|
|
12
|
+
"z": "rrh46410-tab",
|
|
13
|
+
"name": "every 3 s",
|
|
14
|
+
"props": [
|
|
15
|
+
{
|
|
16
|
+
"p": "payload"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"repeat": "3",
|
|
20
|
+
"crontab": "",
|
|
21
|
+
"once": true,
|
|
22
|
+
"onceDelay": 1,
|
|
23
|
+
"topic": "",
|
|
24
|
+
"payloadType": "date",
|
|
25
|
+
"x": 150,
|
|
26
|
+
"y": 160,
|
|
27
|
+
"wires": [
|
|
28
|
+
[
|
|
29
|
+
"rrh46410-node"
|
|
30
|
+
]
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "rrh46410-device-1",
|
|
35
|
+
"type": "rrh46410-device",
|
|
36
|
+
"name": "RRH46410",
|
|
37
|
+
"bus": "1",
|
|
38
|
+
"mode": "1",
|
|
39
|
+
"humidity": "50"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "rrh46410-node",
|
|
43
|
+
"type": "rrh46410",
|
|
44
|
+
"z": "rrh46410-tab",
|
|
45
|
+
"name": "RRH46410",
|
|
46
|
+
"device": "rrh46410-device-1",
|
|
47
|
+
"x": 340,
|
|
48
|
+
"y": 160,
|
|
49
|
+
"wires": [
|
|
50
|
+
[
|
|
51
|
+
"rrh46410-label"
|
|
52
|
+
]
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"id": "rrh46410-label",
|
|
57
|
+
"type": "function",
|
|
58
|
+
"z": "rrh46410-tab",
|
|
59
|
+
"name": "IAQ rating",
|
|
60
|
+
"func": "const iaq = msg.payload.iaq;\nmsg.payload.rating = iaq < 2 ? 'very good' : iaq < 3 ? 'good' : iaq < 4 ? 'medium' : iaq < 5 ? 'poor' : 'bad';\nreturn [msg, { payload: iaq }];",
|
|
61
|
+
"outputs": 2,
|
|
62
|
+
"noerr": 0,
|
|
63
|
+
"initialize": "",
|
|
64
|
+
"finalize": "",
|
|
65
|
+
"libs": [],
|
|
66
|
+
"x": 540,
|
|
67
|
+
"y": 160,
|
|
68
|
+
"wires": [
|
|
69
|
+
[
|
|
70
|
+
"rrh46410-debug"
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
"rrh46410-gauge"
|
|
74
|
+
]
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"id": "rrh46410-debug",
|
|
79
|
+
"type": "debug",
|
|
80
|
+
"z": "rrh46410-tab",
|
|
81
|
+
"name": "Reading",
|
|
82
|
+
"active": true,
|
|
83
|
+
"tosidebar": true,
|
|
84
|
+
"console": false,
|
|
85
|
+
"tostatus": false,
|
|
86
|
+
"complete": "payload",
|
|
87
|
+
"targetType": "msg",
|
|
88
|
+
"statusVal": "",
|
|
89
|
+
"statusType": "auto",
|
|
90
|
+
"x": 750,
|
|
91
|
+
"y": 120,
|
|
92
|
+
"wires": []
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"id": "rrh46410-gauge",
|
|
96
|
+
"type": "ui_gauge",
|
|
97
|
+
"z": "rrh46410-tab",
|
|
98
|
+
"name": "IAQ gauge",
|
|
99
|
+
"group": "rrh46410-group-1",
|
|
100
|
+
"order": 1,
|
|
101
|
+
"width": 6,
|
|
102
|
+
"height": 4,
|
|
103
|
+
"gtype": "gage",
|
|
104
|
+
"title": "IAQ",
|
|
105
|
+
"label": "UBA level",
|
|
106
|
+
"format": "{{value}}",
|
|
107
|
+
"min": 1,
|
|
108
|
+
"max": 5,
|
|
109
|
+
"colors": [
|
|
110
|
+
"#00b500",
|
|
111
|
+
"#e6e600",
|
|
112
|
+
"#ca3838"
|
|
113
|
+
],
|
|
114
|
+
"seg1": "3",
|
|
115
|
+
"seg2": "4",
|
|
116
|
+
"x": 750,
|
|
117
|
+
"y": 200,
|
|
118
|
+
"wires": []
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
"id": "rrh46410-group-1",
|
|
122
|
+
"type": "ui_group",
|
|
123
|
+
"name": "RRH46410 Air Quality",
|
|
124
|
+
"tab": "rrh46410-ui-tab-1",
|
|
125
|
+
"order": 1,
|
|
126
|
+
"disp": true,
|
|
127
|
+
"width": 6
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"id": "rrh46410-ui-tab-1",
|
|
131
|
+
"type": "ui_tab",
|
|
132
|
+
"name": "RRH46410 Demo",
|
|
133
|
+
"icon": "dashboard",
|
|
134
|
+
"order": 1
|
|
135
|
+
}
|
|
136
|
+
]
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('ccs811-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '0x5A' },
|
|
9
|
+
mode: { value: '1' }
|
|
10
|
+
},
|
|
11
|
+
label: function() {
|
|
12
|
+
return this.name || ('CCS811 @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script type="text/html" data-template-name="ccs811-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="CCS811">
|
|
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"> (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
|
+
<select id="node-config-input-address" style="width:120px">
|
|
29
|
+
<option value="0x5A" selected>0x5A (ADDR low)</option>
|
|
30
|
+
<option value="0x5B">0x5B (ADDR high)</option>
|
|
31
|
+
</select>
|
|
32
|
+
</div>
|
|
33
|
+
<div class="form-row">
|
|
34
|
+
<label for="node-config-input-mode"><i class="fa fa-cog"></i> Drive mode</label>
|
|
35
|
+
<select id="node-config-input-mode" style="width:220px">
|
|
36
|
+
<option value="1" selected>1: every 1 s (constant power)</option>
|
|
37
|
+
<option value="2">2: every 10 s (pulse heating)</option>
|
|
38
|
+
<option value="3">3: every 60 s (low-power pulse)</option>
|
|
39
|
+
</select>
|
|
40
|
+
</div>
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<!-- Read node -->
|
|
44
|
+
<script type="text/javascript">
|
|
45
|
+
RED.nodes.registerType('ccs811', {
|
|
46
|
+
category: 'Peripheral',
|
|
47
|
+
color: '#C084FC',
|
|
48
|
+
defaults: {
|
|
49
|
+
name: { value: '' },
|
|
50
|
+
device: { value: '', type: 'ccs811-device', required: true }
|
|
51
|
+
},
|
|
52
|
+
inputs: 1,
|
|
53
|
+
outputs: 1,
|
|
54
|
+
icon: 'bridge.svg',
|
|
55
|
+
label: function() { return this.name || 'CCS811'; },
|
|
56
|
+
paletteLabel: 'CCS811'
|
|
57
|
+
});
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<script type="text/html" data-template-name="ccs811">
|
|
61
|
+
<div class="form-row">
|
|
62
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
63
|
+
<input type="text" id="node-input-name" placeholder="CCS811">
|
|
64
|
+
</div>
|
|
65
|
+
<div class="form-row">
|
|
66
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
67
|
+
<input type="text" id="node-input-device">
|
|
68
|
+
</div>
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<script type="text/html" data-help-name="ccs811">
|
|
72
|
+
<p>Reads equivalent CO₂ (eCO₂) and total VOC (TVOC) from a ScioSense CCS811 over I²C
|
|
73
|
+
(address 0x5A or 0x5B), one sample per message.</p>
|
|
74
|
+
<h3>Inputs</h3>
|
|
75
|
+
<dl class="message-properties">
|
|
76
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
77
|
+
<dd>Any incoming message returns the next sample; if none is ready yet, the node waits for it.</dd>
|
|
78
|
+
<dt class="optional">humidity <span class="property-type">number</span></dt>
|
|
79
|
+
<dd>Relative humidity in % (0–100). With <code>msg.temperature</code>, written as environment data
|
|
80
|
+
before the read to improve the compensation.</dd>
|
|
81
|
+
<dt class="optional">temperature <span class="property-type">number</span></dt>
|
|
82
|
+
<dd>Ambient temperature in °C (-25 to 102), used together with <code>msg.humidity</code>.</dd>
|
|
83
|
+
</dl>
|
|
84
|
+
<h3>Outputs</h3>
|
|
85
|
+
<dl class="message-properties">
|
|
86
|
+
<dt>payload.eco2_ppm <span class="property-type">number</span></dt>
|
|
87
|
+
<dd>Equivalent CO₂ in ppm (400–8192), estimated from the VOC level.</dd>
|
|
88
|
+
<dt>payload.tvoc_ppb <span class="property-type">number</span></dt>
|
|
89
|
+
<dd>Total volatile organic compounds in ppb (0–1187).</dd>
|
|
90
|
+
</dl>
|
|
91
|
+
<h3>Configuration</h3>
|
|
92
|
+
<dl class="message-properties">
|
|
93
|
+
<dt>I²C bus <span class="property-type">number</span></dt>
|
|
94
|
+
<dd>Linux bus number N of <code>/dev/i2c-N</code>. The chip stretches the clock; lower the bus
|
|
95
|
+
speed if the host does not support clock stretching.</dd>
|
|
96
|
+
<dt>I²C address <span class="property-type">0x5A | 0x5B</span></dt>
|
|
97
|
+
<dd>0x5A with ADDR low (default), 0x5B with ADDR high.</dd>
|
|
98
|
+
<dt>Drive mode <span class="property-type">1 | 2 | 3</span></dt>
|
|
99
|
+
<dd>Sample interval: 1 s, 10 s or 60 s. Slower modes use less power; with mode 2 or 3 a message
|
|
100
|
+
can wait up to one interval for its sample.</dd>
|
|
101
|
+
</dl>
|
|
102
|
+
<h3>Details</h3>
|
|
103
|
+
<p>The node starts the chip's application firmware at deploy. Tie nWAKE low. Values settle about
|
|
104
|
+
20 minutes after power-up; a new sensor needs a 48 h burn-in.</p>
|
|
105
|
+
</script>
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { CCS811Full } = require('periph/src/chips/gas/ccs811');
|
|
6
|
+
|
|
7
|
+
function CCS811DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const address = parseInt(config.address, 16) || 0x5A;
|
|
12
|
+
const connection = new I2CConnection(parseInt(config.bus), address);
|
|
13
|
+
node.connection = connection;
|
|
14
|
+
node.driver = new CCS811Full(connection);
|
|
15
|
+
node.ready = (async () => {
|
|
16
|
+
await node.driver.init();
|
|
17
|
+
const mode = parseInt(config.mode);
|
|
18
|
+
if (!isNaN(mode) && mode !== 1) await node.driver.setMode(mode);
|
|
19
|
+
})();
|
|
20
|
+
node.ready.catch((e) => {
|
|
21
|
+
node.error('CCS811 init failed: ' + e.message);
|
|
22
|
+
});
|
|
23
|
+
} catch (e) {
|
|
24
|
+
node.error('CCS811 init failed: ' + e.message);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
node.on('close', function() {
|
|
28
|
+
if (node.connection) node.connection.close();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
RED.nodes.registerType('ccs811-device', CCS811DeviceNode);
|
|
32
|
+
|
|
33
|
+
function CCS811ReadNode(config) {
|
|
34
|
+
RED.nodes.createNode(this, config);
|
|
35
|
+
const node = this;
|
|
36
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
37
|
+
|
|
38
|
+
node.on('input', async function(msg, send, done) {
|
|
39
|
+
if (!deviceNode.driver) {
|
|
40
|
+
node.error('CCS811 not initialised', msg);
|
|
41
|
+
done();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
await deviceNode.ready;
|
|
46
|
+
if (typeof msg.humidity === 'number' && typeof msg.temperature === 'number') {
|
|
47
|
+
await deviceNode.driver.setEnvironment(msg.humidity, msg.temperature);
|
|
48
|
+
}
|
|
49
|
+
const { eco2_ppm, tvoc_ppb } = await deviceNode.driver.read();
|
|
50
|
+
msg.payload = { eco2_ppm, tvoc_ppb };
|
|
51
|
+
send(msg);
|
|
52
|
+
done();
|
|
53
|
+
} catch (e) {
|
|
54
|
+
done(e);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
RED.nodes.registerType('ccs811', CCS811ReadNode);
|
|
59
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('rrh46410-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
mode: { value: '1' },
|
|
9
|
+
humidity: { value: '50', validate: RED.validators.number() }
|
|
10
|
+
},
|
|
11
|
+
label: function() {
|
|
12
|
+
return this.name || ('RRH46410 @ 0x38 (bus ' + this.bus + ')');
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script type="text/html" data-template-name="rrh46410-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="RRH46410">
|
|
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"> (Linux /dev/i2c-N, address 0x38)
|
|
25
|
+
</div>
|
|
26
|
+
<div class="form-row">
|
|
27
|
+
<label for="node-config-input-mode"><i class="fa fa-cog"></i> Operation mode</label>
|
|
28
|
+
<select id="node-config-input-mode" style="width:260px">
|
|
29
|
+
<option value="1" selected>IAQ 2nd Gen (every 3 s)</option>
|
|
30
|
+
<option value="2">ULP (every 90 s)</option>
|
|
31
|
+
<option value="5">PBAQ (every 5 s, TVOC and ethanol)</option>
|
|
32
|
+
</select>
|
|
33
|
+
</div>
|
|
34
|
+
<div class="form-row">
|
|
35
|
+
<label for="node-config-input-humidity"><i class="fa fa-tint"></i> Humidity (%RH)</label>
|
|
36
|
+
<input type="number" id="node-config-input-humidity" min="0" max="100" style="width:80px">
|
|
37
|
+
</div>
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<!-- Read node -->
|
|
41
|
+
<script type="text/javascript">
|
|
42
|
+
RED.nodes.registerType('rrh46410', {
|
|
43
|
+
category: 'Peripheral',
|
|
44
|
+
color: '#C084FC',
|
|
45
|
+
defaults: {
|
|
46
|
+
name: { value: '' },
|
|
47
|
+
device: { value: '', type: 'rrh46410-device', required: true }
|
|
48
|
+
},
|
|
49
|
+
inputs: 1,
|
|
50
|
+
outputs: 1,
|
|
51
|
+
icon: 'bridge.svg',
|
|
52
|
+
label: function() { return this.name || 'RRH46410'; },
|
|
53
|
+
paletteLabel: 'RRH46410'
|
|
54
|
+
});
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<script type="text/html" data-template-name="rrh46410">
|
|
58
|
+
<div class="form-row">
|
|
59
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
60
|
+
<input type="text" id="node-input-name" placeholder="RRH46410">
|
|
61
|
+
</div>
|
|
62
|
+
<div class="form-row">
|
|
63
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
64
|
+
<input type="text" id="node-input-device">
|
|
65
|
+
</div>
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<script type="text/html" data-help-name="rrh46410">
|
|
69
|
+
<p>Reads the indoor air quality (IAQ index, TVOC, ethanol equivalent, eCO₂ and relative IAQ) from a
|
|
70
|
+
Renesas RRH46410 gas sensor module over I²C (address 0x38), one result per message.</p>
|
|
71
|
+
<h3>Inputs</h3>
|
|
72
|
+
<dl class="message-properties">
|
|
73
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
74
|
+
<dd>Any incoming message returns the latest sample; before the first sample of the mode the node
|
|
75
|
+
waits for it.</dd>
|
|
76
|
+
<dt class="optional">humidity <span class="property-type">number</span></dt>
|
|
77
|
+
<dd>Ambient relative humidity in % (0–100), sent to the module for compensation before the read.</dd>
|
|
78
|
+
</dl>
|
|
79
|
+
<h3>Outputs</h3>
|
|
80
|
+
<dl class="message-properties">
|
|
81
|
+
<dt>payload.iaq <span class="property-type">number</span></dt>
|
|
82
|
+
<dd>IAQ index, UBA level 1.0 (very good) to 5.0 (bad). Absent in PBAQ mode.</dd>
|
|
83
|
+
<dt>payload.tvoc_mg_m3 <span class="property-type">number</span></dt>
|
|
84
|
+
<dd>Total volatile organic compounds in mg/m³.</dd>
|
|
85
|
+
<dt>payload.etoh_ppm <span class="property-type">number</span></dt>
|
|
86
|
+
<dd>Ethanol equivalent in ppm.</dd>
|
|
87
|
+
<dt>payload.eco2_ppm <span class="property-type">number</span></dt>
|
|
88
|
+
<dd>Estimated CO₂ in ppm. Absent in PBAQ mode.</dd>
|
|
89
|
+
<dt>payload.relative_iaq <span class="property-type">number</span></dt>
|
|
90
|
+
<dd>Relative IAQ. Absent in PBAQ mode.</dd>
|
|
91
|
+
<dt>payload.warmed_up <span class="property-type">boolean</span></dt>
|
|
92
|
+
<dd>False during the warm-up (100 samples ≈ 5 min in IAQ 2nd Gen mode), while the values stay fixed.</dd>
|
|
93
|
+
</dl>
|
|
94
|
+
<h3>Configuration</h3>
|
|
95
|
+
<dl class="message-properties">
|
|
96
|
+
<dt>I²C bus <span class="property-type">number</span></dt>
|
|
97
|
+
<dd>Linux bus number N of <code>/dev/i2c-N</code>. The address is fixed at 0x38. The module stretches
|
|
98
|
+
the clock; lower the bus speed if the host does not support clock stretching.</dd>
|
|
99
|
+
<dt>Operation mode <span class="property-type">1 | 2 | 5</span></dt>
|
|
100
|
+
<dd>IAQ 2nd Gen (sample every 3 s), ULP (every 90 s, 0.23 mW) or PBAQ (every 5 s, TVOC and ethanol
|
|
101
|
+
only).</dd>
|
|
102
|
+
<dt>Humidity <span class="property-type">number</span></dt>
|
|
103
|
+
<dd>Ambient relative humidity in % written at deploy (the module assumes 50 %RH).</dd>
|
|
104
|
+
</dl>
|
|
105
|
+
<h3>Details</h3>
|
|
106
|
+
<p>The node verifies the product ID (0x2310) and starts the selected mode at deploy. Each mode needs a
|
|
107
|
+
warm-up before its results are valid; 48 hours of continuous operation give the best stability.</p>
|
|
108
|
+
</script>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { RRH46410Full } = require('periph/src/chips/gas/rrh46410');
|
|
6
|
+
|
|
7
|
+
function RRH46410DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), 0x38);
|
|
12
|
+
node.connection = connection;
|
|
13
|
+
node.driver = new RRH46410Full(connection);
|
|
14
|
+
node.ready = (async () => {
|
|
15
|
+
await node.driver.init();
|
|
16
|
+
const humidity = parseFloat(config.humidity);
|
|
17
|
+
if (!isNaN(humidity) && humidity !== 50) await node.driver.setHumidity(humidity);
|
|
18
|
+
const mode = parseInt(config.mode);
|
|
19
|
+
if (!isNaN(mode) && mode !== RRH46410Full.MODE_IAQ_2ND_GEN) await node.driver.setMode(mode);
|
|
20
|
+
})();
|
|
21
|
+
node.ready.catch((e) => {
|
|
22
|
+
node.error('RRH46410 init failed: ' + e.message);
|
|
23
|
+
});
|
|
24
|
+
} catch (e) {
|
|
25
|
+
node.error('RRH46410 init failed: ' + e.message);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
node.on('close', function() {
|
|
29
|
+
if (node.connection) node.connection.close();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
RED.nodes.registerType('rrh46410-device', RRH46410DeviceNode);
|
|
33
|
+
|
|
34
|
+
function RRH46410ReadNode(config) {
|
|
35
|
+
RED.nodes.createNode(this, config);
|
|
36
|
+
const node = this;
|
|
37
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
38
|
+
|
|
39
|
+
node.on('input', async function(msg, send, done) {
|
|
40
|
+
if (!deviceNode.driver) {
|
|
41
|
+
node.error('RRH46410 not initialised', msg);
|
|
42
|
+
done();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
await deviceNode.ready;
|
|
47
|
+
const driver = deviceNode.driver;
|
|
48
|
+
if (typeof msg.humidity === 'number') await driver.setHumidity(msg.humidity);
|
|
49
|
+
let r = await driver.readResults();
|
|
50
|
+
if (r === null) r = await driver.read();
|
|
51
|
+
const { iaq, tvoc_mg_m3, etoh_ppm, eco2_ppm, relative_iaq, warmed_up } = r;
|
|
52
|
+
msg.payload = { iaq, tvoc_mg_m3, etoh_ppm, eco2_ppm, relative_iaq, warmed_up };
|
|
53
|
+
send(msg);
|
|
54
|
+
done();
|
|
55
|
+
} catch (e) {
|
|
56
|
+
done(e);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
RED.nodes.registerType('rrh46410', RRH46410ReadNode);
|
|
61
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-gas",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Node-RED nodes for gas sensor chips: ENS160",
|
|
3
|
+
"version": "1.6.0",
|
|
4
|
+
"description": "Node-RED nodes for gas sensor chips: CCS811, ENS160, RRH46410",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
7
7
|
"gas",
|
|
@@ -10,12 +10,16 @@
|
|
|
10
10
|
"sensor",
|
|
11
11
|
"peripheral",
|
|
12
12
|
"node-red-contrib",
|
|
13
|
-
"
|
|
13
|
+
"ccs811",
|
|
14
|
+
"ens160",
|
|
15
|
+
"rrh46410"
|
|
14
16
|
],
|
|
15
17
|
"node-red": {
|
|
16
18
|
"version": ">=3.0.0",
|
|
17
19
|
"nodes": {
|
|
18
|
-
"
|
|
20
|
+
"ccs811": "nodes/ccs811/ccs811.js",
|
|
21
|
+
"ens160": "nodes/ens160/ens160.js",
|
|
22
|
+
"rrh46410": "nodes/rrh46410/rrh46410.js"
|
|
19
23
|
}
|
|
20
24
|
},
|
|
21
25
|
"dependencies": {
|