node-red-contrib-periph-humidity 1.5.0 → 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.
- package/README.md +14 -3
- package/examples/dht11/demo.json +68 -6
- package/examples/hdc1008/demo.json +91 -0
- package/examples/hdc1080/demo.json +91 -0
- package/examples/hs30xx/demo.json +90 -0
- package/examples/hs40xx/demo.json +90 -0
- package/examples/htu21df/demo.json +11 -5
- package/examples/sht31/demo.json +11 -5
- package/examples/si7021/demo.json +11 -5
- package/nodes/hdc1008/hdc1008.html +88 -0
- package/nodes/hdc1008/hdc1008.js +58 -0
- package/nodes/hdc1080/hdc1080.html +88 -0
- package/nodes/hdc1080/hdc1080.js +58 -0
- package/nodes/hs30xx/hs30xx.html +78 -0
- package/nodes/hs30xx/hs30xx.js +46 -0
- package/nodes/hs40xx/hs40xx.html +90 -0
- package/nodes/hs40xx/hs40xx.js +51 -0
- package/nodes/htu21df/htu21df.html +44 -19
- package/nodes/htu21df/htu21df.js +16 -9
- package/nodes/sht31/sht31.html +41 -16
- package/nodes/sht31/sht31.js +16 -9
- package/nodes/si7021/si7021.html +44 -19
- package/nodes/si7021/si7021.js +16 -9
- package/package.json +5 -1
- package/index.js +0 -11
|
@@ -0,0 +1,58 @@
|
|
|
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 HDC1008DeviceNode(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('close', function() {
|
|
30
|
+
if (node.connection) node.connection.close();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
RED.nodes.registerType('hdc1008-device', HDC1008DeviceNode);
|
|
34
|
+
|
|
35
|
+
function HDC1008ReadNode(config) {
|
|
36
|
+
RED.nodes.createNode(this, config);
|
|
37
|
+
const node = this;
|
|
38
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
39
|
+
|
|
40
|
+
node.on('input', async function(msg, send, done) {
|
|
41
|
+
if (!deviceNode.driver) {
|
|
42
|
+
node.error('HDC1008 not initialised', msg);
|
|
43
|
+
done();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await deviceNode.ready;
|
|
48
|
+
const [temperature_c, humidity_pct] = await deviceNode.driver.read();
|
|
49
|
+
msg.payload = { temperature_c, humidity_pct };
|
|
50
|
+
send(msg);
|
|
51
|
+
done();
|
|
52
|
+
} catch (e) {
|
|
53
|
+
done(e);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
RED.nodes.registerType('hdc1008', HDC1008ReadNode);
|
|
58
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('hdc1080-device', {
|
|
4
|
+
category: 'config',
|
|
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
|
+
label: function() {
|
|
12
|
+
return this.name || ('HDC1080 @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script type="text/html" data-template-name="hdc1080-device">
|
|
18
|
+
<div class="form-row">
|
|
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="HDC1080">
|
|
21
|
+
</div>
|
|
22
|
+
<div class="form-row">
|
|
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"> (Linux /dev/i2c-N)
|
|
25
|
+
</div>
|
|
26
|
+
<div class="form-row">
|
|
27
|
+
<label for="node-config-input-address"><i class="fa fa-microchip"></i> I²C address</label>
|
|
28
|
+
<input type="text" id="node-config-input-address" style="width:80px" placeholder="0x40"> (fixed 0x40)
|
|
29
|
+
</div>
|
|
30
|
+
<div class="form-row">
|
|
31
|
+
<label for="node-config-input-resolution"><i class="fa fa-cog"></i> Resolution</label>
|
|
32
|
+
<select id="node-config-input-resolution" style="width:200px">
|
|
33
|
+
<option value="14/14" selected>T 14 bit / RH 14 bit</option>
|
|
34
|
+
<option value="14/11">T 14 bit / RH 11 bit</option>
|
|
35
|
+
<option value="14/8">T 14 bit / RH 8 bit</option>
|
|
36
|
+
<option value="11/14">T 11 bit / RH 14 bit</option>
|
|
37
|
+
<option value="11/11">T 11 bit / RH 11 bit</option>
|
|
38
|
+
<option value="11/8">T 11 bit / RH 8 bit</option>
|
|
39
|
+
</select>
|
|
40
|
+
</div>
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<!-- Read node -->
|
|
44
|
+
<script type="text/javascript">
|
|
45
|
+
RED.nodes.registerType('hdc1080', {
|
|
46
|
+
category: 'Peripheral',
|
|
47
|
+
color: '#C084FC',
|
|
48
|
+
defaults: {
|
|
49
|
+
name: { value: '' },
|
|
50
|
+
device: { value: '', type: 'hdc1080-device', required: true }
|
|
51
|
+
},
|
|
52
|
+
inputs: 1,
|
|
53
|
+
outputs: 1,
|
|
54
|
+
icon: 'bridge.svg',
|
|
55
|
+
label: function() { return this.name || 'HDC1080'; },
|
|
56
|
+
paletteLabel: 'HDC1080'
|
|
57
|
+
});
|
|
58
|
+
</script>
|
|
59
|
+
|
|
60
|
+
<script type="text/html" data-template-name="hdc1080">
|
|
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="HDC1080">
|
|
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="hdc1080">
|
|
72
|
+
<p>Reads temperature and relative humidity from a Texas Instruments HDC1080 over I²C (address 0x40)
|
|
73
|
+
with one sequence measurement (temperature then humidity) per message.</p>
|
|
74
|
+
<h3>Inputs</h3>
|
|
75
|
+
<dl class="message-properties">
|
|
76
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
77
|
+
<dd>Any incoming message triggers one measurement.</dd>
|
|
78
|
+
</dl>
|
|
79
|
+
<h3>Outputs</h3>
|
|
80
|
+
<dl class="message-properties">
|
|
81
|
+
<dt>payload.temperature_c <span class="property-type">number</span></dt>
|
|
82
|
+
<dd>Temperature in °C.</dd>
|
|
83
|
+
<dt>payload.humidity_pct <span class="property-type">number</span></dt>
|
|
84
|
+
<dd>Relative humidity in %RH (0 to 100).</dd>
|
|
85
|
+
</dl>
|
|
86
|
+
<h3>Configuration</h3>
|
|
87
|
+
<p>I²C bus number, I²C address (0x40) and the temperature / humidity resolution (bits).</p>
|
|
88
|
+
</script>
|
|
@@ -0,0 +1,58 @@
|
|
|
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 HDC1080DeviceNode(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('close', function() {
|
|
30
|
+
if (node.connection) node.connection.close();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
RED.nodes.registerType('hdc1080-device', HDC1080DeviceNode);
|
|
34
|
+
|
|
35
|
+
function HDC1080ReadNode(config) {
|
|
36
|
+
RED.nodes.createNode(this, config);
|
|
37
|
+
const node = this;
|
|
38
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
39
|
+
|
|
40
|
+
node.on('input', async function(msg, send, done) {
|
|
41
|
+
if (!deviceNode.driver) {
|
|
42
|
+
node.error('HDC1080 not initialised', msg);
|
|
43
|
+
done();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await deviceNode.ready;
|
|
48
|
+
const [temperature_c, humidity_pct] = await deviceNode.driver.read();
|
|
49
|
+
msg.payload = { temperature_c, humidity_pct };
|
|
50
|
+
send(msg);
|
|
51
|
+
done();
|
|
52
|
+
} catch (e) {
|
|
53
|
+
done(e);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
RED.nodes.registerType('hdc1080', HDC1080ReadNode);
|
|
58
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('hs30xx-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '0x44' }
|
|
9
|
+
},
|
|
10
|
+
label: function() {
|
|
11
|
+
return this.name || ('HS30XX @ ' + this.address + ' (bus ' + this.bus + ')');
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script type="text/html" data-template-name="hs30xx-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="HS30XX">
|
|
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"> (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"> (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">
|
|
52
|
+
</div>
|
|
53
|
+
<div class="form-row">
|
|
54
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
55
|
+
<input type="text" id="node-input-device">
|
|
56
|
+
</div>
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<script type="text/html" data-help-name="hs30xx">
|
|
60
|
+
<p>Reads temperature and relative humidity from a Renesas HS3001, HS3002 or HS3003 (the HS30xx family, one
|
|
61
|
+
protocol) over I²C (fixed address 0x44) with one measurement per message.</p>
|
|
62
|
+
<h3>Inputs</h3>
|
|
63
|
+
<dl class="message-properties">
|
|
64
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
65
|
+
<dd>Any incoming message triggers one measurement (request, 40 ms wait, data fetch).</dd>
|
|
66
|
+
</dl>
|
|
67
|
+
<h3>Outputs</h3>
|
|
68
|
+
<dl class="message-properties">
|
|
69
|
+
<dt>payload.temperature_c <span class="property-type">number</span></dt>
|
|
70
|
+
<dd>Temperature in °C.</dd>
|
|
71
|
+
<dt>payload.humidity_pct <span class="property-type">number</span></dt>
|
|
72
|
+
<dd>Relative humidity in %RH (0 to 100).</dd>
|
|
73
|
+
</dl>
|
|
74
|
+
<h3>Configuration</h3>
|
|
75
|
+
<p>I²C bus number and I²C address (0x44). The node reads at the factory resolution (14 bit) and does not touch the
|
|
76
|
+
sensor's NVM; send no more than one message per second to keep self-heating low. A reading whose status bits
|
|
77
|
+
still report stale data after one retry raises an error.</p>
|
|
78
|
+
</script>
|
|
@@ -0,0 +1,46 @@
|
|
|
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 HS30xxDeviceNode(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('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
|
+
|
|
30
|
+
node.on('input', async function(msg, send, done) {
|
|
31
|
+
if (!deviceNode.driver) {
|
|
32
|
+
node.error('HS30xx not initialised', msg);
|
|
33
|
+
done();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
msg.payload = await deviceNode.driver.read();
|
|
38
|
+
send(msg);
|
|
39
|
+
done();
|
|
40
|
+
} catch (e) {
|
|
41
|
+
done(e);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
RED.nodes.registerType('hs30xx', HS30xxReadNode);
|
|
46
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
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"> (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"> (fixed, 0x54)
|
|
28
|
+
</div>
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<!-- Read node -->
|
|
32
|
+
<script type="text/javascript">
|
|
33
|
+
RED.nodes.registerType('hs40xx', {
|
|
34
|
+
category: 'Peripheral',
|
|
35
|
+
color: '#C084FC',
|
|
36
|
+
defaults: {
|
|
37
|
+
name: { value: '' },
|
|
38
|
+
device: { value: '', type: 'hs40xx-device', required: true },
|
|
39
|
+
resolution: { value: '14' }
|
|
40
|
+
},
|
|
41
|
+
inputs: 1,
|
|
42
|
+
outputs: 1,
|
|
43
|
+
icon: 'bridge.svg',
|
|
44
|
+
label: function() { return this.name || 'HS40XX'; },
|
|
45
|
+
paletteLabel: 'HS40XX'
|
|
46
|
+
});
|
|
47
|
+
</script>
|
|
48
|
+
|
|
49
|
+
<script type="text/html" data-template-name="hs40xx">
|
|
50
|
+
<div class="form-row">
|
|
51
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
52
|
+
<input type="text" id="node-input-name" placeholder="HS40XX">
|
|
53
|
+
</div>
|
|
54
|
+
<div class="form-row">
|
|
55
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
56
|
+
<input type="text" id="node-input-device">
|
|
57
|
+
</div>
|
|
58
|
+
<div class="form-row">
|
|
59
|
+
<label for="node-input-resolution"><i class="fa fa-sliders"></i> Resolution</label>
|
|
60
|
+
<select id="node-input-resolution" style="width:100px">
|
|
61
|
+
<option value="8">8 bit</option>
|
|
62
|
+
<option value="10">10 bit</option>
|
|
63
|
+
<option value="12">12 bit</option>
|
|
64
|
+
<option value="14">14 bit</option>
|
|
65
|
+
</select> (humidity and temperature)
|
|
66
|
+
</div>
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<script type="text/html" data-help-name="hs40xx">
|
|
70
|
+
<p>Reads temperature and relative humidity from a Renesas HS4001 or HS4003 (the HS40xx family, one protocol)
|
|
71
|
+
over I²C (fixed address 0x54) with one no-hold measurement per message. HS4002 and the HS401x variants are
|
|
72
|
+
physically different versions of the same part and are not offered separately.</p>
|
|
73
|
+
<h3>Inputs</h3>
|
|
74
|
+
<dl class="message-properties">
|
|
75
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
76
|
+
<dd>Any incoming message triggers one measurement (command 0xF5, 3 ms wait, 5-byte read, CRC check).</dd>
|
|
77
|
+
</dl>
|
|
78
|
+
<h3>Outputs</h3>
|
|
79
|
+
<dl class="message-properties">
|
|
80
|
+
<dt>payload.temperature_c <span class="property-type">number</span></dt>
|
|
81
|
+
<dd>Temperature in °C.</dd>
|
|
82
|
+
<dt>payload.humidity_pct <span class="property-type">number</span></dt>
|
|
83
|
+
<dd>Relative humidity in %RH (0 to 100).</dd>
|
|
84
|
+
</dl>
|
|
85
|
+
<h3>Configuration</h3>
|
|
86
|
+
<p>I²C bus number, I²C address (0x54) and the measurement resolution (8, 10, 12 or 14 bit for humidity and
|
|
87
|
+
temperature). A resolution other than 14 bit is written to the sensor before the first measurement; the
|
|
88
|
+
registers are volatile and return to 14 bit whenever the sensor loses power. A measurement whose CRC is wrong
|
|
89
|
+
after one retry raises an error.</p>
|
|
90
|
+
</script>
|
|
@@ -0,0 +1,51 @@
|
|
|
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 HS40xxDeviceNode(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('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
|
+
|
|
30
|
+
node.on('input', async function(msg, send, done) {
|
|
31
|
+
if (!deviceNode.driver) {
|
|
32
|
+
node.error('HS40xx not initialised', msg);
|
|
33
|
+
done();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
if (!node.resolutionSet) {
|
|
38
|
+
const bits = parseInt(config.resolution) || 14;
|
|
39
|
+
if (bits !== 14) await deviceNode.driver.setResolution(bits, bits);
|
|
40
|
+
node.resolutionSet = true;
|
|
41
|
+
}
|
|
42
|
+
msg.payload = await deviceNode.driver.read();
|
|
43
|
+
send(msg);
|
|
44
|
+
done();
|
|
45
|
+
} catch (e) {
|
|
46
|
+
done(e);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
RED.nodes.registerType('hs40xx', HS40xxReadNode);
|
|
51
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
1
2
|
<script type="text/javascript">
|
|
2
|
-
RED.nodes.registerType('
|
|
3
|
-
category:
|
|
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 || ('
|
|
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="
|
|
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="
|
|
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"> (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"> (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"> (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"> (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"> 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"> 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="
|
|
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>
|
package/nodes/htu21df/htu21df.js
CHANGED
|
@@ -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
|
|
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 (!
|
|
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
|
|
38
|
-
const [temperature_c, humidity_pct] = await
|
|
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('
|
|
58
|
+
RED.nodes.registerType('htu21df', HTU21DFReadNode);
|
|
52
59
|
};
|