node-red-contrib-periph-environmental 1.4.0 → 1.5.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 CHANGED
@@ -18,6 +18,7 @@ npm install node-red-contrib-periph-environmental
18
18
  |------|------|-------------|
19
19
  | `aht21-device` | config | I²C bus and address for an AHT21 |
20
20
  | `aht21` | input | Reads temperature and humidity from an AHT21 environmental sensor over I²C. |
21
+ | `periph-am2315` | input | Reads temperature and relative humidity from an Aosong AM2315 over I²C (fixed address 0x5C). The sensor sleeps between transactions and returns the result of the previous measurement; the node keeps transactions at least 2 s apart, so a message arriving earlier is answered after the remaining delay. Every response is CRC-16 checked. |
21
22
  | `bme280-device` | config | Bus configuration for a BME280 |
22
23
  | `periph-bme280` | input | Reads temperature, pressure, humidity, altitude, and dew point from a BME280 combined humidity + pressure + temperature sensor. |
23
24
  | `bme680-device` | config | Bus configuration for a BME680 |
@@ -0,0 +1,84 @@
1
+ [
2
+ {
3
+ "id": "am2315-tab",
4
+ "type": "tab",
5
+ "label": "AM2315 humidity logger",
6
+ "disabled": false,
7
+ "info": "Reads temperature and relative humidity from an AM2315 every 5 s and formats them. The sensor returns the previous measurement on every read and needs at least 2 s between transactions; each response is CRC-16 checked."
8
+ },
9
+ {
10
+ "id": "am2315-inject",
11
+ "type": "inject",
12
+ "z": "am2315-tab",
13
+ "name": "5 s timer",
14
+ "props": [
15
+ {
16
+ "p": "payload"
17
+ }
18
+ ],
19
+ "repeat": "5",
20
+ "crontab": "",
21
+ "once": false,
22
+ "onceDelay": 0.1,
23
+ "topic": "",
24
+ "payloadType": "date",
25
+ "x": 160,
26
+ "y": 160,
27
+ "wires": [
28
+ [
29
+ "am2315-node"
30
+ ]
31
+ ]
32
+ },
33
+ {
34
+ "id": "am2315-node",
35
+ "type": "periph-am2315",
36
+ "z": "am2315-tab",
37
+ "name": "AM2315",
38
+ "bus": "1",
39
+ "address": "0x5C",
40
+ "x": 380,
41
+ "y": 160,
42
+ "wires": [
43
+ [
44
+ "am2315-format"
45
+ ]
46
+ ]
47
+ },
48
+ {
49
+ "id": "am2315-format",
50
+ "type": "function",
51
+ "z": "am2315-tab",
52
+ "name": "Format",
53
+ "func": "msg.payload = msg.payload.temperature_c.toFixed(1) + ' °C / ' + msg.payload.humidity_pct.toFixed(1) + ' %RH';\nreturn msg;",
54
+ "outputs": 1,
55
+ "noerr": 0,
56
+ "initialize": "",
57
+ "finalize": "",
58
+ "libs": [],
59
+ "x": 600,
60
+ "y": 160,
61
+ "wires": [
62
+ [
63
+ "am2315-debug"
64
+ ]
65
+ ]
66
+ },
67
+ {
68
+ "id": "am2315-debug",
69
+ "type": "debug",
70
+ "z": "am2315-tab",
71
+ "name": "Reading",
72
+ "active": true,
73
+ "tosidebar": true,
74
+ "console": false,
75
+ "tostatus": false,
76
+ "complete": "payload",
77
+ "targetType": "msg",
78
+ "statusVal": "",
79
+ "statusType": "auto",
80
+ "x": 800,
81
+ "y": 160,
82
+ "wires": []
83
+ }
84
+ ]
@@ -0,0 +1,53 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-am2315', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x5C' }
9
+ },
10
+ inputs: 1,
11
+ outputs: 1,
12
+ icon: 'bridge.svg',
13
+ label: function() {
14
+ return this.name || ('AM2315 @ ' + this.address + ' (bus ' + this.bus + ')');
15
+ }
16
+ });
17
+ </script>
18
+
19
+ <script type="text/html" data-template-name="periph-am2315">
20
+ <div class="form-row">
21
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
22
+ <input type="text" id="node-input-name" placeholder="AM2315">
23
+ </div>
24
+ <div class="form-row">
25
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
26
+ <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N, standard mode)
27
+ </div>
28
+ <div class="form-row">
29
+ <label for="node-input-address"><i class="fa fa-microchip"></i> I²C address</label>
30
+ <input type="text" id="node-input-address" style="width:80px" placeholder="0x5C"> &nbsp;(fixed, 0x5C)
31
+ </div>
32
+ </script>
33
+
34
+ <script type="text/html" data-help-name="periph-am2315">
35
+ <p>Reads temperature and relative humidity from an Aosong AM2315 over I²C (fixed address 0x5C). The sensor
36
+ sleeps between transactions and returns the result of the <em>previous</em> measurement; the node keeps
37
+ transactions at least 2 s apart, so a message arriving earlier is answered after the remaining delay.
38
+ Every response is CRC-16 checked.</p>
39
+ <h3>Inputs</h3>
40
+ <dl class="message-properties">
41
+ <dt>payload <span class="property-type">any</span></dt>
42
+ <dd>Any incoming message triggers one reading.</dd>
43
+ </dl>
44
+ <h3>Outputs</h3>
45
+ <dl class="message-properties">
46
+ <dt>payload.temperature_c <span class="property-type">number</span></dt>
47
+ <dd>Temperature in °C (−40 to 125).</dd>
48
+ <dt>payload.humidity_pct <span class="property-type">number</span></dt>
49
+ <dd>Relative humidity in %RH (0 to 99.9).</dd>
50
+ </dl>
51
+ <h3>Configuration</h3>
52
+ <p>I²C bus number and I²C address (0x5C). The bus must run at 100 kHz or less.</p>
53
+ </script>
@@ -0,0 +1,43 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { AM2315Full } = require('periph/src/chips/environmental/am2315');
6
+
7
+ function AM2315Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const address = parseInt(config.address, 16) || 0x5C;
12
+ const connection = new I2CConnection(parseInt(config.bus), address);
13
+ node.connection = connection;
14
+ node.driver = new AM2315Full(connection);
15
+ } catch (e) {
16
+ node.error('AM2315 init failed: ' + e.message);
17
+ }
18
+
19
+ // Messages are handled one at a time; the driver itself waits the >= 2 s between transactions.
20
+ let queue = Promise.resolve();
21
+ node.on('input', function(msg, send, done) {
22
+ if (!node.driver) {
23
+ node.error('AM2315 not initialised', msg);
24
+ done();
25
+ return;
26
+ }
27
+ queue = queue.then(async () => {
28
+ try {
29
+ msg.payload = await node.driver.read();
30
+ send(msg);
31
+ done();
32
+ } catch (e) {
33
+ done(e);
34
+ }
35
+ });
36
+ });
37
+
38
+ node.on('close', function() {
39
+ if (node.connection) node.connection.close();
40
+ });
41
+ }
42
+ RED.nodes.registerType('periph-am2315', AM2315Node);
43
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-environmental",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "Node-RED nodes for environmental sensor chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -14,6 +14,7 @@
14
14
  "node-red": {
15
15
  "nodes": {
16
16
  "aht21": "nodes/aht21/aht21.js",
17
+ "am2315": "nodes/am2315/am2315.js",
17
18
  "bme280": "nodes/bme280/bme280.js",
18
19
  "bme680": "nodes/bme680/bme680.js"
19
20
  }