node-red-contrib-periph-humidity 1.5.1 → 1.5.2

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.
@@ -1,37 +1,62 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-hs30xx', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('hs30xx-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  bus: { value: '1', required: true, validate: RED.validators.number() },
8
8
  address: { value: '0x44' }
9
9
  },
10
- inputs: 1,
11
- outputs: 1,
12
- icon: 'bridge.svg',
13
10
  label: function() {
14
- return this.name || ('HS30xx @ ' + this.address + ' (bus ' + this.bus + ')');
11
+ return this.name || ('HS30XX @ ' + this.address + ' (bus ' + this.bus + ')');
15
12
  }
16
13
  });
17
14
  </script>
18
15
 
19
- <script type="text/html" data-template-name="periph-hs30xx">
16
+ <script type="text/html" data-template-name="hs30xx-device">
20
17
  <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="HS30xx">
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="HS30XX">
23
20
  </div>
24
21
  <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)
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-address"><i class="fa fa-microchip"></i> I²C address</label>
27
+ <input type="text" id="node-config-input-address" style="width:80px" placeholder="0x44"> &nbsp;(fixed, 0x44)
28
+ </div>
29
+ </script>
30
+
31
+ <!-- Read node -->
32
+ <script type="text/javascript">
33
+ RED.nodes.registerType('hs30xx', {
34
+ category: 'Peripheral',
35
+ color: '#C084FC',
36
+ defaults: {
37
+ name: { value: '' },
38
+ device: { value: '', type: 'hs30xx-device', required: true }
39
+ },
40
+ inputs: 1,
41
+ outputs: 1,
42
+ icon: 'bridge.svg',
43
+ label: function() { return this.name || 'HS30XX'; },
44
+ paletteLabel: 'HS30XX'
45
+ });
46
+ </script>
47
+
48
+ <script type="text/html" data-template-name="hs30xx">
49
+ <div class="form-row">
50
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
51
+ <input type="text" id="node-input-name" placeholder="HS30XX">
27
52
  </div>
28
53
  <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="0x44"> &nbsp;(fixed, 0x44)
54
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
55
+ <input type="text" id="node-input-device">
31
56
  </div>
32
57
  </script>
33
58
 
34
- <script type="text/html" data-help-name="periph-hs30xx">
59
+ <script type="text/html" data-help-name="hs30xx">
35
60
  <p>Reads temperature and relative humidity from a Renesas HS3001, HS3002 or HS3003 (the HS30xx family, one
36
61
  protocol) over I²C (fixed address 0x44) with one measurement per message.</p>
37
62
  <h3>Inputs</h3>
@@ -4,7 +4,7 @@ module.exports = function(RED) {
4
4
  const { I2CConnection } = require('periph/src/connection/i2c');
5
5
  const { HS30xxMinimal } = require('periph/src/chips/humidity/hs30xx');
6
6
 
7
- function HS30xxNode(config) {
7
+ function HS30xxDeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
10
  try {
@@ -16,24 +16,31 @@ module.exports = function(RED) {
16
16
  node.error('HS30xx init failed: ' + e.message);
17
17
  }
18
18
 
19
+ node.on('close', function() {
20
+ if (node.connection) node.connection.close();
21
+ });
22
+ }
23
+ RED.nodes.registerType('hs30xx-device', HS30xxDeviceNode);
24
+
25
+ function HS30xxReadNode(config) {
26
+ RED.nodes.createNode(this, config);
27
+ const node = this;
28
+ const deviceNode = RED.nodes.getNode(config.device) || {};
29
+
19
30
  node.on('input', async function(msg, send, done) {
20
- if (!node.driver) {
31
+ if (!deviceNode.driver) {
21
32
  node.error('HS30xx not initialised', msg);
22
33
  done();
23
34
  return;
24
35
  }
25
36
  try {
26
- msg.payload = await node.driver.read();
37
+ msg.payload = await deviceNode.driver.read();
27
38
  send(msg);
28
39
  done();
29
40
  } catch (e) {
30
41
  done(e);
31
42
  }
32
43
  });
33
-
34
- node.on('close', function() {
35
- if (node.connection) node.connection.close();
36
- });
37
44
  }
38
- RED.nodes.registerType('periph-hs30xx', HS30xxNode);
45
+ RED.nodes.registerType('hs30xx', HS30xxReadNode);
39
46
  };
@@ -1,34 +1,59 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-hs40xx', {
3
+ RED.nodes.registerType('hs40xx-device', {
4
+ category: 'config',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x54' }
9
+ },
10
+ label: function() {
11
+ return this.name || ('HS40XX @ ' + this.address + ' (bus ' + this.bus + ')');
12
+ }
13
+ });
14
+ </script>
15
+
16
+ <script type="text/html" data-template-name="hs40xx-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="HS40XX">
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-address"><i class="fa fa-microchip"></i> I²C address</label>
27
+ <input type="text" id="node-config-input-address" style="width:80px" placeholder="0x54"> &nbsp;(fixed, 0x54)
28
+ </div>
29
+ </script>
30
+
31
+ <!-- Read node -->
32
+ <script type="text/javascript">
33
+ RED.nodes.registerType('hs40xx', {
3
34
  category: 'Peripheral',
4
35
  color: '#C084FC',
5
36
  defaults: {
6
37
  name: { value: '' },
7
- bus: { value: '1', required: true, validate: RED.validators.number() },
8
- address: { value: '0x54' },
38
+ device: { value: '', type: 'hs40xx-device', required: true },
9
39
  resolution: { value: '14' }
10
40
  },
11
41
  inputs: 1,
12
42
  outputs: 1,
13
43
  icon: 'bridge.svg',
14
- label: function() {
15
- return this.name || ('HS40xx @ ' + this.address + ' (bus ' + this.bus + ')');
16
- }
44
+ label: function() { return this.name || 'HS40XX'; },
45
+ paletteLabel: 'HS40XX'
17
46
  });
18
47
  </script>
19
48
 
20
- <script type="text/html" data-template-name="periph-hs40xx">
49
+ <script type="text/html" data-template-name="hs40xx">
21
50
  <div class="form-row">
22
51
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
23
- <input type="text" id="node-input-name" placeholder="HS40xx">
24
- </div>
25
- <div class="form-row">
26
- <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
27
- <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
52
+ <input type="text" id="node-input-name" placeholder="HS40XX">
28
53
  </div>
29
54
  <div class="form-row">
30
- <label for="node-input-address"><i class="fa fa-microchip"></i> I²C address</label>
31
- <input type="text" id="node-input-address" style="width:80px" placeholder="0x54"> &nbsp;(fixed, 0x54)
55
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
56
+ <input type="text" id="node-input-device">
32
57
  </div>
33
58
  <div class="form-row">
34
59
  <label for="node-input-resolution"><i class="fa fa-sliders"></i> Resolution</label>
@@ -41,7 +66,7 @@
41
66
  </div>
42
67
  </script>
43
68
 
44
- <script type="text/html" data-help-name="periph-hs40xx">
69
+ <script type="text/html" data-help-name="hs40xx">
45
70
  <p>Reads temperature and relative humidity from a Renesas HS4001 or HS4003 (the HS40xx family, one protocol)
46
71
  over I²C (fixed address 0x54) with one no-hold measurement per message. HS4002 and the HS401x variants are
47
72
  physically different versions of the same part and are not offered separately.</p>
@@ -4,7 +4,7 @@ module.exports = function(RED) {
4
4
  const { I2CConnection } = require('periph/src/connection/i2c');
5
5
  const { HS40xxFull } = require('periph/src/chips/humidity/hs40xx');
6
6
 
7
- function HS40xxNode(config) {
7
+ function HS40xxDeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
10
  try {
@@ -16,8 +16,19 @@ module.exports = function(RED) {
16
16
  node.error('HS40xx init failed: ' + e.message);
17
17
  }
18
18
 
19
+ node.on('close', function() {
20
+ if (node.connection) node.connection.close();
21
+ });
22
+ }
23
+ RED.nodes.registerType('hs40xx-device', HS40xxDeviceNode);
24
+
25
+ function HS40xxReadNode(config) {
26
+ RED.nodes.createNode(this, config);
27
+ const node = this;
28
+ const deviceNode = RED.nodes.getNode(config.device) || {};
29
+
19
30
  node.on('input', async function(msg, send, done) {
20
- if (!node.driver) {
31
+ if (!deviceNode.driver) {
21
32
  node.error('HS40xx not initialised', msg);
22
33
  done();
23
34
  return;
@@ -25,20 +36,16 @@ module.exports = function(RED) {
25
36
  try {
26
37
  if (!node.resolutionSet) {
27
38
  const bits = parseInt(config.resolution) || 14;
28
- if (bits !== 14) await node.driver.setResolution(bits, bits);
39
+ if (bits !== 14) await deviceNode.driver.setResolution(bits, bits);
29
40
  node.resolutionSet = true;
30
41
  }
31
- msg.payload = await node.driver.read();
42
+ msg.payload = await deviceNode.driver.read();
32
43
  send(msg);
33
44
  done();
34
45
  } catch (e) {
35
46
  done(e);
36
47
  }
37
48
  });
38
-
39
- node.on('close', function() {
40
- if (node.connection) node.connection.close();
41
- });
42
49
  }
43
- RED.nodes.registerType('periph-hs40xx', HS40xxNode);
50
+ RED.nodes.registerType('hs40xx', HS40xxReadNode);
44
51
  };
@@ -1,7 +1,7 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-htu21df', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('htu21df-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  bus: { value: '1', required: true, validate: RED.validators.number() },
@@ -9,31 +9,28 @@
9
9
  resolution: { value: '12/14' },
10
10
  heater: { value: false }
11
11
  },
12
- inputs: 1,
13
- outputs: 1,
14
- icon: 'bridge.svg',
15
12
  label: function() {
16
- return this.name || ('HTU21D-F @ ' + this.address + ' (bus ' + this.bus + ')');
13
+ return this.name || ('HTU21DF @ ' + this.address + ' (bus ' + this.bus + ')');
17
14
  }
18
15
  });
19
16
  </script>
20
17
 
21
- <script type="text/html" data-template-name="periph-htu21df">
18
+ <script type="text/html" data-template-name="htu21df-device">
22
19
  <div class="form-row">
23
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
24
- <input type="text" id="node-input-name" placeholder="HTU21D-F">
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="HTU21DF">
25
22
  </div>
26
23
  <div class="form-row">
27
- <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
28
- <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
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"> &nbsp;(Linux /dev/i2c-N)
29
26
  </div>
30
27
  <div class="form-row">
31
- <label for="node-input-address"><i class="fa fa-microchip"></i> I²C address</label>
32
- <input type="text" id="node-input-address" style="width:80px" placeholder="0x40"> &nbsp;(fixed, 0x40)
28
+ <label for="node-config-input-address"><i class="fa fa-microchip"></i> I²C address</label>
29
+ <input type="text" id="node-config-input-address" style="width:80px" placeholder="0x40"> &nbsp;(fixed, 0x40)
33
30
  </div>
34
31
  <div class="form-row">
35
- <label for="node-input-resolution"><i class="fa fa-cog"></i> Resolution</label>
36
- <select id="node-input-resolution" style="width:200px">
32
+ <label for="node-config-input-resolution"><i class="fa fa-cog"></i> Resolution</label>
33
+ <select id="node-config-input-resolution" style="width:200px">
37
34
  <option value="12/14" selected>RH 12 bit / T 14 bit</option>
38
35
  <option value="10/13">RH 10 bit / T 13 bit</option>
39
36
  <option value="11/11">RH 11 bit / T 11 bit</option>
@@ -41,12 +38,40 @@
41
38
  </select>
42
39
  </div>
43
40
  <div class="form-row">
44
- <label for="node-input-heater"><i class="fa fa-fire"></i> Heater</label>
45
- <input type="checkbox" id="node-input-heater" style="width:auto"> &nbsp;on-chip heater (about 5.5 mW)
41
+ <label for="node-config-input-heater"><i class="fa fa-fire"></i> Heater</label>
42
+ <input type="checkbox" id="node-config-input-heater" style="width:auto"> &nbsp;on-chip heater (about 5.5 mW)
43
+ </div>
44
+ </script>
45
+
46
+ <!-- Read node -->
47
+ <script type="text/javascript">
48
+ RED.nodes.registerType('htu21df', {
49
+ category: 'Peripheral',
50
+ color: '#C084FC',
51
+ defaults: {
52
+ name: { value: '' },
53
+ device: { value: '', type: 'htu21df-device', required: true }
54
+ },
55
+ inputs: 1,
56
+ outputs: 1,
57
+ icon: 'bridge.svg',
58
+ label: function() { return this.name || 'HTU21DF'; },
59
+ paletteLabel: 'HTU21DF'
60
+ });
61
+ </script>
62
+
63
+ <script type="text/html" data-template-name="htu21df">
64
+ <div class="form-row">
65
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
66
+ <input type="text" id="node-input-name" placeholder="HTU21DF">
67
+ </div>
68
+ <div class="form-row">
69
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
70
+ <input type="text" id="node-input-device">
46
71
  </div>
47
72
  </script>
48
73
 
49
- <script type="text/html" data-help-name="periph-htu21df">
74
+ <script type="text/html" data-help-name="htu21df">
50
75
  <p>Reads temperature and relative humidity from a Measurement Specialties HTU21D-F over I²C (fixed address 0x40)
51
76
  with one temperature and one humidity measurement per message. The CRC of both results is verified.</p>
52
77
  <h3>Inputs</h3>
@@ -6,7 +6,7 @@ module.exports = function(RED) {
6
6
 
7
7
  const RESOLUTIONS = { '12/14': 0, '8/12': 1, '10/13': 2, '11/11': 3 };
8
8
 
9
- function HTU21DFNode(config) {
9
+ function HTU21DFDeviceNode(config) {
10
10
  RED.nodes.createNode(this, config);
11
11
  const node = this;
12
12
  try {
@@ -27,15 +27,26 @@ module.exports = function(RED) {
27
27
  node.error('HTU21D-F init failed: ' + e.message);
28
28
  }
29
29
 
30
+ node.on('close', function() {
31
+ if (node.connection) node.connection.close();
32
+ });
33
+ }
34
+ RED.nodes.registerType('htu21df-device', HTU21DFDeviceNode);
35
+
36
+ function HTU21DFReadNode(config) {
37
+ RED.nodes.createNode(this, config);
38
+ const node = this;
39
+ const deviceNode = RED.nodes.getNode(config.device) || {};
40
+
30
41
  node.on('input', async function(msg, send, done) {
31
- if (!node.driver) {
42
+ if (!deviceNode.driver) {
32
43
  node.error('HTU21D-F not initialised', msg);
33
44
  done();
34
45
  return;
35
46
  }
36
47
  try {
37
- await node.ready;
38
- const [temperature_c, humidity_pct] = await node.driver.read();
48
+ await deviceNode.ready;
49
+ const [temperature_c, humidity_pct] = await deviceNode.driver.read();
39
50
  msg.payload = { temperature_c, humidity_pct };
40
51
  send(msg);
41
52
  done();
@@ -43,10 +54,6 @@ module.exports = function(RED) {
43
54
  done(e);
44
55
  }
45
56
  });
46
-
47
- node.on('close', function() {
48
- if (node.connection) node.connection.close();
49
- });
50
57
  }
51
- RED.nodes.registerType('periph-htu21df', HTU21DFNode);
58
+ RED.nodes.registerType('htu21df', HTU21DFReadNode);
52
59
  };
@@ -1,41 +1,38 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-sht31', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('sht31-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  bus: { value: '1', required: true, validate: RED.validators.number() },
8
8
  address: { value: '0x44' },
9
9
  repeatability: { value: 'high' }
10
10
  },
11
- inputs: 1,
12
- outputs: 1,
13
- icon: 'bridge.svg',
14
11
  label: function() {
15
12
  return this.name || ('SHT31 @ ' + this.address + ' (bus ' + this.bus + ')');
16
13
  }
17
14
  });
18
15
  </script>
19
16
 
20
- <script type="text/html" data-template-name="periph-sht31">
17
+ <script type="text/html" data-template-name="sht31-device">
21
18
  <div class="form-row">
22
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
23
- <input type="text" id="node-input-name" placeholder="SHT31">
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="SHT31">
24
21
  </div>
25
22
  <div class="form-row">
26
- <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
27
- <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
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"> &nbsp;(Linux /dev/i2c-N)
28
25
  </div>
29
26
  <div class="form-row">
30
- <label for="node-input-address"><i class="fa fa-microchip"></i> I²C address</label>
31
- <select id="node-input-address" style="width:160px">
27
+ <label for="node-config-input-address"><i class="fa fa-microchip"></i> I²C address</label>
28
+ <select id="node-config-input-address" style="width:160px">
32
29
  <option value="0x44" selected>0x44 (ADDR = low)</option>
33
30
  <option value="0x45">0x45 (ADDR = high)</option>
34
31
  </select>
35
32
  </div>
36
33
  <div class="form-row">
37
- <label for="node-input-repeatability"><i class="fa fa-cog"></i> Repeatability</label>
38
- <select id="node-input-repeatability" style="width:160px">
34
+ <label for="node-config-input-repeatability"><i class="fa fa-cog"></i> Repeatability</label>
35
+ <select id="node-config-input-repeatability" style="width:160px">
39
36
  <option value="high" selected>High (15 ms)</option>
40
37
  <option value="medium">Medium (6 ms)</option>
41
38
  <option value="low">Low (4 ms)</option>
@@ -43,7 +40,35 @@
43
40
  </div>
44
41
  </script>
45
42
 
46
- <script type="text/html" data-help-name="periph-sht31">
43
+ <!-- Read node -->
44
+ <script type="text/javascript">
45
+ RED.nodes.registerType('sht31', {
46
+ category: 'Peripheral',
47
+ color: '#C084FC',
48
+ defaults: {
49
+ name: { value: '' },
50
+ device: { value: '', type: 'sht31-device', required: true }
51
+ },
52
+ inputs: 1,
53
+ outputs: 1,
54
+ icon: 'bridge.svg',
55
+ label: function() { return this.name || 'SHT31'; },
56
+ paletteLabel: 'SHT31'
57
+ });
58
+ </script>
59
+
60
+ <script type="text/html" data-template-name="sht31">
61
+ <div class="form-row">
62
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
63
+ <input type="text" id="node-input-name" placeholder="SHT31">
64
+ </div>
65
+ <div class="form-row">
66
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
67
+ <input type="text" id="node-input-device">
68
+ </div>
69
+ </script>
70
+
71
+ <script type="text/html" data-help-name="sht31">
47
72
  <p>Reads temperature and relative humidity from a Sensirion SHT31 over I²C (0x44 with ADDR low, 0x45 with
48
73
  ADDR high) with one single-shot measurement per message. Both CRC bytes are verified.</p>
49
74
  <h3>Inputs</h3>
@@ -4,7 +4,7 @@ module.exports = function(RED) {
4
4
  const { I2CConnection } = require('periph/src/connection/i2c');
5
5
  const { SHT31Full } = require('periph/src/chips/humidity/sht31');
6
6
 
7
- function SHT31Node(config) {
7
+ function SHT31DeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
10
  try {
@@ -23,15 +23,26 @@ module.exports = function(RED) {
23
23
  node.error('SHT31 init failed: ' + e.message);
24
24
  }
25
25
 
26
+ node.on('close', function() {
27
+ if (node.connection) node.connection.close();
28
+ });
29
+ }
30
+ RED.nodes.registerType('sht31-device', SHT31DeviceNode);
31
+
32
+ function SHT31ReadNode(config) {
33
+ RED.nodes.createNode(this, config);
34
+ const node = this;
35
+ const deviceNode = RED.nodes.getNode(config.device) || {};
36
+
26
37
  node.on('input', async function(msg, send, done) {
27
- if (!node.driver) {
38
+ if (!deviceNode.driver) {
28
39
  node.error('SHT31 not initialised', msg);
29
40
  done();
30
41
  return;
31
42
  }
32
43
  try {
33
- await node.ready;
34
- const [temperature, humidity] = await node.driver.read();
44
+ await deviceNode.ready;
45
+ const [temperature, humidity] = await deviceNode.driver.read();
35
46
  msg.payload = { temperature, humidity };
36
47
  send(msg);
37
48
  done();
@@ -39,10 +50,6 @@ module.exports = function(RED) {
39
50
  done(e);
40
51
  }
41
52
  });
42
-
43
- node.on('close', function() {
44
- if (node.connection) node.connection.close();
45
- });
46
53
  }
47
- RED.nodes.registerType('periph-sht31', SHT31Node);
54
+ RED.nodes.registerType('sht31', SHT31ReadNode);
48
55
  };
@@ -1,7 +1,7 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-si7021', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('si7021-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  bus: { value: '1', required: true, validate: RED.validators.number() },
@@ -9,31 +9,28 @@
9
9
  resolution: { value: '12/14' },
10
10
  heater: { value: false }
11
11
  },
12
- inputs: 1,
13
- outputs: 1,
14
- icon: 'bridge.svg',
15
12
  label: function() {
16
- return this.name || ('Si7021 @ ' + this.address + ' (bus ' + this.bus + ')');
13
+ return this.name || ('SI7021 @ ' + this.address + ' (bus ' + this.bus + ')');
17
14
  }
18
15
  });
19
16
  </script>
20
17
 
21
- <script type="text/html" data-template-name="periph-si7021">
18
+ <script type="text/html" data-template-name="si7021-device">
22
19
  <div class="form-row">
23
- <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
24
- <input type="text" id="node-input-name" placeholder="Si7021">
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="SI7021">
25
22
  </div>
26
23
  <div class="form-row">
27
- <label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
28
- <input type="number" id="node-input-bus" min="0" style="width:80px"> &nbsp;(Linux /dev/i2c-N)
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"> &nbsp;(Linux /dev/i2c-N)
29
26
  </div>
30
27
  <div class="form-row">
31
- <label for="node-input-address"><i class="fa fa-microchip"></i> I²C address</label>
32
- <input type="text" id="node-input-address" style="width:80px" placeholder="0x40"> &nbsp;(fixed, 0x40)
28
+ <label for="node-config-input-address"><i class="fa fa-microchip"></i> I²C address</label>
29
+ <input type="text" id="node-config-input-address" style="width:80px" placeholder="0x40"> &nbsp;(fixed, 0x40)
33
30
  </div>
34
31
  <div class="form-row">
35
- <label for="node-input-resolution"><i class="fa fa-cog"></i> Resolution</label>
36
- <select id="node-input-resolution" style="width:200px">
32
+ <label for="node-config-input-resolution"><i class="fa fa-cog"></i> Resolution</label>
33
+ <select id="node-config-input-resolution" style="width:200px">
37
34
  <option value="12/14" selected>RH 12 bit / T 14 bit</option>
38
35
  <option value="10/13">RH 10 bit / T 13 bit</option>
39
36
  <option value="11/11">RH 11 bit / T 11 bit</option>
@@ -41,12 +38,40 @@
41
38
  </select>
42
39
  </div>
43
40
  <div class="form-row">
44
- <label for="node-input-heater"><i class="fa fa-fire"></i> Heater</label>
45
- <input type="checkbox" id="node-input-heater" style="width:auto"> &nbsp;on-chip heater (3.1 mA)
41
+ <label for="node-config-input-heater"><i class="fa fa-fire"></i> Heater</label>
42
+ <input type="checkbox" id="node-config-input-heater" style="width:auto"> &nbsp;on-chip heater (3.1 mA)
43
+ </div>
44
+ </script>
45
+
46
+ <!-- Read node -->
47
+ <script type="text/javascript">
48
+ RED.nodes.registerType('si7021', {
49
+ category: 'Peripheral',
50
+ color: '#C084FC',
51
+ defaults: {
52
+ name: { value: '' },
53
+ device: { value: '', type: 'si7021-device', required: true }
54
+ },
55
+ inputs: 1,
56
+ outputs: 1,
57
+ icon: 'bridge.svg',
58
+ label: function() { return this.name || 'SI7021'; },
59
+ paletteLabel: 'SI7021'
60
+ });
61
+ </script>
62
+
63
+ <script type="text/html" data-template-name="si7021">
64
+ <div class="form-row">
65
+ <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
66
+ <input type="text" id="node-input-name" placeholder="SI7021">
67
+ </div>
68
+ <div class="form-row">
69
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
70
+ <input type="text" id="node-input-device">
46
71
  </div>
47
72
  </script>
48
73
 
49
- <script type="text/html" data-help-name="periph-si7021">
74
+ <script type="text/html" data-help-name="si7021">
50
75
  <p>Reads relative humidity and temperature from a Silicon Labs Si7021 over I²C (fixed address 0x40) with one
51
76
  relative-humidity measurement per message; the temperature comes from the same conversion. The CRC of the
52
77
  humidity result is verified.</p>