node-red-contrib-periph-temperature 1.1.0 → 1.2.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.
- package/README.md +12 -3
- package/examples/mcp9808/demo.json +86 -0
- package/examples/tmp117/demo.json +100 -0
- package/nodes/mcp9808/mcp9808.html +126 -0
- package/nodes/mcp9808/mcp9808.js +77 -0
- package/nodes/tmp117/tmp117.html +121 -0
- package/nodes/tmp117/tmp117.js +78 -0
- package/package.json +5 -2
- package/examples/.gitkeep +0 -0
- package/nodes/.gitkeep +0 -0
package/README.md
CHANGED
|
@@ -2,15 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
Node-RED nodes for temperature 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-temperature`.
|
|
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-temperature
|
|
11
13
|
```
|
|
12
14
|
|
|
15
|
+
## Nodes
|
|
16
|
+
|
|
17
|
+
| Node | Kind | Description |
|
|
18
|
+
|------|------|-------------|
|
|
19
|
+
| `periph-mcp9808` | input | Reads the ambient temperature from an MCP9808 ±0.5 °C digital temperature sensor over I²C, and optionally reports its TUPPER/TLOWER/TCRIT boundary alerts. |
|
|
20
|
+
| `periph-tmp117` | input | Reads the temperature from a TMP117 ±0.1 °C high-accuracy digital temperature sensor over I²C, and optionally reports its THIGH/TLOW limit alerts. |
|
|
21
|
+
|
|
13
22
|
## Links
|
|
14
23
|
|
|
15
24
|
- [GitHub](https://github.com/tuhde/Periph)
|
|
16
|
-
- [
|
|
25
|
+
- [periph JS driver](https://www.npmjs.com/package/periph)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-mcp9808-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "MCP9808 Freezer Monitor Demo",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "An Inject node fires every 5 seconds, triggering the periph-mcp9808 node to read the temperature and Alert status, which a Function node formats into a log line. The node is configured with TCRIT at -5 °C — the \"too warm, door left open\" threshold for a freezer — with the Alert source set to TCRIT only and the Alert in latched interrupt mode. When the freezer warms past TCRIT the node emits a separate {source: \"critical\"} message; the Function node turns it into an alarm notification on the Debug sidebar and sends {clear_interrupt: true} back into the node to re-arm the latched Alert. To try it without a freezer, raise TCRIT just above room temperature and warm the sensor with a fingertip."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "inj-read",
|
|
11
|
+
"type": "inject",
|
|
12
|
+
"name": "Read temperature (5s)",
|
|
13
|
+
"topic": "",
|
|
14
|
+
"payload": "",
|
|
15
|
+
"payloadType": "date",
|
|
16
|
+
"repeat": "5",
|
|
17
|
+
"crontab": "",
|
|
18
|
+
"once": true,
|
|
19
|
+
"onceDelay": 1,
|
|
20
|
+
"z": "tab-mcp9808-demo",
|
|
21
|
+
"x": 160,
|
|
22
|
+
"y": 100,
|
|
23
|
+
"wires": [
|
|
24
|
+
[
|
|
25
|
+
"mcp9808-node"
|
|
26
|
+
]
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "mcp9808-node",
|
|
31
|
+
"type": "periph-mcp9808",
|
|
32
|
+
"name": "Freezer MCP9808",
|
|
33
|
+
"bus": "1",
|
|
34
|
+
"address": "0x18",
|
|
35
|
+
"resolution": "0.25",
|
|
36
|
+
"alertEnabled": true,
|
|
37
|
+
"upperLimit": "-15",
|
|
38
|
+
"lowerLimit": "-25",
|
|
39
|
+
"criticalLimit": "-5",
|
|
40
|
+
"hysteresis": "3",
|
|
41
|
+
"alertMode": "critical_only",
|
|
42
|
+
"alertOutput": "interrupt",
|
|
43
|
+
"z": "tab-mcp9808-demo",
|
|
44
|
+
"x": 400,
|
|
45
|
+
"y": 100,
|
|
46
|
+
"wires": [
|
|
47
|
+
[
|
|
48
|
+
"fn-alarm"
|
|
49
|
+
]
|
|
50
|
+
]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"id": "fn-alarm",
|
|
54
|
+
"type": "function",
|
|
55
|
+
"name": "format reading / raise alarm",
|
|
56
|
+
"func": "const p = msg.payload;\nif (p && p.source === 'critical') {\n // Alarm, then re-arm the latched interrupt-mode Alert.\n return [{ payload: 'ALARM: freezer above -5 °C - door left open?' },\n { payload: { clear_interrupt: true } }];\n}\nif (p && p.temperature_c !== undefined) {\n msg.payload = `${p.temperature_c.toFixed(2)} °C` + (p.alert_asserted ? ' (alert asserted)' : '');\n return [msg, null];\n}\nreturn null;",
|
|
57
|
+
"outputs": 2,
|
|
58
|
+
"noerr": 0,
|
|
59
|
+
"z": "tab-mcp9808-demo",
|
|
60
|
+
"x": 650,
|
|
61
|
+
"y": 100,
|
|
62
|
+
"wires": [
|
|
63
|
+
[
|
|
64
|
+
"debug-log"
|
|
65
|
+
],
|
|
66
|
+
[
|
|
67
|
+
"mcp9808-node"
|
|
68
|
+
]
|
|
69
|
+
]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
"id": "debug-log",
|
|
73
|
+
"type": "debug",
|
|
74
|
+
"name": "Freezer log",
|
|
75
|
+
"active": true,
|
|
76
|
+
"tosidebar": true,
|
|
77
|
+
"console": false,
|
|
78
|
+
"tostatus": false,
|
|
79
|
+
"complete": "payload",
|
|
80
|
+
"targetType": "msg",
|
|
81
|
+
"z": "tab-mcp9808-demo",
|
|
82
|
+
"x": 890,
|
|
83
|
+
"y": 100,
|
|
84
|
+
"wires": []
|
|
85
|
+
}
|
|
86
|
+
]
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-tmp117-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "TMP117 Server Room Cooling Demo",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "An Inject node fires every 5 seconds, triggering the periph-tmp117 node to read the temperature and its alert flags, which a Function node formats into a log line. The node is configured in Therm mode with THIGH at 30 °C — a server-room \"too hot\" threshold — and TLOW at 27 °C. When the room heats past THIGH the node emits a separate {source: \"high\"} message and the Function node switches the cooling fan on through the second output. In Therm mode the HIGH_Alert flag latches until the room cools below TLOW, so the periodic reading's high_alert field keeps the fan running and switches it off again automatically once the room is back below 27 °C. Replace the \"Cooling fan\" Debug node with a GPIO or relay node to drive a real fan. To try it without a server room, set THIGH just above room temperature and warm the sensor with a fingertip."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "inj-read",
|
|
11
|
+
"type": "inject",
|
|
12
|
+
"name": "Read temperature (5s)",
|
|
13
|
+
"topic": "",
|
|
14
|
+
"payload": "",
|
|
15
|
+
"payloadType": "date",
|
|
16
|
+
"repeat": "5",
|
|
17
|
+
"crontab": "",
|
|
18
|
+
"once": true,
|
|
19
|
+
"onceDelay": 1,
|
|
20
|
+
"z": "tab-tmp117-demo",
|
|
21
|
+
"x": 160,
|
|
22
|
+
"y": 100,
|
|
23
|
+
"wires": [
|
|
24
|
+
[
|
|
25
|
+
"tmp117-node"
|
|
26
|
+
]
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"id": "tmp117-node",
|
|
31
|
+
"type": "periph-tmp117",
|
|
32
|
+
"name": "Server room TMP117",
|
|
33
|
+
"bus": "1",
|
|
34
|
+
"address": "0x48",
|
|
35
|
+
"averaging": "8",
|
|
36
|
+
"cycleSeconds": "1",
|
|
37
|
+
"alertEnabled": true,
|
|
38
|
+
"highLimit": "30",
|
|
39
|
+
"lowLimit": "27",
|
|
40
|
+
"alertMode": "therm",
|
|
41
|
+
"polarity": "active_low",
|
|
42
|
+
"z": "tab-tmp117-demo",
|
|
43
|
+
"x": 400,
|
|
44
|
+
"y": 100,
|
|
45
|
+
"wires": [
|
|
46
|
+
[
|
|
47
|
+
"fn-fan"
|
|
48
|
+
]
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"id": "fn-fan",
|
|
53
|
+
"type": "function",
|
|
54
|
+
"name": "format reading / drive fan",
|
|
55
|
+
"func": "const p = msg.payload;\nif (p && p.source === 'high') {\n // Therm-mode HIGH_Alert tripped: room above THIGH, start cooling.\n return [{ payload: 'ALERT: server room above 30 °C' }, { payload: true }];\n}\nif (p && p.temperature_c !== undefined) {\n // HIGH_Alert stays latched in Therm mode until the room drops below\n // TLOW, so it doubles as the fan state and switches the fan off again.\n msg.payload = `${p.temperature_c.toFixed(3)} °C` + (p.high_alert ? ' (cooling)' : '');\n return [msg, { payload: p.high_alert }];\n}\nreturn null;",
|
|
56
|
+
"outputs": 2,
|
|
57
|
+
"noerr": 0,
|
|
58
|
+
"z": "tab-tmp117-demo",
|
|
59
|
+
"x": 650,
|
|
60
|
+
"y": 100,
|
|
61
|
+
"wires": [
|
|
62
|
+
[
|
|
63
|
+
"dbg-log"
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
"dbg-fan"
|
|
67
|
+
]
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"id": "dbg-log",
|
|
72
|
+
"type": "debug",
|
|
73
|
+
"name": "Temperature log",
|
|
74
|
+
"active": true,
|
|
75
|
+
"tosidebar": true,
|
|
76
|
+
"console": false,
|
|
77
|
+
"tostatus": false,
|
|
78
|
+
"complete": "payload",
|
|
79
|
+
"targetType": "msg",
|
|
80
|
+
"z": "tab-tmp117-demo",
|
|
81
|
+
"x": 900,
|
|
82
|
+
"y": 80,
|
|
83
|
+
"wires": []
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"id": "dbg-fan",
|
|
87
|
+
"type": "debug",
|
|
88
|
+
"name": "Cooling fan",
|
|
89
|
+
"active": true,
|
|
90
|
+
"tosidebar": true,
|
|
91
|
+
"console": false,
|
|
92
|
+
"tostatus": true,
|
|
93
|
+
"complete": "payload",
|
|
94
|
+
"targetType": "msg",
|
|
95
|
+
"z": "tab-tmp117-demo",
|
|
96
|
+
"x": 890,
|
|
97
|
+
"y": 140,
|
|
98
|
+
"wires": []
|
|
99
|
+
}
|
|
100
|
+
]
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-mcp9808', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '0x18' },
|
|
9
|
+
resolution: { value: '0.0625' },
|
|
10
|
+
|
|
11
|
+
alertEnabled: { value: false },
|
|
12
|
+
upperLimit: { value: '30', validate: RED.validators.number() },
|
|
13
|
+
lowerLimit: { value: '10', validate: RED.validators.number() },
|
|
14
|
+
criticalLimit: { value: '45', validate: RED.validators.number() },
|
|
15
|
+
hysteresis: { value: '0' },
|
|
16
|
+
alertMode: { value: 'all' },
|
|
17
|
+
alertOutput: { value: 'comparator' }
|
|
18
|
+
},
|
|
19
|
+
inputs: 1,
|
|
20
|
+
outputs: 1,
|
|
21
|
+
icon: 'font-awesome/fa-thermometer-half',
|
|
22
|
+
label: function() { return this.name || 'MCP9808'; },
|
|
23
|
+
paletteLabel: 'MCP9808'
|
|
24
|
+
});
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<script type="text/html" data-template-name="periph-mcp9808">
|
|
28
|
+
<div class="form-row">
|
|
29
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
30
|
+
<input type="text" id="node-input-name" placeholder="MCP9808">
|
|
31
|
+
</div>
|
|
32
|
+
<div class="form-row">
|
|
33
|
+
<label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
34
|
+
<input type="number" id="node-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
35
|
+
</div>
|
|
36
|
+
<div class="form-row">
|
|
37
|
+
<label for="node-input-address"><i class="fa fa-map-marker"></i> I²C address</label>
|
|
38
|
+
<select id="node-input-address" style="width:120px">
|
|
39
|
+
<option value="0x18">0x18</option>
|
|
40
|
+
<option value="0x19">0x19</option>
|
|
41
|
+
<option value="0x1A">0x1A</option>
|
|
42
|
+
<option value="0x1B">0x1B</option>
|
|
43
|
+
<option value="0x1C">0x1C</option>
|
|
44
|
+
<option value="0x1D">0x1D</option>
|
|
45
|
+
<option value="0x1E">0x1E</option>
|
|
46
|
+
<option value="0x1F">0x1F</option>
|
|
47
|
+
</select>
|
|
48
|
+
</div>
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-resolution"><i class="fa fa-sliders"></i> Resolution</label>
|
|
51
|
+
<select id="node-input-resolution" style="width:200px">
|
|
52
|
+
<option value="0.5">0.5 °C (30 ms)</option>
|
|
53
|
+
<option value="0.25">0.25 °C (65 ms)</option>
|
|
54
|
+
<option value="0.125">0.125 °C (130 ms)</option>
|
|
55
|
+
<option value="0.0625">0.0625 °C (250 ms)</option>
|
|
56
|
+
</select>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<hr>
|
|
60
|
+
<div class="form-row">
|
|
61
|
+
<label for="node-input-alertEnabled"><i class="fa fa-bell"></i> Alert</label>
|
|
62
|
+
<input type="checkbox" id="node-input-alertEnabled" style="width:auto"> enabled (emits a <code>source</code> message when a boundary trips)
|
|
63
|
+
</div>
|
|
64
|
+
<div class="form-row">
|
|
65
|
+
<label for="node-input-upperLimit"> TUPPER °C</label>
|
|
66
|
+
<input type="text" id="node-input-upperLimit" style="width:80px">
|
|
67
|
+
</div>
|
|
68
|
+
<div class="form-row">
|
|
69
|
+
<label for="node-input-lowerLimit"> TLOWER °C</label>
|
|
70
|
+
<input type="text" id="node-input-lowerLimit" style="width:80px">
|
|
71
|
+
</div>
|
|
72
|
+
<div class="form-row">
|
|
73
|
+
<label for="node-input-criticalLimit"> TCRIT °C</label>
|
|
74
|
+
<input type="text" id="node-input-criticalLimit" style="width:80px">
|
|
75
|
+
</div>
|
|
76
|
+
<div class="form-row">
|
|
77
|
+
<label for="node-input-hysteresis"> Hysteresis</label>
|
|
78
|
+
<select id="node-input-hysteresis" style="width:120px">
|
|
79
|
+
<option value="0">0 °C</option>
|
|
80
|
+
<option value="1.5">1.5 °C</option>
|
|
81
|
+
<option value="3">3.0 °C</option>
|
|
82
|
+
<option value="6">6.0 °C</option>
|
|
83
|
+
</select>
|
|
84
|
+
</div>
|
|
85
|
+
<div class="form-row">
|
|
86
|
+
<label for="node-input-alertMode"> Source</label>
|
|
87
|
+
<select id="node-input-alertMode" style="width:200px">
|
|
88
|
+
<option value="all">TUPPER / TLOWER / TCRIT</option>
|
|
89
|
+
<option value="critical_only">TCRIT only</option>
|
|
90
|
+
</select>
|
|
91
|
+
</div>
|
|
92
|
+
<div class="form-row">
|
|
93
|
+
<label for="node-input-alertOutput"> Mode</label>
|
|
94
|
+
<select id="node-input-alertOutput" style="width:200px">
|
|
95
|
+
<option value="comparator">Comparator</option>
|
|
96
|
+
<option value="interrupt">Interrupt (latched)</option>
|
|
97
|
+
</select>
|
|
98
|
+
</div>
|
|
99
|
+
</script>
|
|
100
|
+
|
|
101
|
+
<script type="text/html" data-help-name="periph-mcp9808">
|
|
102
|
+
<p>Reads the ambient temperature from an MCP9808 ±0.5 °C digital temperature sensor over I²C, and optionally reports its TUPPER/TLOWER/TCRIT boundary alerts.</p>
|
|
103
|
+
|
|
104
|
+
<h3>Inputs</h3>
|
|
105
|
+
<dl class="message-properties">
|
|
106
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
107
|
+
<dd>Any incoming message triggers a temperature and Alert-status read.</dd>
|
|
108
|
+
<dt>payload.shutdown <span class="property-type">boolean</span> (optional)</dt>
|
|
109
|
+
<dd><code>true</code> puts the sensor in low-power Shutdown mode, <code>false</code> resumes continuous conversion. No output is sent.</dd>
|
|
110
|
+
<dt>payload.clear_interrupt <span class="property-type">boolean</span> (optional)</dt>
|
|
111
|
+
<dd><code>true</code> clears a latched interrupt-mode Alert so it can fire again. No output is sent.</dd>
|
|
112
|
+
</dl>
|
|
113
|
+
|
|
114
|
+
<h3>Outputs</h3>
|
|
115
|
+
<dl class="message-properties">
|
|
116
|
+
<dt>payload.temperature_c <span class="property-type">number</span></dt>
|
|
117
|
+
<dd>Ambient temperature in °C.</dd>
|
|
118
|
+
<dt>payload.alert_asserted <span class="property-type">boolean</span></dt>
|
|
119
|
+
<dd>Whether the Alert output is currently asserted.</dd>
|
|
120
|
+
<dt>payload.source <span class="property-type">string</span></dt>
|
|
121
|
+
<dd>Emitted separately, independent of the polling trigger above, when the Alert is enabled and a boundary trips: <code>"lower"</code> (below TLOWER), <code>"upper"</code> (above TUPPER) or <code>"critical"</code> (at or above TCRIT). Several messages may follow one event when more than one boundary is crossed.</dd>
|
|
122
|
+
</dl>
|
|
123
|
+
|
|
124
|
+
<h3>Configuration</h3>
|
|
125
|
+
<p>Set the I²C bus number, the address selected by the board's A0/A1/A2 straps (<code>0x18</code>–<code>0x1F</code>), and the measurement resolution — finer steps take longer to convert. Optionally enable the Alert: set the three boundaries (rounded to 0.25 °C), the hysteresis applied when cooling back past a boundary, which boundaries drive it, and whether it behaves as a comparator or a latched interrupt (re-arm the latter with <code>payload.clear_interrupt</code>).</p>
|
|
126
|
+
</script>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { MCP9808Full } = require('periph/src/chips/temperature/mcp9808');
|
|
6
|
+
|
|
7
|
+
const SOURCE_NAMES = [
|
|
8
|
+
[MCP9808Full.SOURCE_LOWER, 'lower'],
|
|
9
|
+
[MCP9808Full.SOURCE_UPPER, 'upper'],
|
|
10
|
+
[MCP9808Full.SOURCE_CRITICAL, 'critical'],
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
function MCP9808Node(config) {
|
|
14
|
+
RED.nodes.createNode(this, config);
|
|
15
|
+
const node = this;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const address = parseInt(config.address, 16) || MCP9808Full.I2C_ADDRESS;
|
|
19
|
+
const connection = new I2CConnection(parseInt(config.bus, 10), address);
|
|
20
|
+
node.driver = new MCP9808Full(connection);
|
|
21
|
+
node.connection = connection;
|
|
22
|
+
|
|
23
|
+
(async () => {
|
|
24
|
+
await node.driver.init();
|
|
25
|
+
await node.driver.setResolution(parseFloat(config.resolution) || 0.0625);
|
|
26
|
+
if (config.alertEnabled) {
|
|
27
|
+
await node.driver.setUpperLimit(parseFloat(config.upperLimit));
|
|
28
|
+
await node.driver.setLowerLimit(parseFloat(config.lowerLimit));
|
|
29
|
+
await node.driver.setCriticalLimit(parseFloat(config.criticalLimit));
|
|
30
|
+
await node.driver.setHysteresis(parseFloat(config.hysteresis) || 0);
|
|
31
|
+
await node.driver.configureAlert(config.alertMode || 'all',
|
|
32
|
+
config.alertOutput || 'comparator', 'active_low');
|
|
33
|
+
await node.driver.enableAlert();
|
|
34
|
+
await node.driver.onInterrupt((status) => {
|
|
35
|
+
for (const [bit, name] of SOURCE_NAMES) {
|
|
36
|
+
if (status & bit) node.send({ payload: { source: name } });
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
})().catch((e) => node.error('MCP9808 init failed: ' + e.message));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
node.error('MCP9808 init failed: ' + e.message);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
node.on('input', async function(msg, send, done) {
|
|
46
|
+
if (!node.driver) { done(); return; }
|
|
47
|
+
try {
|
|
48
|
+
const p = msg.payload;
|
|
49
|
+
if (p && typeof p === 'object') {
|
|
50
|
+
if (p.shutdown === true) { await node.driver.shutdown(); done(); return; }
|
|
51
|
+
if (p.shutdown === false) { await node.driver.wake(); done(); return; }
|
|
52
|
+
if (p.clear_interrupt === true) { await node.driver.clearInterrupt(); done(); return; }
|
|
53
|
+
}
|
|
54
|
+
msg.payload = {
|
|
55
|
+
temperature_c: await node.driver.readTemperature(),
|
|
56
|
+
alert_asserted: await node.driver.isAlertAsserted(),
|
|
57
|
+
};
|
|
58
|
+
send(msg);
|
|
59
|
+
done();
|
|
60
|
+
} catch (e) {
|
|
61
|
+
done(e);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
node.on('close', async function(removed, done) {
|
|
66
|
+
try {
|
|
67
|
+
if (node.driver) await node.driver.offInterrupt();
|
|
68
|
+
if (node.connection) await node.connection.close();
|
|
69
|
+
} catch (e) {
|
|
70
|
+
// bus may already be gone; nothing more to do on close
|
|
71
|
+
} finally {
|
|
72
|
+
done();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
RED.nodes.registerType('periph-mcp9808', MCP9808Node);
|
|
77
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
<script type="text/javascript">
|
|
2
|
+
RED.nodes.registerType('periph-tmp117', {
|
|
3
|
+
category: 'Peripheral',
|
|
4
|
+
color: '#C084FC',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '0x48' },
|
|
9
|
+
averaging: { value: '8' },
|
|
10
|
+
cycleSeconds: { value: '1' },
|
|
11
|
+
|
|
12
|
+
alertEnabled: { value: false },
|
|
13
|
+
highLimit: { value: '30', validate: RED.validators.number() },
|
|
14
|
+
lowLimit: { value: '10', validate: RED.validators.number() },
|
|
15
|
+
alertMode: { value: 'alert' },
|
|
16
|
+
polarity: { value: 'active_low' }
|
|
17
|
+
},
|
|
18
|
+
inputs: 1,
|
|
19
|
+
outputs: 1,
|
|
20
|
+
icon: 'font-awesome/fa-thermometer-half',
|
|
21
|
+
label: function() { return this.name || 'TMP117'; },
|
|
22
|
+
paletteLabel: 'TMP117'
|
|
23
|
+
});
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script type="text/html" data-template-name="periph-tmp117">
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
29
|
+
<input type="text" id="node-input-name" placeholder="TMP117">
|
|
30
|
+
</div>
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
33
|
+
<input type="number" id="node-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
34
|
+
</div>
|
|
35
|
+
<div class="form-row">
|
|
36
|
+
<label for="node-input-address"><i class="fa fa-map-marker"></i> I²C address</label>
|
|
37
|
+
<select id="node-input-address" style="width:200px">
|
|
38
|
+
<option value="0x48">0x48 (ADD0 = GND)</option>
|
|
39
|
+
<option value="0x49">0x49 (ADD0 = V+)</option>
|
|
40
|
+
<option value="0x4A">0x4A (ADD0 = SDA)</option>
|
|
41
|
+
<option value="0x4B">0x4B (ADD0 = SCL)</option>
|
|
42
|
+
</select>
|
|
43
|
+
</div>
|
|
44
|
+
<div class="form-row">
|
|
45
|
+
<label for="node-input-averaging"><i class="fa fa-sliders"></i> Averaging</label>
|
|
46
|
+
<select id="node-input-averaging" style="width:200px">
|
|
47
|
+
<option value="0">none</option>
|
|
48
|
+
<option value="8">8 conversions</option>
|
|
49
|
+
<option value="32">32 conversions</option>
|
|
50
|
+
<option value="64">64 conversions</option>
|
|
51
|
+
</select>
|
|
52
|
+
</div>
|
|
53
|
+
<div class="form-row">
|
|
54
|
+
<label for="node-input-cycleSeconds"><i class="fa fa-clock-o"></i> Cycle time</label>
|
|
55
|
+
<select id="node-input-cycleSeconds" style="width:200px">
|
|
56
|
+
<option value="0.0155">15.5 ms</option>
|
|
57
|
+
<option value="0.125">125 ms</option>
|
|
58
|
+
<option value="0.25">250 ms</option>
|
|
59
|
+
<option value="0.5">500 ms</option>
|
|
60
|
+
<option value="1">1 s</option>
|
|
61
|
+
<option value="4">4 s</option>
|
|
62
|
+
<option value="8">8 s</option>
|
|
63
|
+
<option value="16">16 s</option>
|
|
64
|
+
</select>
|
|
65
|
+
</div>
|
|
66
|
+
|
|
67
|
+
<hr>
|
|
68
|
+
<div class="form-row">
|
|
69
|
+
<label for="node-input-alertEnabled"><i class="fa fa-bell"></i> Alert</label>
|
|
70
|
+
<input type="checkbox" id="node-input-alertEnabled" style="width:auto"> enabled (emits a <code>source</code> message when a limit trips)
|
|
71
|
+
</div>
|
|
72
|
+
<div class="form-row">
|
|
73
|
+
<label for="node-input-highLimit"> THIGH °C</label>
|
|
74
|
+
<input type="text" id="node-input-highLimit" style="width:80px">
|
|
75
|
+
</div>
|
|
76
|
+
<div class="form-row">
|
|
77
|
+
<label for="node-input-lowLimit"> TLOW °C</label>
|
|
78
|
+
<input type="text" id="node-input-lowLimit" style="width:80px">
|
|
79
|
+
</div>
|
|
80
|
+
<div class="form-row">
|
|
81
|
+
<label for="node-input-alertMode"> Mode</label>
|
|
82
|
+
<select id="node-input-alertMode" style="width:200px">
|
|
83
|
+
<option value="alert">Alert (window)</option>
|
|
84
|
+
<option value="therm">Therm (latching, TLOW resets)</option>
|
|
85
|
+
</select>
|
|
86
|
+
</div>
|
|
87
|
+
<div class="form-row">
|
|
88
|
+
<label for="node-input-polarity"> Polarity</label>
|
|
89
|
+
<select id="node-input-polarity" style="width:200px">
|
|
90
|
+
<option value="active_low">Active low</option>
|
|
91
|
+
<option value="active_high">Active high</option>
|
|
92
|
+
</select>
|
|
93
|
+
</div>
|
|
94
|
+
</script>
|
|
95
|
+
|
|
96
|
+
<script type="text/html" data-help-name="periph-tmp117">
|
|
97
|
+
<p>Reads the temperature from a TMP117 ±0.1 °C high-accuracy digital temperature sensor over I²C, and optionally reports its THIGH/TLOW limit alerts.</p>
|
|
98
|
+
|
|
99
|
+
<h3>Inputs</h3>
|
|
100
|
+
<dl class="message-properties">
|
|
101
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
102
|
+
<dd>Any incoming message triggers a temperature and alert-flag read.</dd>
|
|
103
|
+
<dt>payload.mode <span class="property-type">string</span> (optional)</dt>
|
|
104
|
+
<dd><code>"continuous"</code>, <code>"shutdown"</code> or <code>"one_shot"</code> changes the conversion mode, keeping the configured averaging and cycle time. No output is sent.</dd>
|
|
105
|
+
</dl>
|
|
106
|
+
|
|
107
|
+
<h3>Outputs</h3>
|
|
108
|
+
<dl class="message-properties">
|
|
109
|
+
<dt>payload.temperature_c <span class="property-type">number</span></dt>
|
|
110
|
+
<dd>Temperature in °C (-256 until the first conversion after power-up).</dd>
|
|
111
|
+
<dt>payload.high_alert <span class="property-type">boolean</span></dt>
|
|
112
|
+
<dd>HIGH_Alert flag: the result exceeded THIGH.</dd>
|
|
113
|
+
<dt>payload.low_alert <span class="property-type">boolean</span></dt>
|
|
114
|
+
<dd>LOW_Alert flag: the result fell below TLOW (Alert mode only). In Alert mode reading the flags clears them.</dd>
|
|
115
|
+
<dt>payload.source <span class="property-type">string</span></dt>
|
|
116
|
+
<dd>Emitted separately, independent of the polling trigger above, when the Alert is enabled and a limit trips: <code>"high"</code> (above THIGH) or <code>"low"</code> (below TLOW).</dd>
|
|
117
|
+
</dl>
|
|
118
|
+
|
|
119
|
+
<h3>Configuration</h3>
|
|
120
|
+
<p>Set the I²C bus number, the address selected by the board's ADD0 strap (<code>0x48</code>–<code>0x4B</code>), and the averaging and cycle time — more averaging lowers noise, and the hardware lengthens short cycles automatically at higher averaging. Optionally enable the Alert: set the THIGH/TLOW limits (0.0078125 °C steps), choose Alert mode (a flag for each side of the window) or Therm mode (latches above THIGH until the temperature drops below TLOW), and the ALERT pin polarity.</p>
|
|
121
|
+
</script>
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { TMP117Full } = require('periph/src/chips/temperature/tmp117');
|
|
6
|
+
|
|
7
|
+
const SOURCE_NAMES = [
|
|
8
|
+
[TMP117Full.SOURCE_HIGH, 'high'],
|
|
9
|
+
[TMP117Full.SOURCE_LOW, 'low'],
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
function TMP117Node(config) {
|
|
13
|
+
RED.nodes.createNode(this, config);
|
|
14
|
+
const node = this;
|
|
15
|
+
const averaging = parseInt(config.averaging, 10);
|
|
16
|
+
const cycleSeconds = parseFloat(config.cycleSeconds) || 1.0;
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const address = parseInt(config.address, 16) || TMP117Full.I2C_ADDRESS;
|
|
20
|
+
const connection = new I2CConnection(parseInt(config.bus, 10), address);
|
|
21
|
+
node.driver = new TMP117Full(connection);
|
|
22
|
+
node.connection = connection;
|
|
23
|
+
|
|
24
|
+
(async () => {
|
|
25
|
+
await node.driver.init();
|
|
26
|
+
await node.driver.configure('continuous', isNaN(averaging) ? 8 : averaging, cycleSeconds);
|
|
27
|
+
if (config.alertEnabled) {
|
|
28
|
+
await node.driver.setHighLimit(parseFloat(config.highLimit));
|
|
29
|
+
await node.driver.setLowLimit(parseFloat(config.lowLimit));
|
|
30
|
+
await node.driver.configureAlert(config.alertMode || 'alert',
|
|
31
|
+
config.polarity || 'active_low', 'alert');
|
|
32
|
+
await node.driver.onInterrupt((status) => {
|
|
33
|
+
for (const [bit, name] of SOURCE_NAMES) {
|
|
34
|
+
if (status & bit) node.send({ payload: { source: name } });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
})().catch((e) => node.error('TMP117 init failed: ' + e.message));
|
|
39
|
+
} catch (e) {
|
|
40
|
+
node.error('TMP117 init failed: ' + e.message);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
node.on('input', async function(msg, send, done) {
|
|
44
|
+
if (!node.driver) { done(); return; }
|
|
45
|
+
try {
|
|
46
|
+
const p = msg.payload;
|
|
47
|
+
if (p && typeof p === 'object' && typeof p.mode === 'string') {
|
|
48
|
+
await node.driver.configure(p.mode, isNaN(averaging) ? 8 : averaging, cycleSeconds);
|
|
49
|
+
done();
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const temperature = await node.driver.readTemperature();
|
|
53
|
+
const status = await node.driver.pollInterrupt();
|
|
54
|
+
msg.payload = {
|
|
55
|
+
temperature_c: temperature,
|
|
56
|
+
high_alert: (status & TMP117Full.SOURCE_HIGH) !== 0,
|
|
57
|
+
low_alert: (status & TMP117Full.SOURCE_LOW) !== 0,
|
|
58
|
+
};
|
|
59
|
+
send(msg);
|
|
60
|
+
done();
|
|
61
|
+
} catch (e) {
|
|
62
|
+
done(e);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
node.on('close', async function(removed, done) {
|
|
67
|
+
try {
|
|
68
|
+
if (node.driver) await node.driver.offInterrupt();
|
|
69
|
+
if (node.connection) await node.connection.close();
|
|
70
|
+
} catch (e) {
|
|
71
|
+
// bus may already be gone; nothing more to do on close
|
|
72
|
+
} finally {
|
|
73
|
+
done();
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
RED.nodes.registerType('periph-tmp117', TMP117Node);
|
|
78
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-temperature",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "Node-RED nodes for temperature sensor chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -11,7 +11,10 @@
|
|
|
11
11
|
"peripheral"
|
|
12
12
|
],
|
|
13
13
|
"node-red": {
|
|
14
|
-
"nodes": {
|
|
14
|
+
"nodes": {
|
|
15
|
+
"mcp9808": "nodes/mcp9808/mcp9808.js",
|
|
16
|
+
"tmp117": "nodes/tmp117/tmp117.js"
|
|
17
|
+
}
|
|
15
18
|
},
|
|
16
19
|
"dependencies": {
|
|
17
20
|
"periph": "*"
|
package/examples/.gitkeep
DELETED
|
File without changes
|
package/nodes/.gitkeep
DELETED
|
File without changes
|