node-red-contrib-periph-power 1.1.0 → 1.2.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 +4 -3
- package/examples/ade7953/demo.json +50 -0
- package/nodes/ade7953/ade7953.html +52 -0
- package/nodes/ade7953/ade7953.js +54 -0
- package/nodes/ina219/ina219.html +1 -1
- package/nodes/ina219/ina219.js +10 -10
- package/nodes/ina226/ina226.html +1 -1
- package/nodes/ina226/ina226.js +10 -10
- package/nodes/ina3221/ina3221.html +1 -1
- package/nodes/ina3221/ina3221.js +11 -11
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -16,12 +16,13 @@ npm install node-red-contrib-periph-power
|
|
|
16
16
|
|
|
17
17
|
| Node | Kind | Description |
|
|
18
18
|
|------|------|-------------|
|
|
19
|
+
| `periph-ade7953` | input | Reads bus voltage, load current, active power, and accumulated active energy from an ADE7953 single-phase multifunction metering IC. |
|
|
19
20
|
| `ina219-device` | config | I²C bus and address for an INA219 |
|
|
20
|
-
| `ina219` | input |
|
|
21
|
+
| `ina219` | input | Reads voltage, current, power, and shunt voltage from an INA219 power monitor over I²C. |
|
|
21
22
|
| `ina226-device` | config | I²C bus and address for an INA226 |
|
|
22
|
-
| `ina226` | input |
|
|
23
|
+
| `ina226` | input | Reads voltage, current, power, and shunt voltage from an INA226 power monitor over I²C. |
|
|
23
24
|
| `ina3221-device` | config | I²C bus and address for an INA3221 |
|
|
24
|
-
| `periph-ina3221` | input |
|
|
25
|
+
| `periph-ina3221` | input | Reads bus voltage, shunt voltage, current, and power from an INA3221 three-channel power monitor over I²C. |
|
|
25
26
|
|
|
26
27
|
## Links
|
|
27
28
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-ade7953-1",
|
|
4
|
+
"type": "ui_tab",
|
|
5
|
+
"name": "ADE7953 Demo",
|
|
6
|
+
"icon": "bolt",
|
|
7
|
+
"order": 1,
|
|
8
|
+
"info": "This flow demonstrates the ADE7953 single-phase multifunction metering IC.\n\n**Continuous single-phase metering**: an inject node fires once per second into the periph-ade7953 node, which emits voltage, current, active power, and cumulative active energy for Current Channel A. A function node formats the four values as one line; a debug node prints them to the sidebar — the user sees a live single-phase energy-monitoring feed, with active energy visibly climbing over the session.\n\nThe chip is wired to the host over I²C at the chip's fixed 7-bit address 0x38; the calibration constants (voltage_gain = 251.0 V/V, current_gain = 30.0 A/V) are placeholders — replace them with the actual values for the external voltage divider and current sensor on your PCB."
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"id": "ade7953-device-1",
|
|
12
|
+
"type": "periph-ade7953",
|
|
13
|
+
"name": "ADE7953 @ i2c-1",
|
|
14
|
+
"bus": "1",
|
|
15
|
+
"addr": "0x38",
|
|
16
|
+
"voltageGain": "251.0",
|
|
17
|
+
"currentGain": "30.0",
|
|
18
|
+
"wires": [["debug-ade7953-1", "format-ade7953-1"]]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"id": "format-ade7953-1",
|
|
22
|
+
"type": "function",
|
|
23
|
+
"name": "Format readings",
|
|
24
|
+
"func": "const p = msg.payload;\nmsg.payload = 'V=' + p.voltage.toFixed(2) + 'V I=' + p.current.toFixed(3) + 'A P=' + p.active_power.toFixed(2) + 'W E=' + p.active_energy.toFixed(4) + 'Wh';\nreturn msg;"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "debug-ade7953-1",
|
|
28
|
+
"type": "debug",
|
|
29
|
+
"name": "Raw measurements",
|
|
30
|
+
"active": true,
|
|
31
|
+
"tosidebar": true,
|
|
32
|
+
"console": false,
|
|
33
|
+
"tostatus": false,
|
|
34
|
+
"complete": "payload",
|
|
35
|
+
"targetType": "msg"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"id": "inject-ade7953-1",
|
|
39
|
+
"type": "inject",
|
|
40
|
+
"name": "Every 1 s",
|
|
41
|
+
"topic": "",
|
|
42
|
+
"payload": "",
|
|
43
|
+
"payloadType": "date",
|
|
44
|
+
"repeat": "1",
|
|
45
|
+
"crontab": "",
|
|
46
|
+
"once": false,
|
|
47
|
+
"onceDelay": 0.1,
|
|
48
|
+
"wires": [["ade7953-device-1"]]
|
|
49
|
+
}
|
|
50
|
+
]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script type="text/html" data-help-name="periph-ade7953">
|
|
2
|
+
<p>Reads bus voltage, load current, active power, and accumulated active
|
|
3
|
+
energy from an ADE7953 single-phase multifunction metering IC.</p>
|
|
4
|
+
<h3>Inputs</h3>
|
|
5
|
+
<dl class="message-properties">
|
|
6
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
7
|
+
<dd>Any incoming message triggers a measurement on Current Channel A.</dd>
|
|
8
|
+
</dl>
|
|
9
|
+
<h3>Outputs</h3>
|
|
10
|
+
<dl class="message-properties">
|
|
11
|
+
<dt>payload.voltage <span class="property-type">number</span></dt>
|
|
12
|
+
<dd>Bus voltage in V.</dd>
|
|
13
|
+
<dt>payload.current <span class="property-type">number</span></dt>
|
|
14
|
+
<dd>Current Channel A RMS current in A.</dd>
|
|
15
|
+
<dt>payload.active_power <span class="property-type">number</span></dt>
|
|
16
|
+
<dd>Active power in W (signed; negative = power flowing back to source).</dd>
|
|
17
|
+
<dt>payload.active_energy <span class="property-type">number</span></dt>
|
|
18
|
+
<dd>Active energy in Wh accumulated since the previous call (RSTREAD=1).</dd>
|
|
19
|
+
</dl>
|
|
20
|
+
<h3>Configuration</h3>
|
|
21
|
+
<p>Set the I²C bus number and the chip's fixed 7-bit address
|
|
22
|
+
(default <code>0x38</code>), then the calibration constants for your
|
|
23
|
+
external front end. <code>voltage_gain</code> is real volts at the
|
|
24
|
+
mains per volt at VP–VN (inverse of the external voltage divider
|
|
25
|
+
ratio); <code>current_gain</code> is real amperes per volt at IAP–IAN
|
|
26
|
+
(transconductance of the CT + burden, shunt or Rogowski front end).
|
|
27
|
+
Both must be supplied at construction — there is no universal default
|
|
28
|
+
because they depend on the external sensor network.</p>
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<script type="text/javascript">
|
|
32
|
+
RED.nodes.registerType('periph-ade7953', {
|
|
33
|
+
category: 'Periph',
|
|
34
|
+
color: '#C084FC',
|
|
35
|
+
defaults: {
|
|
36
|
+
name: { value: '' },
|
|
37
|
+
bus: { value: '1', validate: RED.validators.number() },
|
|
38
|
+
addr: { value: '0x38', validate: RED.validators.regex(/^0x[0-9a-fA-F]{1,2}$/) },
|
|
39
|
+
voltageGain: { value: '251.0', validate: RED.validators.number() },
|
|
40
|
+
currentGain: { value: '30.0', validate: RED.validators.number() },
|
|
41
|
+
},
|
|
42
|
+
inputs: 1,
|
|
43
|
+
outputs: 1,
|
|
44
|
+
icon: 'light.png',
|
|
45
|
+
label: function() {
|
|
46
|
+
return this.name || 'ADE7953';
|
|
47
|
+
},
|
|
48
|
+
labelStyle: function() {
|
|
49
|
+
return this.name ? 'node_label_italic' : '';
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
</script>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { ADE7953Full } = require('periph/src/chips/power/ade7953');
|
|
6
|
+
|
|
7
|
+
function ADE7953Node(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new I2CConnection(
|
|
12
|
+
parseInt(config.bus, 10) || 1,
|
|
13
|
+
parseInt(config.addr, 16) || 0x38
|
|
14
|
+
);
|
|
15
|
+
node.driver = new ADE7953Full(
|
|
16
|
+
connection,
|
|
17
|
+
parseFloat(config.voltageGain) || 251.0,
|
|
18
|
+
parseFloat(config.currentGain) || 30.0
|
|
19
|
+
);
|
|
20
|
+
node.connection = connection;
|
|
21
|
+
} catch (e) {
|
|
22
|
+
node.error('ADE7953 init failed: ' + e.message);
|
|
23
|
+
}
|
|
24
|
+
node.on('close', function() {
|
|
25
|
+
if (node.connection) node.connection.close();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
node.on('input', async function(msg, send, done) {
|
|
29
|
+
if (!node.driver) {
|
|
30
|
+
node.error('No ADE7953 driver', msg);
|
|
31
|
+
done();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const d = node.driver;
|
|
36
|
+
const voltage = await d.voltage();
|
|
37
|
+
const current = await d.current();
|
|
38
|
+
const activePower = await d.activePower();
|
|
39
|
+
const activeEnergy = await d.activeEnergy();
|
|
40
|
+
msg.payload = {
|
|
41
|
+
voltage: voltage,
|
|
42
|
+
current: current,
|
|
43
|
+
active_power: activePower,
|
|
44
|
+
active_energy: activeEnergy,
|
|
45
|
+
};
|
|
46
|
+
send(msg);
|
|
47
|
+
done();
|
|
48
|
+
} catch (e) {
|
|
49
|
+
done(e);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
RED.nodes.registerType('periph-ade7953', ADE7953Node);
|
|
54
|
+
};
|
package/nodes/ina219/ina219.html
CHANGED
package/nodes/ina219/ina219.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = function(RED) {
|
|
4
|
-
const {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { INA219Full } = require('periph/src/chips/power/ina219');
|
|
6
6
|
|
|
7
7
|
function INA219DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
10
|
try {
|
|
11
|
-
const
|
|
12
|
-
node.driver
|
|
13
|
-
node.
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new INA219Full(connection, parseFloat(config.rShunt), parseFloat(config.maxCurrent));
|
|
13
|
+
node.connection = connection;
|
|
14
14
|
} catch (e) {
|
|
15
15
|
node.error('INA219 init failed: ' + e.message);
|
|
16
16
|
}
|
|
17
17
|
node.on('close', function() {
|
|
18
|
-
if (node.
|
|
18
|
+
if (node.connection) node.connection.close();
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
RED.nodes.registerType('ina219-device', INA219DeviceNode);
|
|
@@ -25,7 +25,7 @@ module.exports = function(RED) {
|
|
|
25
25
|
const node = this;
|
|
26
26
|
node.device = RED.nodes.getNode(config.device);
|
|
27
27
|
|
|
28
|
-
node.on('input', function(msg, send, done) {
|
|
28
|
+
node.on('input', async function(msg, send, done) {
|
|
29
29
|
if (!node.device || !node.device.driver) {
|
|
30
30
|
node.error('No INA219 device configured', msg);
|
|
31
31
|
done();
|
|
@@ -34,10 +34,10 @@ module.exports = function(RED) {
|
|
|
34
34
|
try {
|
|
35
35
|
const d = node.device.driver;
|
|
36
36
|
msg.payload = {
|
|
37
|
-
voltage: d.voltage(),
|
|
38
|
-
current: d.current(),
|
|
39
|
-
power: d.power(),
|
|
40
|
-
shuntVoltage: d.shuntVoltage()
|
|
37
|
+
voltage: await d.voltage(),
|
|
38
|
+
current: await d.current(),
|
|
39
|
+
power: await d.power(),
|
|
40
|
+
shuntVoltage: await d.shuntVoltage()
|
|
41
41
|
};
|
|
42
42
|
send(msg);
|
|
43
43
|
done();
|
package/nodes/ina226/ina226.html
CHANGED
package/nodes/ina226/ina226.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = function(RED) {
|
|
4
|
-
const {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { INA226Full } = require('periph/src/chips/power/ina226');
|
|
6
6
|
|
|
7
7
|
function INA226DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
10
|
try {
|
|
11
|
-
const
|
|
12
|
-
node.driver
|
|
13
|
-
node.
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new INA226Full(connection, parseFloat(config.rShunt), parseFloat(config.maxCurrent));
|
|
13
|
+
node.connection = connection;
|
|
14
14
|
} catch (e) {
|
|
15
15
|
node.error('INA226 init failed: ' + e.message);
|
|
16
16
|
}
|
|
17
17
|
node.on('close', function() {
|
|
18
|
-
if (node.
|
|
18
|
+
if (node.connection) node.connection.close();
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
RED.nodes.registerType('ina226-device', INA226DeviceNode);
|
|
@@ -25,7 +25,7 @@ module.exports = function(RED) {
|
|
|
25
25
|
const node = this;
|
|
26
26
|
node.device = RED.nodes.getNode(config.device);
|
|
27
27
|
|
|
28
|
-
node.on('input', function(msg, send, done) {
|
|
28
|
+
node.on('input', async function(msg, send, done) {
|
|
29
29
|
if (!node.device || !node.device.driver) {
|
|
30
30
|
node.error('No INA226 device configured', msg);
|
|
31
31
|
done();
|
|
@@ -34,10 +34,10 @@ module.exports = function(RED) {
|
|
|
34
34
|
try {
|
|
35
35
|
const d = node.device.driver;
|
|
36
36
|
msg.payload = {
|
|
37
|
-
voltage: d.voltage(),
|
|
38
|
-
current: d.current(),
|
|
39
|
-
power: d.power(),
|
|
40
|
-
shuntVoltage: d.shuntVoltage()
|
|
37
|
+
voltage: await d.voltage(),
|
|
38
|
+
current: await d.current(),
|
|
39
|
+
power: await d.power(),
|
|
40
|
+
shuntVoltage: await d.shuntVoltage()
|
|
41
41
|
};
|
|
42
42
|
send(msg);
|
|
43
43
|
done();
|
package/nodes/ina3221/ina3221.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = function(RED) {
|
|
4
|
-
const {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
5
|
const { INA3221Full } = require('periph/src/chips/power/ina3221');
|
|
6
6
|
|
|
7
7
|
function INA3221DeviceNode(config) {
|
|
8
8
|
RED.nodes.createNode(this, config);
|
|
9
9
|
const node = this;
|
|
10
10
|
try {
|
|
11
|
-
const
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
12
|
const rShunt = config.rShunt || 0.1;
|
|
13
|
-
node.driver
|
|
14
|
-
node.
|
|
13
|
+
node.driver = new INA3221Full(connection, rShunt);
|
|
14
|
+
node.connection = connection;
|
|
15
15
|
} catch (e) {
|
|
16
16
|
node.error('INA3221 init failed: ' + e.message);
|
|
17
17
|
}
|
|
18
18
|
node.on('close', function() {
|
|
19
|
-
if (node.
|
|
19
|
+
if (node.connection) node.connection.close();
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
RED.nodes.registerType('ina3221-device', INA3221DeviceNode);
|
|
@@ -26,7 +26,7 @@ module.exports = function(RED) {
|
|
|
26
26
|
const node = this;
|
|
27
27
|
node.device = RED.nodes.getNode(config.device);
|
|
28
28
|
|
|
29
|
-
node.on('input', function(msg, send, done) {
|
|
29
|
+
node.on('input', async function(msg, send, done) {
|
|
30
30
|
if (!node.device || !node.device.driver) {
|
|
31
31
|
node.error('No INA3221 device configured', msg);
|
|
32
32
|
done();
|
|
@@ -37,10 +37,10 @@ module.exports = function(RED) {
|
|
|
37
37
|
const payload = {};
|
|
38
38
|
for (const ch of [1, 2, 3]) {
|
|
39
39
|
payload['ch' + ch] = {
|
|
40
|
-
voltage: d.voltage(ch),
|
|
41
|
-
shuntVoltage: d.shuntVoltage(ch),
|
|
42
|
-
current: d.current(ch),
|
|
43
|
-
power: d.power(ch)
|
|
40
|
+
voltage: await d.voltage(ch),
|
|
41
|
+
shuntVoltage: await d.shuntVoltage(ch),
|
|
42
|
+
current: await d.current(ch),
|
|
43
|
+
power: await d.power(ch)
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
msg.payload = payload;
|
|
@@ -52,4 +52,4 @@ module.exports = function(RED) {
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
RED.nodes.registerType('periph-ina3221', INA3221ReadNode);
|
|
55
|
-
};
|
|
55
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-power",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Node-RED nodes for power monitor chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"nodes": {
|
|
16
16
|
"ina226": "nodes/ina226/ina226.js",
|
|
17
17
|
"ina219": "nodes/ina219/ina219.js",
|
|
18
|
-
"ina3221": "nodes/ina3221/ina3221.js"
|
|
18
|
+
"ina3221": "nodes/ina3221/ina3221.js",
|
|
19
|
+
"ade7953": "nodes/ade7953/ade7953.js"
|
|
19
20
|
}
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|