node-red-contrib-periph-gas 1.0.1 → 1.1.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.
@@ -0,0 +1,91 @@
1
+ [
2
+ {
3
+ "id": "ens160-device-1",
4
+ "type": "ens160-device",
5
+ "name": "ENS160 @ i2c-1",
6
+ "bus": "1",
7
+ "addr": "0x52"
8
+ },
9
+ {
10
+ "id": "ens160-read-1",
11
+ "type": "periph-ens160",
12
+ "name": "ENS160 Air Quality",
13
+ "device": "ens160-device-1",
14
+ "wires": [["debug-1", "aqi-function-1"]]
15
+ },
16
+ {
17
+ "id": "inject-timer-1",
18
+ "type": "inject",
19
+ "name": "Every 10 seconds",
20
+ "topic": "",
21
+ "payload": "",
22
+ "payloadType": "date",
23
+ "repeat": "10",
24
+ "crontab": "",
25
+ "onceDelay": "0.1",
26
+ "wires": [["ens160-read-1"]]
27
+ },
28
+ {
29
+ "id": "debug-1",
30
+ "type": "debug",
31
+ "name": "Debug output",
32
+ "active": true,
33
+ "tosideuit": false,
34
+ "console": "false",
35
+ "tostatus": "false",
36
+ "complete": "payload",
37
+ "targetType": "msg",
38
+ "x": 480,
39
+ "y": 200,
40
+ "wires": []
41
+ },
42
+ {
43
+ "id": "aqi-function-1",
44
+ "type": "function",
45
+ "name": "Format AQI message",
46
+ "func": "const labels = {1: 'Excellent', 2: 'Good', 3: 'Moderate', 4: 'Poor', 5: 'Unhealthy'};\nconst aqi = msg.payload.aqi;\nconst label = labels[aqi] || 'Unknown';\nmsg.payload = {\n aqi: aqi,\n label: label,\n tvoc: msg.payload.tvocPpb + ' ppb',\n eco2: msg.payload.eco2Ppm + ' ppm'\n};\nreturn msg;",
47
+ "outputs": 1,
48
+ "noerr": 0,
49
+ "x": 480,
50
+ "y": 260,
51
+ "wires": [["gauge-1"]]
52
+ },
53
+ {
54
+ "id": "gauge-1",
55
+ "type": "ui_gauge",
56
+ "name": "AQI Gauge",
57
+ "group": "ens160-group-1",
58
+ "order": 1,
59
+ "width": 6,
60
+ "height": 4,
61
+ "gtype": "gage",
62
+ "title": "Air Quality Index",
63
+ "label": "AQI",
64
+ "format": "{{value}}",
65
+ "min": 1,
66
+ "max": 5,
67
+ "colors": ["#00b500", "#fdd000", "#f70909"],
68
+ "seg1": "2",
69
+ "seg2": "4",
70
+ "x": 680,
71
+ "y": 260,
72
+ "wires": []
73
+ },
74
+ {
75
+ "id": "ens160-group-1",
76
+ "type": "ui_group",
77
+ "name": "ENS160 Air Quality Monitor",
78
+ "tab": "ens160-tab-1",
79
+ "order": 1,
80
+ "disp": true,
81
+ "width": 12
82
+ },
83
+ {
84
+ "id": "ens160-tab-1",
85
+ "type": "ui_tab",
86
+ "name": "ENS160 Demo",
87
+ "icon": "dashboard",
88
+ "order": 1,
89
+ "info": "This flow demonstrates the ENS160 digital multi-gas sensor for indoor air quality monitoring.\n\nAn inject node fires every 10 seconds, triggering the ENS160 node to read air quality. The output includes AQI (1-5 scale), TVOC (ppb), and eCO2 (ppm).\n\nA function node formats the AQI with a human-readable label (Excellent/Good/Moderate/Poor/Unhealthy) and feeds a gauge widget showing the color-coded AQI value.\n\nThe ENS160 requires ~3 minutes warm-up after power-on before VALIDITY_FLAG reaches 0. During warm-up, the node outputs a warning with the current status."
90
+ }
91
+ ]
@@ -0,0 +1,88 @@
1
+ <!-- Config node: one instance per physical device -->
2
+ <script type="text/javascript">
3
+ RED.nodes.registerType('ens160-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ addr: { value: '0x52', required: true }
9
+ },
10
+ label: function() {
11
+ return this.name || ('ENS160 @ ' + this.addr + ' (bus ' + this.bus + ')');
12
+ }
13
+ });
14
+ </script>
15
+
16
+ <script type="text/html" data-template-name="ens160-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="ENS160">
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-addr"><i class="fa fa-microchip"></i> I²C address</label>
27
+ <select id="node-config-input-addr" style="width:100px">
28
+ <option value="0x52">0x52 (ADDR low)</option>
29
+ <option value="0x53">0x53 (ADDR high)</option>
30
+ </select>
31
+ </div>
32
+ </script>
33
+
34
+ <!-- Read node: trigger → measurements -->
35
+ <script type="text/javascript">
36
+ RED.nodes.registerType('periph-ens160', {
37
+ category: 'Peripheral',
38
+ color: '#a6bbcf',
39
+ defaults: {
40
+ name: { value: '' },
41
+ device: { value: '', type: 'ens160-device', required: true }
42
+ },
43
+ inputs: 1,
44
+ outputs: 1,
45
+ icon: 'font-awesome/fa-leaf',
46
+ label: function() { return this.name || 'ENS160'; },
47
+ paletteLabel: 'ENS160'
48
+ });
49
+ </script>
50
+
51
+ <script type="text/html" data-template-name="periph-ens160">
52
+ <div class="form-row">
53
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
54
+ <input type="text" id="node-input-device">
55
+ </div>
56
+ <div class="form-row">
57
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
58
+ <input type="text" id="node-input-name" placeholder="ENS160">
59
+ </div>
60
+ </script>
61
+
62
+ <script type="text/html" data-help-name="periph-ens160">
63
+ <p>Reads air quality (AQI, TVOC, eCO2) from an ENS160 digital multi-gas sensor.</p>
64
+ <p>Any input message triggers a measurement. The device is configured via an <b>ens160-device</b> config node.</p>
65
+
66
+ <h3>Inputs</h3>
67
+ <dl class="message-properties">
68
+ <dt>payload <span class="property-type">any</span></dt>
69
+ <dd>Any incoming message triggers a measurement.</dd>
70
+ </dl>
71
+
72
+ <h3>Outputs</h3>
73
+ <dl class="message-properties">
74
+ <dt>payload.aqi <span class="property-type">number</span></dt>
75
+ <dd>Air Quality Index (UBA scale, 1–5).</dd>
76
+ <dt>payload.tvocPpb <span class="property-type">number</span></dt>
77
+ <dd>TVOC concentration in ppb.</dd>
78
+ <dt>payload.eco2Ppm <span class="property-type">number</span></dt>
79
+ <dd>Equivalent CO2 concentration in ppm.</dd>
80
+ <dt>payload.status <span class="property-type">number</span></dt>
81
+ <dd>VALIDITY_FLAG (0=OK, 1=Warm-up, 2=Initial Start-up, 3=Invalid).</dd>
82
+ </dl>
83
+
84
+ <h3>Configuration</h3>
85
+ <p>Set the I²C bus number and I²C address (<code>0x52</code> or <code>0x53</code>)
86
+ in the device config node. The sensor requires ~3 minutes warm-up after power-on
87
+ before VALIDITY_FLAG reaches 0.</p>
88
+ </script>
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CTransport } = require('periph/src/transport/i2c');
5
+ const { ENS160Full } = require('periph/src/chips/gas/ens160');
6
+
7
+ function ENS160DeviceNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const addr = parseInt(config.addr) || 0x52;
12
+ const transport = new I2CTransport(parseInt(config.bus), addr);
13
+ node.driver = new ENS160Full(transport);
14
+ node.transport = transport;
15
+ } catch (e) {
16
+ node.error('ENS160 init failed: ' + e.message);
17
+ }
18
+ node.on('close', function() {
19
+ if (node.transport) node.transport.close();
20
+ });
21
+ }
22
+ RED.nodes.registerType('ens160-device', ENS160DeviceNode);
23
+
24
+ function ENS160ReadNode(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 ENS160 device configured', msg);
32
+ done();
33
+ return;
34
+ }
35
+ try {
36
+ const d = node.device.driver;
37
+ const status = d.status();
38
+ if (status !== 0) {
39
+ node.warn('ENS160 data not valid (status=' + status + ')');
40
+ msg.payload = { status: status };
41
+ send(msg);
42
+ done();
43
+ return;
44
+ }
45
+ const data = d.readAirQuality();
46
+ msg.payload = {
47
+ aqi: data.aqi,
48
+ tvocPpb: data.tvocPpb,
49
+ eco2Ppm: data.eco2Ppm,
50
+ status: 0
51
+ };
52
+ send(msg);
53
+ done();
54
+ } catch (e) {
55
+ done(e);
56
+ }
57
+ });
58
+ }
59
+ RED.nodes.registerType('periph-ens160', ENS160ReadNode);
60
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-gas",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Node-RED nodes for gas 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
+ "ens160": "nodes/ens160/ens160.js"
16
+ }
15
17
  },
16
18
  "dependencies": {
17
19
  "periph": "*"