node-red-contrib-periph-power 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.
- package/README.md +29 -0
- package/examples/ina219/demo.json +76 -0
- package/examples/ina226/demo.json +76 -0
- package/examples/ina3221/demo.json +77 -0
- package/index.js +11 -0
- package/nodes/ina219/ina219.html +88 -0
- package/nodes/ina219/ina219.js +50 -0
- package/nodes/ina226/ina226.html +88 -0
- package/nodes/ina226/ina226.js +50 -0
- package/nodes/ina3221/ina3221.html +82 -0
- package/nodes/ina3221/ina3221.js +55 -0
- package/package.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# node-red-contrib-periph-power
|
|
2
|
+
|
|
3
|
+
Node-RED nodes for power monitor chips — part of the [Periph](https://github.com/tuhde/Periph) library.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Open Node-RED, go to **Manage Palette → Install** and search for `node-red-contrib-periph-power`.
|
|
8
|
+
|
|
9
|
+
Or from the command line in your Node-RED user directory:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install node-red-contrib-periph-power
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Nodes
|
|
16
|
+
|
|
17
|
+
| Node | Kind | Description |
|
|
18
|
+
|------|------|-------------|
|
|
19
|
+
| `ina219-device` | config | I²C bus and address for an INA219 |
|
|
20
|
+
| `ina219` | input | Read voltage, current, and power from an INA219 |
|
|
21
|
+
| `ina226-device` | config | I²C bus and address for an INA226 |
|
|
22
|
+
| `ina226` | input | Read voltage, current, and power from an INA226 |
|
|
23
|
+
| `ina3221-device` | config | I²C bus and address for an INA3221 |
|
|
24
|
+
| `periph-ina3221` | input | Read 3-channel voltage and current from an INA3221 |
|
|
25
|
+
|
|
26
|
+
## Links
|
|
27
|
+
|
|
28
|
+
- [GitHub](https://github.com/tuhde/Periph)
|
|
29
|
+
- [periph JS driver](https://www.npmjs.com/package/periph)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-ina219-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "INA219 Power Monitor",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Reads voltage, current, and power from an INA219 every second and displays a formatted string in the debug panel."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-ina219",
|
|
11
|
+
"type": "ina219-device",
|
|
12
|
+
"name": "INA219",
|
|
13
|
+
"bus": "1",
|
|
14
|
+
"address": "40",
|
|
15
|
+
"rShunt": "0.1",
|
|
16
|
+
"maxCurrent": "2.0"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "inj-tick",
|
|
20
|
+
"type": "inject",
|
|
21
|
+
"name": "every 1 s",
|
|
22
|
+
"repeat": "1",
|
|
23
|
+
"crontab": "",
|
|
24
|
+
"once": true,
|
|
25
|
+
"onceDelay": 0.1,
|
|
26
|
+
"topic": "",
|
|
27
|
+
"payload": "",
|
|
28
|
+
"payloadType": "date",
|
|
29
|
+
"z": "tab-ina219-demo",
|
|
30
|
+
"x": 120,
|
|
31
|
+
"y": 160,
|
|
32
|
+
"wires": [["read-ina219"]]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "read-ina219",
|
|
36
|
+
"type": "ina219",
|
|
37
|
+
"name": "INA219",
|
|
38
|
+
"device": "cfg-ina219",
|
|
39
|
+
"z": "tab-ina219-demo",
|
|
40
|
+
"x": 300,
|
|
41
|
+
"y": 160,
|
|
42
|
+
"wires": [["fmt-readings"]]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "fmt-readings",
|
|
46
|
+
"type": "function",
|
|
47
|
+
"name": "format",
|
|
48
|
+
"func": "const p = msg.payload;\nmsg.payload = p.voltage.toFixed(3) + 'V ' + p.current.toFixed(4) + 'A ' + p.power.toFixed(4) + 'W';\nreturn msg;",
|
|
49
|
+
"outputs": 1,
|
|
50
|
+
"noerr": 0,
|
|
51
|
+
"initialize": "",
|
|
52
|
+
"finalize": "",
|
|
53
|
+
"libs": [],
|
|
54
|
+
"z": "tab-ina219-demo",
|
|
55
|
+
"x": 480,
|
|
56
|
+
"y": 160,
|
|
57
|
+
"wires": [["dbg-readings"]]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "dbg-readings",
|
|
61
|
+
"type": "debug",
|
|
62
|
+
"name": "",
|
|
63
|
+
"active": true,
|
|
64
|
+
"tosidebar": true,
|
|
65
|
+
"console": false,
|
|
66
|
+
"tostatus": true,
|
|
67
|
+
"complete": "payload",
|
|
68
|
+
"targetType": "msg",
|
|
69
|
+
"statusVal": "payload",
|
|
70
|
+
"statusType": "auto",
|
|
71
|
+
"z": "tab-ina219-demo",
|
|
72
|
+
"x": 650,
|
|
73
|
+
"y": 160,
|
|
74
|
+
"wires": []
|
|
75
|
+
}
|
|
76
|
+
]
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-ina226-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "INA226 Power Monitor",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Reads voltage, current, and power from an INA226 every second and displays a formatted string in the debug panel."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-ina226",
|
|
11
|
+
"type": "ina226-device",
|
|
12
|
+
"name": "INA226",
|
|
13
|
+
"bus": "1",
|
|
14
|
+
"address": "40",
|
|
15
|
+
"rShunt": "0.1",
|
|
16
|
+
"maxCurrent": "2.0"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "inj-tick",
|
|
20
|
+
"type": "inject",
|
|
21
|
+
"name": "every 1 s",
|
|
22
|
+
"repeat": "1",
|
|
23
|
+
"crontab": "",
|
|
24
|
+
"once": true,
|
|
25
|
+
"onceDelay": 0.1,
|
|
26
|
+
"topic": "",
|
|
27
|
+
"payload": "",
|
|
28
|
+
"payloadType": "date",
|
|
29
|
+
"z": "tab-ina226-demo",
|
|
30
|
+
"x": 120,
|
|
31
|
+
"y": 160,
|
|
32
|
+
"wires": [["read-ina226"]]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "read-ina226",
|
|
36
|
+
"type": "ina226",
|
|
37
|
+
"name": "INA226",
|
|
38
|
+
"device": "cfg-ina226",
|
|
39
|
+
"z": "tab-ina226-demo",
|
|
40
|
+
"x": 300,
|
|
41
|
+
"y": 160,
|
|
42
|
+
"wires": [["fmt-readings"]]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "fmt-readings",
|
|
46
|
+
"type": "function",
|
|
47
|
+
"name": "format",
|
|
48
|
+
"func": "const p = msg.payload;\nmsg.payload = p.voltage.toFixed(3) + 'V ' + p.current.toFixed(4) + 'A ' + p.power.toFixed(4) + 'W';\nreturn msg;",
|
|
49
|
+
"outputs": 1,
|
|
50
|
+
"noerr": 0,
|
|
51
|
+
"initialize": "",
|
|
52
|
+
"finalize": "",
|
|
53
|
+
"libs": [],
|
|
54
|
+
"z": "tab-ina226-demo",
|
|
55
|
+
"x": 480,
|
|
56
|
+
"y": 160,
|
|
57
|
+
"wires": [["dbg-readings"]]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "dbg-readings",
|
|
61
|
+
"type": "debug",
|
|
62
|
+
"name": "",
|
|
63
|
+
"active": true,
|
|
64
|
+
"tosidebar": true,
|
|
65
|
+
"console": false,
|
|
66
|
+
"tostatus": true,
|
|
67
|
+
"complete": "payload",
|
|
68
|
+
"targetType": "msg",
|
|
69
|
+
"statusVal": "payload",
|
|
70
|
+
"statusType": "auto",
|
|
71
|
+
"z": "tab-ina226-demo",
|
|
72
|
+
"x": 650,
|
|
73
|
+
"y": 160,
|
|
74
|
+
"wires": []
|
|
75
|
+
}
|
|
76
|
+
]
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "n1",
|
|
4
|
+
"type": "periph-ina3221",
|
|
5
|
+
"name": "INA3221 Monitor",
|
|
6
|
+
"device": "c1",
|
|
7
|
+
"wires": [["n2_ch1", "n2_ch2", "n2_ch3"]],
|
|
8
|
+
"z": "ina3221_demo"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"id": "c1",
|
|
12
|
+
"type": "ina3221-device",
|
|
13
|
+
"name": "",
|
|
14
|
+
"bus": "1",
|
|
15
|
+
"address": "40",
|
|
16
|
+
"rShunt": "0.1",
|
|
17
|
+
"z": "ina3221_demo"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"id": "n2_ch1",
|
|
21
|
+
"type": "ui_chart",
|
|
22
|
+
"name": "CH1 Voltage",
|
|
23
|
+
"z": "ina3221_demo",
|
|
24
|
+
"group": "g1",
|
|
25
|
+
"order": 1,
|
|
26
|
+
"wires": []
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"id": "n2_ch2",
|
|
30
|
+
"type": "ui_chart",
|
|
31
|
+
"name": "CH2 Voltage",
|
|
32
|
+
"z": "ina3221_demo",
|
|
33
|
+
"group": "g1",
|
|
34
|
+
"order": 2,
|
|
35
|
+
"wires": []
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"id": "n2_ch3",
|
|
39
|
+
"type": "ui_chart",
|
|
40
|
+
"name": "CH3 Voltage",
|
|
41
|
+
"z": "ina3221_demo",
|
|
42
|
+
"group": "g1",
|
|
43
|
+
"order": 3,
|
|
44
|
+
"wires": []
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"id": "n3",
|
|
48
|
+
"type": "inject",
|
|
49
|
+
"name": "Tick",
|
|
50
|
+
"repeat": "1",
|
|
51
|
+
"crontab": "",
|
|
52
|
+
"once": false,
|
|
53
|
+
"topic": "",
|
|
54
|
+
"payload": "",
|
|
55
|
+
"payloadType": "date",
|
|
56
|
+
"wires": [["n1"]],
|
|
57
|
+
"z": "ina3221_demo"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"id": "g1",
|
|
61
|
+
"type": "ui_group",
|
|
62
|
+
"name": "INA3221 Channels",
|
|
63
|
+
"z": "ina3221_demo",
|
|
64
|
+
"tab": "t1"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
"id": "t1",
|
|
68
|
+
"type": "ui_tab",
|
|
69
|
+
"name": "Power Monitor",
|
|
70
|
+
"z": "ina3221_demo"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"id": "ina3221_demo",
|
|
74
|
+
"type": "tab",
|
|
75
|
+
"label": "INA3221 Three-Rail Monitor"
|
|
76
|
+
}
|
|
77
|
+
]
|
package/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
module.exports = function(RED) {
|
|
5
|
+
const nodesDir = path.join(__dirname, 'nodes');
|
|
6
|
+
if (!fs.existsSync(nodesDir)) return;
|
|
7
|
+
fs.readdirSync(nodesDir).forEach(function(chip) {
|
|
8
|
+
const nodeFile = path.join(nodesDir, chip, chip + '.js');
|
|
9
|
+
if (fs.existsSync(nodeFile)) require(nodeFile)(RED);
|
|
10
|
+
});
|
|
11
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('ina219-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '40', required: true },
|
|
9
|
+
rShunt: { value: '0.1', required: true, validate: RED.validators.number() },
|
|
10
|
+
maxCurrent: { value: '2.0', required: true, validate: RED.validators.number() }
|
|
11
|
+
},
|
|
12
|
+
label: function() {
|
|
13
|
+
return this.name || ('INA219 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script type="text/html" data-template-name="ina219-device">
|
|
19
|
+
<div class="form-row">
|
|
20
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
21
|
+
<input type="text" id="node-config-input-name" placeholder="INA219">
|
|
22
|
+
</div>
|
|
23
|
+
<div class="form-row">
|
|
24
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
25
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
26
|
+
</div>
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-config-input-address">Address (hex)</label>
|
|
29
|
+
<input type="text" id="node-config-input-address" placeholder="40" style="width:80px"> default: 40 (0x40)
|
|
30
|
+
</div>
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-config-input-rShunt">R<sub>shunt</sub> (Ω)</label>
|
|
33
|
+
<input type="number" id="node-config-input-rShunt" min="0.001" step="0.001" style="width:100px">
|
|
34
|
+
</div>
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-config-input-maxCurrent">Max current (A)</label>
|
|
37
|
+
<input type="number" id="node-config-input-maxCurrent" min="0.001" step="0.1" style="width:100px">
|
|
38
|
+
</div>
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<!-- Read node: trigger → measurements -->
|
|
42
|
+
<script type="text/javascript">
|
|
43
|
+
RED.nodes.registerType('ina219', {
|
|
44
|
+
category: 'Peripheral',
|
|
45
|
+
color: '#a6bbcf',
|
|
46
|
+
defaults: {
|
|
47
|
+
name: { value: '' },
|
|
48
|
+
device: { value: '', type: 'ina219-device', required: true }
|
|
49
|
+
},
|
|
50
|
+
inputs: 1,
|
|
51
|
+
outputs: 1,
|
|
52
|
+
icon: 'font-awesome/fa-bolt',
|
|
53
|
+
label: function() { return this.name || 'INA219'; },
|
|
54
|
+
paletteLabel: 'INA219'
|
|
55
|
+
});
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<script type="text/html" data-template-name="ina219">
|
|
59
|
+
<div class="form-row">
|
|
60
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
61
|
+
<input type="text" id="node-input-device">
|
|
62
|
+
</div>
|
|
63
|
+
<div class="form-row">
|
|
64
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
65
|
+
<input type="text" id="node-input-name" placeholder="INA219">
|
|
66
|
+
</div>
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<script type="text/html" data-help-name="ina219">
|
|
70
|
+
<p>Reads voltage, current, power, and shunt voltage from an INA219 power monitor over I²C.</p>
|
|
71
|
+
<p>Any input message triggers a measurement. The device is configured via an <b>ina219-device</b> config node.</p>
|
|
72
|
+
|
|
73
|
+
<h3>Output</h3>
|
|
74
|
+
<dl class="message-properties">
|
|
75
|
+
<dt>payload.voltage <span class="property-type">number</span></dt>
|
|
76
|
+
<dd>Bus voltage in volts.</dd>
|
|
77
|
+
<dt>payload.current <span class="property-type">number</span></dt>
|
|
78
|
+
<dd>Current in amperes.</dd>
|
|
79
|
+
<dt>payload.power <span class="property-type">number</span></dt>
|
|
80
|
+
<dd>Power in watts.</dd>
|
|
81
|
+
<dt>payload.shuntVoltage <span class="property-type">number</span></dt>
|
|
82
|
+
<dd>Shunt voltage in volts.</dd>
|
|
83
|
+
</dl>
|
|
84
|
+
|
|
85
|
+
<h3>Details</h3>
|
|
86
|
+
<p>Configure bus number, I²C address (default <code>0x40</code>), shunt resistance, and maximum expected
|
|
87
|
+
current in the device config node. The driver uses these to set the calibration register on startup.</p>
|
|
88
|
+
</script>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CTransport } = require('periph/src/transport/i2c');
|
|
5
|
+
const { INA219Full } = require('periph/src/chips/power/ina219');
|
|
6
|
+
|
|
7
|
+
function INA219DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const transport = new I2CTransport(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new INA219Full(transport, parseFloat(config.rShunt), parseFloat(config.maxCurrent));
|
|
13
|
+
node.transport = transport;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
node.error('INA219 init failed: ' + e.message);
|
|
16
|
+
}
|
|
17
|
+
node.on('close', function() {
|
|
18
|
+
if (node.transport) node.transport.close();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
RED.nodes.registerType('ina219-device', INA219DeviceNode);
|
|
22
|
+
|
|
23
|
+
function INA219ReadNode(config) {
|
|
24
|
+
RED.nodes.createNode(this, config);
|
|
25
|
+
const node = this;
|
|
26
|
+
node.device = RED.nodes.getNode(config.device);
|
|
27
|
+
|
|
28
|
+
node.on('input', function(msg, send, done) {
|
|
29
|
+
if (!node.device || !node.device.driver) {
|
|
30
|
+
node.error('No INA219 device configured', msg);
|
|
31
|
+
done();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const d = node.device.driver;
|
|
36
|
+
msg.payload = {
|
|
37
|
+
voltage: d.voltage(),
|
|
38
|
+
current: d.current(),
|
|
39
|
+
power: d.power(),
|
|
40
|
+
shuntVoltage: d.shuntVoltage()
|
|
41
|
+
};
|
|
42
|
+
send(msg);
|
|
43
|
+
done();
|
|
44
|
+
} catch (e) {
|
|
45
|
+
done(e);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
RED.nodes.registerType('ina219', INA219ReadNode);
|
|
50
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('ina226-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '40', required: true },
|
|
9
|
+
rShunt: { value: '0.1', required: true, validate: RED.validators.number() },
|
|
10
|
+
maxCurrent: { value: '2.0', required: true, validate: RED.validators.number() }
|
|
11
|
+
},
|
|
12
|
+
label: function() {
|
|
13
|
+
return this.name || ('INA226 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script type="text/html" data-template-name="ina226-device">
|
|
19
|
+
<div class="form-row">
|
|
20
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
21
|
+
<input type="text" id="node-config-input-name" placeholder="INA226">
|
|
22
|
+
</div>
|
|
23
|
+
<div class="form-row">
|
|
24
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
25
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
26
|
+
</div>
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-config-input-address">Address (hex)</label>
|
|
29
|
+
<input type="text" id="node-config-input-address" placeholder="40" style="width:80px"> default: 40 (0x40)
|
|
30
|
+
</div>
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-config-input-rShunt">R<sub>shunt</sub> (Ω)</label>
|
|
33
|
+
<input type="number" id="node-config-input-rShunt" min="0.001" step="0.001" style="width:100px">
|
|
34
|
+
</div>
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-config-input-maxCurrent">Max current (A)</label>
|
|
37
|
+
<input type="number" id="node-config-input-maxCurrent" min="0.001" step="0.1" style="width:100px">
|
|
38
|
+
</div>
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<!-- Read node: trigger → measurements -->
|
|
42
|
+
<script type="text/javascript">
|
|
43
|
+
RED.nodes.registerType('ina226', {
|
|
44
|
+
category: 'Peripheral',
|
|
45
|
+
color: '#a6bbcf',
|
|
46
|
+
defaults: {
|
|
47
|
+
name: { value: '' },
|
|
48
|
+
device: { value: '', type: 'ina226-device', required: true }
|
|
49
|
+
},
|
|
50
|
+
inputs: 1,
|
|
51
|
+
outputs: 1,
|
|
52
|
+
icon: 'font-awesome/fa-bolt',
|
|
53
|
+
label: function() { return this.name || 'INA226'; },
|
|
54
|
+
paletteLabel: 'INA226'
|
|
55
|
+
});
|
|
56
|
+
</script>
|
|
57
|
+
|
|
58
|
+
<script type="text/html" data-template-name="ina226">
|
|
59
|
+
<div class="form-row">
|
|
60
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
61
|
+
<input type="text" id="node-input-device">
|
|
62
|
+
</div>
|
|
63
|
+
<div class="form-row">
|
|
64
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
65
|
+
<input type="text" id="node-input-name" placeholder="INA226">
|
|
66
|
+
</div>
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<script type="text/html" data-help-name="ina226">
|
|
70
|
+
<p>Reads voltage, current, power, and shunt voltage from an INA226 power monitor over I²C.</p>
|
|
71
|
+
<p>Any input message triggers a measurement. The device is configured via an <b>ina226-device</b> config node.</p>
|
|
72
|
+
|
|
73
|
+
<h3>Output</h3>
|
|
74
|
+
<dl class="message-properties">
|
|
75
|
+
<dt>payload.voltage <span class="property-type">number</span></dt>
|
|
76
|
+
<dd>Bus voltage in volts.</dd>
|
|
77
|
+
<dt>payload.current <span class="property-type">number</span></dt>
|
|
78
|
+
<dd>Current in amperes. Requires correct R<sub>shunt</sub> and max current in the device config.</dd>
|
|
79
|
+
<dt>payload.power <span class="property-type">number</span></dt>
|
|
80
|
+
<dd>Power in watts.</dd>
|
|
81
|
+
<dt>payload.shuntVoltage <span class="property-type">number</span></dt>
|
|
82
|
+
<dd>Shunt voltage in volts.</dd>
|
|
83
|
+
</dl>
|
|
84
|
+
|
|
85
|
+
<h3>Details</h3>
|
|
86
|
+
<p>Configure bus number, I²C address (default <code>0x40</code>), shunt resistance, and maximum expected
|
|
87
|
+
current in the device config node. The driver uses these to set the calibration register on startup.</p>
|
|
88
|
+
</script>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CTransport } = require('periph/src/transport/i2c');
|
|
5
|
+
const { INA226Full } = require('periph/src/chips/power/ina226');
|
|
6
|
+
|
|
7
|
+
function INA226DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const transport = new I2CTransport(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new INA226Full(transport, parseFloat(config.rShunt), parseFloat(config.maxCurrent));
|
|
13
|
+
node.transport = transport;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
node.error('INA226 init failed: ' + e.message);
|
|
16
|
+
}
|
|
17
|
+
node.on('close', function() {
|
|
18
|
+
if (node.transport) node.transport.close();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
RED.nodes.registerType('ina226-device', INA226DeviceNode);
|
|
22
|
+
|
|
23
|
+
function INA226ReadNode(config) {
|
|
24
|
+
RED.nodes.createNode(this, config);
|
|
25
|
+
const node = this;
|
|
26
|
+
node.device = RED.nodes.getNode(config.device);
|
|
27
|
+
|
|
28
|
+
node.on('input', function(msg, send, done) {
|
|
29
|
+
if (!node.device || !node.device.driver) {
|
|
30
|
+
node.error('No INA226 device configured', msg);
|
|
31
|
+
done();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const d = node.device.driver;
|
|
36
|
+
msg.payload = {
|
|
37
|
+
voltage: d.voltage(),
|
|
38
|
+
current: d.current(),
|
|
39
|
+
power: d.power(),
|
|
40
|
+
shuntVoltage: d.shuntVoltage()
|
|
41
|
+
};
|
|
42
|
+
send(msg);
|
|
43
|
+
done();
|
|
44
|
+
} catch (e) {
|
|
45
|
+
done(e);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
RED.nodes.registerType('ina226', INA226ReadNode);
|
|
50
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('ina3221-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address:{ value: '40', required: true },
|
|
9
|
+
rShunt: { value: '0.1', required: true, validate: RED.validators.number() }
|
|
10
|
+
},
|
|
11
|
+
label: function() {
|
|
12
|
+
return this.name || ('INA3221 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script type="text/html" data-template-name="ina3221-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="INA3221">
|
|
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">Address (hex)</label>
|
|
28
|
+
<input type="text" id="node-config-input-address" placeholder="40" style="width:80px"> default: 40 (0x40)
|
|
29
|
+
</div>
|
|
30
|
+
<div class="form-row">
|
|
31
|
+
<label for="node-config-input-rShunt">R<sub>shunt</sub> (Ω)</label>
|
|
32
|
+
<input type="number" id="node-config-input-rShunt" min="0.001" step="0.001" style="width:100px">
|
|
33
|
+
</div>
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<!-- Read node: trigger → measurements -->
|
|
37
|
+
<script type="text/javascript">
|
|
38
|
+
RED.nodes.registerType('periph-ina3221', {
|
|
39
|
+
category: 'Peripheral',
|
|
40
|
+
color: '#a6bbcf',
|
|
41
|
+
defaults: {
|
|
42
|
+
name: { value: '' },
|
|
43
|
+
device: { value: '', type: 'ina3221-device', required: true }
|
|
44
|
+
},
|
|
45
|
+
inputs: 1,
|
|
46
|
+
outputs: 1,
|
|
47
|
+
icon: 'font-awesome/fa-bolt',
|
|
48
|
+
label: function() { return this.name || 'INA3221'; },
|
|
49
|
+
paletteLabel: 'INA3221'
|
|
50
|
+
});
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
<script type="text/html" data-template-name="periph-ina3221">
|
|
54
|
+
<div class="form-row">
|
|
55
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
56
|
+
<input type="text" id="node-input-device">
|
|
57
|
+
</div>
|
|
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="INA3221">
|
|
61
|
+
</div>
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<script type="text/html" data-help-name="periph-ina3221">
|
|
65
|
+
<p>Reads bus voltage, shunt voltage, current, and power from an INA3221 three-channel power monitor over I²C.</p>
|
|
66
|
+
<p>Any input message triggers a measurement. The device is configured via an <b>ina3221-device</b> config node.</p>
|
|
67
|
+
|
|
68
|
+
<h3>Output</h3>
|
|
69
|
+
<dl class="message-properties">
|
|
70
|
+
<dt>payload.ch1 <span class="property-type">object</span></dt>
|
|
71
|
+
<dd>Channel 1 readings: voltage, shuntVoltage, current, power.</dd>
|
|
72
|
+
<dt>payload.ch2 <span class="property-type">object</span></dt>
|
|
73
|
+
<dd>Channel 2 readings: voltage, shuntVoltage, current, power.</dd>
|
|
74
|
+
<dt>payload.ch3 <span class="property-type">object</span></dt>
|
|
75
|
+
<dd>Channel 3 readings: voltage, shuntVoltage, current, power.</dd>
|
|
76
|
+
</dl>
|
|
77
|
+
|
|
78
|
+
<h3>Details</h3>
|
|
79
|
+
<p>Configure bus number, I²C address (default <code>0x40</code>), and shunt resistance
|
|
80
|
+
in the device config node. The INA3221's three channels can monitor three separate
|
|
81
|
+
power rails simultaneously.</p>
|
|
82
|
+
</script>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CTransport } = require('periph/src/transport/i2c');
|
|
5
|
+
const { INA3221Full } = require('periph/src/chips/power/ina3221');
|
|
6
|
+
|
|
7
|
+
function INA3221DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const transport = new I2CTransport(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
const rShunt = config.rShunt || 0.1;
|
|
13
|
+
node.driver = new INA3221Full(transport, rShunt);
|
|
14
|
+
node.transport = transport;
|
|
15
|
+
} catch (e) {
|
|
16
|
+
node.error('INA3221 init failed: ' + e.message);
|
|
17
|
+
}
|
|
18
|
+
node.on('close', function() {
|
|
19
|
+
if (node.transport) node.transport.close();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
RED.nodes.registerType('ina3221-device', INA3221DeviceNode);
|
|
23
|
+
|
|
24
|
+
function INA3221ReadNode(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 INA3221 device configured', msg);
|
|
32
|
+
done();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const d = node.device.driver;
|
|
37
|
+
const payload = {};
|
|
38
|
+
for (const ch of [1, 2, 3]) {
|
|
39
|
+
payload['ch' + ch] = {
|
|
40
|
+
voltage: d.voltage(ch),
|
|
41
|
+
shuntVoltage: d.shuntVoltage(ch),
|
|
42
|
+
current: d.current(ch),
|
|
43
|
+
power: d.power(ch)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
msg.payload = payload;
|
|
47
|
+
send(msg);
|
|
48
|
+
done();
|
|
49
|
+
} catch (e) {
|
|
50
|
+
done(e);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
RED.nodes.registerType('periph-ina3221', INA3221ReadNode);
|
|
55
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-red-contrib-periph-power",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Node-RED nodes for power monitor chips",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"node-red",
|
|
7
|
+
"power",
|
|
8
|
+
"i2c",
|
|
9
|
+
"spi",
|
|
10
|
+
"sensor",
|
|
11
|
+
"peripheral"
|
|
12
|
+
],
|
|
13
|
+
"main": "index.js",
|
|
14
|
+
"node-red": {
|
|
15
|
+
"nodes": {
|
|
16
|
+
"ina226": "nodes/ina226/ina226.js",
|
|
17
|
+
"ina219": "nodes/ina219/ina219.js",
|
|
18
|
+
"ina3221": "nodes/ina3221/ina3221.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"periph": "*"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT"
|
|
25
|
+
}
|