node-red-contrib-periph-environmental 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 +16 -3
- package/nodes/aht21/aht21.html +1 -1
- package/nodes/aht21/aht21.js +7 -7
- package/nodes/bme280/bme280.html +1 -1
- package/nodes/bme280/bme280.js +9 -9
- package/nodes/bme680/bme680.html +1 -1
- package/nodes/bme680/bme680.js +7 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,15 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
Node-RED nodes for environmental sensor chips — part of the [Periph](https://github.com/tuhde/Periph) library.
|
|
4
4
|
|
|
5
|
-
> **Coming soon.** Nodes will be added as chips in this category are implemented.
|
|
6
|
-
|
|
7
5
|
## Install
|
|
8
6
|
|
|
7
|
+
Open Node-RED, go to **Manage Palette → Install** and search for `node-red-contrib-periph-environmental`.
|
|
8
|
+
|
|
9
|
+
Or from the command line in your Node-RED user directory:
|
|
10
|
+
|
|
9
11
|
```sh
|
|
10
12
|
npm install node-red-contrib-periph-environmental
|
|
11
13
|
```
|
|
12
14
|
|
|
15
|
+
## Nodes
|
|
16
|
+
|
|
17
|
+
| Node | Kind | Description |
|
|
18
|
+
|------|------|-------------|
|
|
19
|
+
| `aht21-device` | config | I²C bus and address for an AHT21 |
|
|
20
|
+
| `aht21` | input | Reads temperature and humidity from an AHT21 environmental sensor over I²C. |
|
|
21
|
+
| `bme280-device` | config | Bus configuration for a BME280 |
|
|
22
|
+
| `periph-bme280` | input | Reads temperature, pressure, humidity, altitude, and dew point from a BME280 combined humidity + pressure + temperature sensor. |
|
|
23
|
+
| `bme680-device` | config | Bus configuration for a BME680 |
|
|
24
|
+
| `periph-bme680` | input | Reads temperature, pressure, humidity, gas resistance, altitude, and dew point from a BME680 4-in-1 environmental sensor. |
|
|
25
|
+
|
|
13
26
|
## Links
|
|
14
27
|
|
|
15
28
|
- [GitHub](https://github.com/tuhde/Periph)
|
|
16
|
-
- [
|
|
29
|
+
- [periph JS driver](https://www.npmjs.com/package/periph)
|
package/nodes/aht21/aht21.html
CHANGED
package/nodes/aht21/aht21.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 { AHT21Full } = require('periph/src/chips/environmental/aht21');
|
|
6
6
|
|
|
7
7
|
function AHT21DeviceNode(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 AHT21Full(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
14
|
} catch (e) {
|
|
15
15
|
node.error('AHT21 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('aht21-device', AHT21DeviceNode);
|
|
@@ -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 AHT21 device configured', msg);
|
|
31
31
|
done();
|
|
@@ -33,7 +33,7 @@ module.exports = function(RED) {
|
|
|
33
33
|
}
|
|
34
34
|
try {
|
|
35
35
|
const d = node.device.driver;
|
|
36
|
-
const r = d.read();
|
|
36
|
+
const r = await d.read();
|
|
37
37
|
msg.payload = {
|
|
38
38
|
temperature_c: r.temperature_c,
|
|
39
39
|
humidity_pct: r.humidity_pct
|
package/nodes/bme280/bme280.html
CHANGED
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
<script type="text/javascript">
|
|
106
106
|
RED.nodes.registerType('periph-bme280', {
|
|
107
107
|
category: 'Peripheral',
|
|
108
|
-
color: '#
|
|
108
|
+
color: '#C084FC',
|
|
109
109
|
defaults: {
|
|
110
110
|
name: { value: '' },
|
|
111
111
|
device: { value: '', type: 'bme280-device', required: true },
|
package/nodes/bme280/bme280.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 { BME280Full } = require('periph/src/chips/environmental/bme280');
|
|
6
6
|
|
|
7
7
|
function BME280DeviceNode(config) {
|
|
@@ -9,8 +9,8 @@ module.exports = function(RED) {
|
|
|
9
9
|
const node = this;
|
|
10
10
|
try {
|
|
11
11
|
const addr = parseInt(config.addr) || 0x76;
|
|
12
|
-
const
|
|
13
|
-
node.driver = new BME280Full(
|
|
12
|
+
const connection = new I2CConnection(parseInt(config.bus), addr);
|
|
13
|
+
node.driver = new BME280Full(connection);
|
|
14
14
|
node.driver.configure(
|
|
15
15
|
parseInt(config.osrsT) || 1,
|
|
16
16
|
parseInt(config.osrsP) || 1,
|
|
@@ -19,12 +19,12 @@ module.exports = function(RED) {
|
|
|
19
19
|
parseInt(config.filter) || 0,
|
|
20
20
|
parseInt(config.tSb) || 0
|
|
21
21
|
);
|
|
22
|
-
node.
|
|
22
|
+
node.connection = connection;
|
|
23
23
|
} catch (e) {
|
|
24
24
|
node.error('BME280 init failed: ' + e.message);
|
|
25
25
|
}
|
|
26
26
|
node.on('close', function() {
|
|
27
|
-
if (node.
|
|
27
|
+
if (node.connection) node.connection.close();
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
RED.nodes.registerType('bme280-device', BME280DeviceNode);
|
|
@@ -34,7 +34,7 @@ module.exports = function(RED) {
|
|
|
34
34
|
const node = this;
|
|
35
35
|
node.device = RED.nodes.getNode(config.device);
|
|
36
36
|
|
|
37
|
-
node.on('input', function(msg, send, done) {
|
|
37
|
+
node.on('input', async function(msg, send, done) {
|
|
38
38
|
if (!node.device || !node.device.driver) {
|
|
39
39
|
node.error('No BME280 device configured', msg);
|
|
40
40
|
done();
|
|
@@ -42,9 +42,9 @@ module.exports = function(RED) {
|
|
|
42
42
|
}
|
|
43
43
|
try {
|
|
44
44
|
const d = node.device.driver;
|
|
45
|
-
const t = d.temperature();
|
|
46
|
-
const p = d.pressure();
|
|
47
|
-
const h = d.humidity();
|
|
45
|
+
const t = await d.temperature();
|
|
46
|
+
const p = await d.pressure();
|
|
47
|
+
const h = await d.humidity();
|
|
48
48
|
const seaLevelHpa = parseFloat(config.seaLevelHpa) || 1013.25;
|
|
49
49
|
const altitude = 44330 * (1 - Math.pow(p / seaLevelHpa, 1 / 5.255));
|
|
50
50
|
const a = 17.27, b = 237.7;
|
package/nodes/bme680/bme680.html
CHANGED
package/nodes/bme680/bme680.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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 { BME680Full } = require('periph/src/chips/environmental/bme680');
|
|
6
6
|
|
|
7
7
|
function BME680DeviceNode(config) {
|
|
@@ -9,8 +9,8 @@ module.exports = function(RED) {
|
|
|
9
9
|
const node = this;
|
|
10
10
|
try {
|
|
11
11
|
const addr = parseInt(config.addr) || 0x76;
|
|
12
|
-
const
|
|
13
|
-
node.driver = new BME680Full(
|
|
12
|
+
const connection = new I2CConnection(parseInt(config.bus), addr);
|
|
13
|
+
node.driver = new BME680Full(connection);
|
|
14
14
|
node.driver.configure(
|
|
15
15
|
parseInt(config.osrsT) || 1,
|
|
16
16
|
parseInt(config.osrsP) || 1,
|
|
@@ -22,12 +22,12 @@ module.exports = function(RED) {
|
|
|
22
22
|
parseInt(config.heaterTemp) || 320,
|
|
23
23
|
parseInt(config.heaterDur) || 150
|
|
24
24
|
);
|
|
25
|
-
node.
|
|
25
|
+
node.connection = connection;
|
|
26
26
|
} catch (e) {
|
|
27
27
|
node.error('BME680 init failed: ' + e.message);
|
|
28
28
|
}
|
|
29
29
|
node.on('close', function() {
|
|
30
|
-
if (node.
|
|
30
|
+
if (node.connection) node.connection.close();
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
RED.nodes.registerType('bme680-device', BME680DeviceNode);
|
|
@@ -37,7 +37,7 @@ module.exports = function(RED) {
|
|
|
37
37
|
const node = this;
|
|
38
38
|
node.device = RED.nodes.getNode(config.device);
|
|
39
39
|
|
|
40
|
-
node.on('input', function(msg, send, done) {
|
|
40
|
+
node.on('input', async function(msg, send, done) {
|
|
41
41
|
if (!node.device || !node.device.driver) {
|
|
42
42
|
node.error('No BME680 device configured', msg);
|
|
43
43
|
done();
|
|
@@ -45,7 +45,7 @@ module.exports = function(RED) {
|
|
|
45
45
|
}
|
|
46
46
|
try {
|
|
47
47
|
const d = node.device.driver;
|
|
48
|
-
const r = d.readAll();
|
|
48
|
+
const r = await d.readAll();
|
|
49
49
|
const seaLevelHpa = parseFloat(config.seaLevelHpa) || 1013.25;
|
|
50
50
|
const altitude = 44330 * (1 - Math.pow(r.pressure / seaLevelHpa, 1 / 5.255));
|
|
51
51
|
const a = 17.62, b = 243.12;
|