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

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.
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { HDC1008Full } = require('periph/src/chips/humidity/hdc1008');
6
+
7
+ const RESOLUTIONS = { '14/14': [14, 14], '14/11': [14, 11], '14/8': [14, 8], '11/14': [11, 14], '11/11': [11, 11], '11/8': [11, 8] };
8
+
9
+ function HDC1008Node(config) {
10
+ RED.nodes.createNode(this, config);
11
+ const node = this;
12
+ try {
13
+ const address = parseInt(config.address, 16) || 0x40;
14
+ const connection = new I2CConnection(parseInt(config.bus), address);
15
+ node.connection = connection;
16
+ node.driver = new HDC1008Full(connection);
17
+ node.ready = (async () => {
18
+ await node.driver.init();
19
+ const res = RESOLUTIONS[config.resolution] || [14, 14];
20
+ await node.driver.setResolution(res[0], res[1]);
21
+ })();
22
+ node.ready.catch((e) => {
23
+ node.error('HDC1008 init failed: ' + e.message);
24
+ });
25
+ } catch (e) {
26
+ node.error('HDC1008 init failed: ' + e.message);
27
+ }
28
+
29
+ node.on('input', async function(msg, send, done) {
30
+ if (!node.driver) {
31
+ node.error('HDC1008 not initialised', msg);
32
+ done();
33
+ return;
34
+ }
35
+ try {
36
+ await node.ready;
37
+ const [temperature_c, humidity_pct] = await node.driver.read();
38
+ msg.payload = { temperature_c, humidity_pct };
39
+ send(msg);
40
+ done();
41
+ } catch (e) {
42
+ done(e);
43
+ }
44
+ });
45
+
46
+ node.on('close', function() {
47
+ if (node.connection) node.connection.close();
48
+ });
49
+ }
50
+ RED.nodes.registerType('periph-hdc1008', HDC1008Node);
51
+ };
@@ -0,0 +1,63 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-hdc1080', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x40' },
9
+ resolution: { value: '14/14' }
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ icon: 'bridge.svg',
14
+ label: function() {
15
+ return this.name || ('HDC1080 @ ' + this.address + ' (bus ' + this.bus + ')');
16
+ }
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="periph-hdc1080">
21
+ <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="HDC1080">
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)
28
+ </div>
29
+ <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="0x40"> &nbsp;(fixed 0x40)
32
+ </div>
33
+ <div class="form-row">
34
+ <label for="node-input-resolution"><i class="fa fa-cog"></i> Resolution</label>
35
+ <select id="node-input-resolution" style="width:200px">
36
+ <option value="14/14" selected>T 14 bit / RH 14 bit</option>
37
+ <option value="14/11">T 14 bit / RH 11 bit</option>
38
+ <option value="14/8">T 14 bit / RH 8 bit</option>
39
+ <option value="11/14">T 11 bit / RH 14 bit</option>
40
+ <option value="11/11">T 11 bit / RH 11 bit</option>
41
+ <option value="11/8">T 11 bit / RH 8 bit</option>
42
+ </select>
43
+ </div>
44
+ </script>
45
+
46
+ <script type="text/html" data-help-name="periph-hdc1080">
47
+ <p>Reads temperature and relative humidity from a Texas Instruments HDC1080 over I²C (address 0x40)
48
+ with one sequence measurement (temperature then humidity) per message.</p>
49
+ <h3>Inputs</h3>
50
+ <dl class="message-properties">
51
+ <dt>payload <span class="property-type">any</span></dt>
52
+ <dd>Any incoming message triggers one measurement.</dd>
53
+ </dl>
54
+ <h3>Outputs</h3>
55
+ <dl class="message-properties">
56
+ <dt>payload.temperature_c <span class="property-type">number</span></dt>
57
+ <dd>Temperature in °C.</dd>
58
+ <dt>payload.humidity_pct <span class="property-type">number</span></dt>
59
+ <dd>Relative humidity in %RH (0 to 100).</dd>
60
+ </dl>
61
+ <h3>Configuration</h3>
62
+ <p>I²C bus number, I²C address (0x40) and the temperature / humidity resolution (bits).</p>
63
+ </script>
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { HDC1080Full } = require('periph/src/chips/humidity/hdc1080');
6
+
7
+ const RESOLUTIONS = { '14/14': [14, 14], '14/11': [14, 11], '14/8': [14, 8], '11/14': [11, 14], '11/11': [11, 11], '11/8': [11, 8] };
8
+
9
+ function HDC1080Node(config) {
10
+ RED.nodes.createNode(this, config);
11
+ const node = this;
12
+ try {
13
+ const address = parseInt(config.address, 16) || 0x40;
14
+ const connection = new I2CConnection(parseInt(config.bus), address);
15
+ node.connection = connection;
16
+ node.driver = new HDC1080Full(connection);
17
+ node.ready = (async () => {
18
+ await node.driver.init();
19
+ const res = RESOLUTIONS[config.resolution] || [14, 14];
20
+ await node.driver.setResolution(res[0], res[1]);
21
+ })();
22
+ node.ready.catch((e) => {
23
+ node.error('HDC1080 init failed: ' + e.message);
24
+ });
25
+ } catch (e) {
26
+ node.error('HDC1080 init failed: ' + e.message);
27
+ }
28
+
29
+ node.on('input', async function(msg, send, done) {
30
+ if (!node.driver) {
31
+ node.error('HDC1080 not initialised', msg);
32
+ done();
33
+ return;
34
+ }
35
+ try {
36
+ await node.ready;
37
+ const [temperature_c, humidity_pct] = await node.driver.read();
38
+ msg.payload = { temperature_c, humidity_pct };
39
+ send(msg);
40
+ done();
41
+ } catch (e) {
42
+ done(e);
43
+ }
44
+ });
45
+
46
+ node.on('close', function() {
47
+ if (node.connection) node.connection.close();
48
+ });
49
+ }
50
+ RED.nodes.registerType('periph-hdc1080', HDC1080Node);
51
+ };
@@ -0,0 +1,53 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-hs30xx', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x44' }
9
+ },
10
+ inputs: 1,
11
+ outputs: 1,
12
+ icon: 'bridge.svg',
13
+ label: function() {
14
+ return this.name || ('HS30xx @ ' + this.address + ' (bus ' + this.bus + ')');
15
+ }
16
+ });
17
+ </script>
18
+
19
+ <script type="text/html" data-template-name="periph-hs30xx">
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="HS30xx">
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)
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="0x44"> &nbsp;(fixed, 0x44)
31
+ </div>
32
+ </script>
33
+
34
+ <script type="text/html" data-help-name="periph-hs30xx">
35
+ <p>Reads temperature and relative humidity from a Renesas HS3001, HS3002 or HS3003 (the HS30xx family, one
36
+ protocol) over I²C (fixed address 0x44) with one measurement per message.</p>
37
+ <h3>Inputs</h3>
38
+ <dl class="message-properties">
39
+ <dt>payload <span class="property-type">any</span></dt>
40
+ <dd>Any incoming message triggers one measurement (request, 40 ms wait, data fetch).</dd>
41
+ </dl>
42
+ <h3>Outputs</h3>
43
+ <dl class="message-properties">
44
+ <dt>payload.temperature_c <span class="property-type">number</span></dt>
45
+ <dd>Temperature in °C.</dd>
46
+ <dt>payload.humidity_pct <span class="property-type">number</span></dt>
47
+ <dd>Relative humidity in %RH (0 to 100).</dd>
48
+ </dl>
49
+ <h3>Configuration</h3>
50
+ <p>I²C bus number and I²C address (0x44). The node reads at the factory resolution (14 bit) and does not touch the
51
+ sensor's NVM; send no more than one message per second to keep self-heating low. A reading whose status bits
52
+ still report stale data after one retry raises an error.</p>
53
+ </script>
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { HS30xxMinimal } = require('periph/src/chips/humidity/hs30xx');
6
+
7
+ function HS30xxNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const address = parseInt(config.address, 16) || 0x44;
12
+ const connection = new I2CConnection(parseInt(config.bus), address);
13
+ node.connection = connection;
14
+ node.driver = new HS30xxMinimal(connection);
15
+ } catch (e) {
16
+ node.error('HS30xx init failed: ' + e.message);
17
+ }
18
+
19
+ node.on('input', async function(msg, send, done) {
20
+ if (!node.driver) {
21
+ node.error('HS30xx not initialised', msg);
22
+ done();
23
+ return;
24
+ }
25
+ try {
26
+ msg.payload = await node.driver.read();
27
+ send(msg);
28
+ done();
29
+ } catch (e) {
30
+ done(e);
31
+ }
32
+ });
33
+
34
+ node.on('close', function() {
35
+ if (node.connection) node.connection.close();
36
+ });
37
+ }
38
+ RED.nodes.registerType('periph-hs30xx', HS30xxNode);
39
+ };
@@ -0,0 +1,65 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-hs40xx', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x54' },
9
+ resolution: { value: '14' }
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ icon: 'bridge.svg',
14
+ label: function() {
15
+ return this.name || ('HS40xx @ ' + this.address + ' (bus ' + this.bus + ')');
16
+ }
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="periph-hs40xx">
21
+ <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="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)
28
+ </div>
29
+ <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)
32
+ </div>
33
+ <div class="form-row">
34
+ <label for="node-input-resolution"><i class="fa fa-sliders"></i> Resolution</label>
35
+ <select id="node-input-resolution" style="width:100px">
36
+ <option value="8">8 bit</option>
37
+ <option value="10">10 bit</option>
38
+ <option value="12">12 bit</option>
39
+ <option value="14">14 bit</option>
40
+ </select> &nbsp;(humidity and temperature)
41
+ </div>
42
+ </script>
43
+
44
+ <script type="text/html" data-help-name="periph-hs40xx">
45
+ <p>Reads temperature and relative humidity from a Renesas HS4001 or HS4003 (the HS40xx family, one protocol)
46
+ over I²C (fixed address 0x54) with one no-hold measurement per message. HS4002 and the HS401x variants are
47
+ physically different versions of the same part and are not offered separately.</p>
48
+ <h3>Inputs</h3>
49
+ <dl class="message-properties">
50
+ <dt>payload <span class="property-type">any</span></dt>
51
+ <dd>Any incoming message triggers one measurement (command 0xF5, 3 ms wait, 5-byte read, CRC check).</dd>
52
+ </dl>
53
+ <h3>Outputs</h3>
54
+ <dl class="message-properties">
55
+ <dt>payload.temperature_c <span class="property-type">number</span></dt>
56
+ <dd>Temperature in °C.</dd>
57
+ <dt>payload.humidity_pct <span class="property-type">number</span></dt>
58
+ <dd>Relative humidity in %RH (0 to 100).</dd>
59
+ </dl>
60
+ <h3>Configuration</h3>
61
+ <p>I²C bus number, I²C address (0x54) and the measurement resolution (8, 10, 12 or 14 bit for humidity and
62
+ temperature). A resolution other than 14 bit is written to the sensor before the first measurement; the
63
+ registers are volatile and return to 14 bit whenever the sensor loses power. A measurement whose CRC is wrong
64
+ after one retry raises an error.</p>
65
+ </script>
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { HS40xxFull } = require('periph/src/chips/humidity/hs40xx');
6
+
7
+ function HS40xxNode(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const address = parseInt(config.address, 16) || 0x54;
12
+ const connection = new I2CConnection(parseInt(config.bus), address);
13
+ node.connection = connection;
14
+ node.driver = new HS40xxFull(connection);
15
+ } catch (e) {
16
+ node.error('HS40xx init failed: ' + e.message);
17
+ }
18
+
19
+ node.on('input', async function(msg, send, done) {
20
+ if (!node.driver) {
21
+ node.error('HS40xx not initialised', msg);
22
+ done();
23
+ return;
24
+ }
25
+ try {
26
+ if (!node.resolutionSet) {
27
+ const bits = parseInt(config.resolution) || 14;
28
+ if (bits !== 14) await node.driver.setResolution(bits, bits);
29
+ node.resolutionSet = true;
30
+ }
31
+ msg.payload = await node.driver.read();
32
+ send(msg);
33
+ done();
34
+ } catch (e) {
35
+ done(e);
36
+ }
37
+ });
38
+
39
+ node.on('close', function() {
40
+ if (node.connection) node.connection.close();
41
+ });
42
+ }
43
+ RED.nodes.registerType('periph-hs40xx', HS40xxNode);
44
+ };
@@ -0,0 +1,67 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-htu21df', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x40' },
9
+ resolution: { value: '12/14' },
10
+ heater: { value: false }
11
+ },
12
+ inputs: 1,
13
+ outputs: 1,
14
+ icon: 'bridge.svg',
15
+ label: function() {
16
+ return this.name || ('HTU21D-F @ ' + this.address + ' (bus ' + this.bus + ')');
17
+ }
18
+ });
19
+ </script>
20
+
21
+ <script type="text/html" data-template-name="periph-htu21df">
22
+ <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">
25
+ </div>
26
+ <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)
29
+ </div>
30
+ <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)
33
+ </div>
34
+ <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">
37
+ <option value="12/14" selected>RH 12 bit / T 14 bit</option>
38
+ <option value="10/13">RH 10 bit / T 13 bit</option>
39
+ <option value="11/11">RH 11 bit / T 11 bit</option>
40
+ <option value="8/12">RH 8 bit / T 12 bit</option>
41
+ </select>
42
+ </div>
43
+ <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)
46
+ </div>
47
+ </script>
48
+
49
+ <script type="text/html" data-help-name="periph-htu21df">
50
+ <p>Reads temperature and relative humidity from a Measurement Specialties HTU21D-F over I²C (fixed address 0x40)
51
+ with one temperature and one humidity measurement per message. The CRC of both results is verified.</p>
52
+ <h3>Inputs</h3>
53
+ <dl class="message-properties">
54
+ <dt>payload <span class="property-type">any</span></dt>
55
+ <dd>Any incoming message triggers one measurement.</dd>
56
+ </dl>
57
+ <h3>Outputs</h3>
58
+ <dl class="message-properties">
59
+ <dt>payload.temperature_c <span class="property-type">number</span></dt>
60
+ <dd>Temperature in °C.</dd>
61
+ <dt>payload.humidity_pct <span class="property-type">number</span></dt>
62
+ <dd>Relative humidity in %RH (not clamped, -6 to 118).</dd>
63
+ </dl>
64
+ <h3>Configuration</h3>
65
+ <p>I²C bus number, I²C address (0x40), measurement resolution (RH / temperature bits) and the on-chip heater.
66
+ With the heater on, readings drift upwards; use it only to drive off condensation.</p>
67
+ </script>
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { HTU21DFFull } = require('periph/src/chips/humidity/htu21df');
6
+
7
+ const RESOLUTIONS = { '12/14': 0, '8/12': 1, '10/13': 2, '11/11': 3 };
8
+
9
+ function HTU21DFNode(config) {
10
+ RED.nodes.createNode(this, config);
11
+ const node = this;
12
+ try {
13
+ const address = parseInt(config.address, 16) || 0x40;
14
+ const connection = new I2CConnection(parseInt(config.bus), address);
15
+ node.connection = connection;
16
+ node.driver = new HTU21DFFull(connection);
17
+ node.ready = (async () => {
18
+ await node.driver.init();
19
+ const res = RESOLUTIONS[config.resolution];
20
+ await node.driver.setResolution(res === undefined ? 0 : res);
21
+ await node.driver.setHeater(config.heater === true || config.heater === 'true');
22
+ })();
23
+ node.ready.catch((e) => {
24
+ node.error('HTU21D-F init failed: ' + e.message);
25
+ });
26
+ } catch (e) {
27
+ node.error('HTU21D-F init failed: ' + e.message);
28
+ }
29
+
30
+ node.on('input', async function(msg, send, done) {
31
+ if (!node.driver) {
32
+ node.error('HTU21D-F not initialised', msg);
33
+ done();
34
+ return;
35
+ }
36
+ try {
37
+ await node.ready;
38
+ const [temperature_c, humidity_pct] = await node.driver.read();
39
+ msg.payload = { temperature_c, humidity_pct };
40
+ send(msg);
41
+ done();
42
+ } catch (e) {
43
+ done(e);
44
+ }
45
+ });
46
+
47
+ node.on('close', function() {
48
+ if (node.connection) node.connection.close();
49
+ });
50
+ }
51
+ RED.nodes.registerType('periph-htu21df', HTU21DFNode);
52
+ };
@@ -0,0 +1,64 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-sht31', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '1', required: true, validate: RED.validators.number() },
8
+ address: { value: '0x44' },
9
+ repeatability: { value: 'high' }
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ icon: 'bridge.svg',
14
+ label: function() {
15
+ return this.name || ('SHT31 @ ' + this.address + ' (bus ' + this.bus + ')');
16
+ }
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="periph-sht31">
21
+ <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">
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)
28
+ </div>
29
+ <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">
32
+ <option value="0x44" selected>0x44 (ADDR = low)</option>
33
+ <option value="0x45">0x45 (ADDR = high)</option>
34
+ </select>
35
+ </div>
36
+ <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">
39
+ <option value="high" selected>High (15 ms)</option>
40
+ <option value="medium">Medium (6 ms)</option>
41
+ <option value="low">Low (4 ms)</option>
42
+ </select>
43
+ </div>
44
+ </script>
45
+
46
+ <script type="text/html" data-help-name="periph-sht31">
47
+ <p>Reads temperature and relative humidity from a Sensirion SHT31 over I²C (0x44 with ADDR low, 0x45 with
48
+ ADDR high) with one single-shot measurement per message. Both CRC bytes are verified.</p>
49
+ <h3>Inputs</h3>
50
+ <dl class="message-properties">
51
+ <dt>payload <span class="property-type">any</span></dt>
52
+ <dd>Any incoming message triggers one measurement.</dd>
53
+ </dl>
54
+ <h3>Outputs</h3>
55
+ <dl class="message-properties">
56
+ <dt>payload.temperature <span class="property-type">number</span></dt>
57
+ <dd>Temperature in °C.</dd>
58
+ <dt>payload.humidity <span class="property-type">number</span></dt>
59
+ <dd>Relative humidity in %RH.</dd>
60
+ </dl>
61
+ <h3>Configuration</h3>
62
+ <p>I²C bus number, I²C address and the single-shot repeatability (high / medium / low; measurement time
63
+ 15 / 6 / 4 ms).</p>
64
+ </script>
@@ -0,0 +1,48 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { SHT31Full } = require('periph/src/chips/humidity/sht31');
6
+
7
+ function SHT31Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const address = parseInt(config.address, 16) || 0x44;
12
+ const connection = new I2CConnection(parseInt(config.bus), address);
13
+ node.connection = connection;
14
+ node.driver = new SHT31Full(connection);
15
+ node.ready = (async () => {
16
+ await node.driver.init();
17
+ node.driver.setRepeatability(['low', 'medium', 'high'].includes(config.repeatability) ? config.repeatability : 'high');
18
+ })();
19
+ node.ready.catch((e) => {
20
+ node.error('SHT31 init failed: ' + e.message);
21
+ });
22
+ } catch (e) {
23
+ node.error('SHT31 init failed: ' + e.message);
24
+ }
25
+
26
+ node.on('input', async function(msg, send, done) {
27
+ if (!node.driver) {
28
+ node.error('SHT31 not initialised', msg);
29
+ done();
30
+ return;
31
+ }
32
+ try {
33
+ await node.ready;
34
+ const [temperature, humidity] = await node.driver.read();
35
+ msg.payload = { temperature, humidity };
36
+ send(msg);
37
+ done();
38
+ } catch (e) {
39
+ done(e);
40
+ }
41
+ });
42
+
43
+ node.on('close', function() {
44
+ if (node.connection) node.connection.close();
45
+ });
46
+ }
47
+ RED.nodes.registerType('periph-sht31', SHT31Node);
48
+ };