node-red-contrib-periph-pressure 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.
- package/README.md +4 -0
- package/examples/lps22hb/demo.json +141 -0
- package/examples/mpl115a2/demo.json +66 -0
- package/nodes/lps22hb/lps22hb.html +137 -0
- package/nodes/lps22hb/lps22hb.js +57 -0
- package/nodes/mpl115a2/mpl115a2.html +74 -0
- package/nodes/mpl115a2/mpl115a2.js +46 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -28,10 +28,14 @@ npm install node-red-contrib-periph-pressure
|
|
|
28
28
|
| `periph-bmp581` | input | Reads pressure, temperature, and altitude from a BMP581 barometric pressure sensor. |
|
|
29
29
|
| `lps22df-device` | config | Bus configuration for a LPS22DF |
|
|
30
30
|
| `periph-lps22df` | input | Reads pressure, temperature, and altitude from an LPS22DF absolute pressure sensor. |
|
|
31
|
+
| `lps22hb-device` | config | Bus configuration for a LPS22HB |
|
|
32
|
+
| `periph-lps22hb` | input | Reads pressure and temperature from an LPS22HB MEMS nano absolute pressure sensor. |
|
|
31
33
|
| `lps28dfw-device` | config | Bus configuration for a LPS28DFW |
|
|
32
34
|
| `periph-lps28dfw` | input | Reads pressure, temperature, and altitude from an LPS28DFW dual full-scale digital barometer. |
|
|
33
35
|
| `lps33hw-device` | config | Bus configuration for a LPS33HW |
|
|
34
36
|
| `periph-lps33hw` | input | Reads pressure and temperature from an LPS33HW water-resistant MEMS absolute pressure sensor. |
|
|
37
|
+
| `mpl115a2-device` | config | Bus configuration for a MPL115A2 |
|
|
38
|
+
| `periph-mpl115a2` | input | Reads the barometric pressure (50–115 kPa) and an approximate temperature from an NXP MPL115A2 over I²C (address 0x60). |
|
|
35
39
|
|
|
36
40
|
## Links
|
|
37
41
|
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "lps22hb-device-1",
|
|
4
|
+
"type": "lps22hb-device",
|
|
5
|
+
"name": "LPS22HB @ i2c-1",
|
|
6
|
+
"bus": "1",
|
|
7
|
+
"addr": "0x5C",
|
|
8
|
+
"odr": "2",
|
|
9
|
+
"bdu": "1",
|
|
10
|
+
"enLpfp": "1",
|
|
11
|
+
"lpfpCfg": "1",
|
|
12
|
+
"lcEn": "0",
|
|
13
|
+
"sim": "0"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"id": "lps22hb-read-1",
|
|
17
|
+
"type": "periph-lps22hb",
|
|
18
|
+
"name": "LPS22HB Altimeter",
|
|
19
|
+
"device": "lps22hb-device-1",
|
|
20
|
+
"wires": [["function-alt-1", "debug-1", "chart-pres-1", "chart-alt-1", "chart-temp-1"]]
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"id": "inject-timer-1",
|
|
24
|
+
"type": "inject",
|
|
25
|
+
"name": "Every 1 second",
|
|
26
|
+
"topic": "",
|
|
27
|
+
"payload": "",
|
|
28
|
+
"payloadType": "date",
|
|
29
|
+
"repeat": "1",
|
|
30
|
+
"crontab": "",
|
|
31
|
+
"onceDelay": "0.1",
|
|
32
|
+
"wires": [["lps22hb-read-1"]]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"id": "function-alt-1",
|
|
36
|
+
"type": "function",
|
|
37
|
+
"name": "Compute altitude",
|
|
38
|
+
"func": "if (msg.payload && typeof msg.payload.pressure_Pa === 'number') {\n const p = msg.payload.pressure_Pa;\n msg.payload.altitude_m = 44330 * (1 - Math.pow(p / 101325, 1 / 5.255));\n}\nreturn msg;",
|
|
39
|
+
"outputs": 1,
|
|
40
|
+
"noerr": 0,
|
|
41
|
+
"x": 480,
|
|
42
|
+
"y": 200,
|
|
43
|
+
"wires": [["chart-alt-1"]]
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"id": "inject-autozero-1",
|
|
47
|
+
"type": "inject",
|
|
48
|
+
"name": "AUTOZERO every 10 s",
|
|
49
|
+
"topic": "",
|
|
50
|
+
"payload": "",
|
|
51
|
+
"payloadType": "date",
|
|
52
|
+
"repeat": "10",
|
|
53
|
+
"crontab": "",
|
|
54
|
+
"onceDelay": "1",
|
|
55
|
+
"wires": [["autozero-function-1"]]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"id": "autozero-function-1",
|
|
59
|
+
"type": "function",
|
|
60
|
+
"name": "Refresh AUTOZERO reference",
|
|
61
|
+
"func": "var device = RED.nodes.getNode('lps22hb-device-1');\nif (device && device.driver) {\n device.driver.setAutozero();\n node.status({text: 'autozero @ ' + new Date().toISOString().substr(11, 8)});\n}\nreturn msg;",
|
|
62
|
+
"outputs": 1,
|
|
63
|
+
"noerr": 0,
|
|
64
|
+
"x": 480,
|
|
65
|
+
"y": 280,
|
|
66
|
+
"wires": [[]]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"id": "debug-1",
|
|
70
|
+
"type": "debug",
|
|
71
|
+
"name": "Debug output",
|
|
72
|
+
"active": true,
|
|
73
|
+
"tosidebar": true,
|
|
74
|
+
"console": false,
|
|
75
|
+
"tostatus": false,
|
|
76
|
+
"complete": "payload",
|
|
77
|
+
"targetType": "msg",
|
|
78
|
+
"x": 700,
|
|
79
|
+
"y": 200,
|
|
80
|
+
"wires": []
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"id": "chart-pres-1",
|
|
84
|
+
"type": "ui_chart",
|
|
85
|
+
"name": "Pressure",
|
|
86
|
+
"group": "lps22hb-group-1",
|
|
87
|
+
"order": 1,
|
|
88
|
+
"width": 6,
|
|
89
|
+
"height": 4,
|
|
90
|
+
"label": "Pressure (Pa)",
|
|
91
|
+
"chartType": "line",
|
|
92
|
+
"x": 700,
|
|
93
|
+
"y": 260,
|
|
94
|
+
"wires": []
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"id": "chart-alt-1",
|
|
98
|
+
"type": "ui_chart",
|
|
99
|
+
"name": "Altitude",
|
|
100
|
+
"group": "lps22hb-group-1",
|
|
101
|
+
"order": 2,
|
|
102
|
+
"width": 6,
|
|
103
|
+
"height": 4,
|
|
104
|
+
"label": "Altitude (m)",
|
|
105
|
+
"chartType": "line",
|
|
106
|
+
"x": 700,
|
|
107
|
+
"y": 320,
|
|
108
|
+
"wires": []
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"id": "chart-temp-1",
|
|
112
|
+
"type": "ui_chart",
|
|
113
|
+
"name": "Temperature",
|
|
114
|
+
"group": "lps22hb-group-1",
|
|
115
|
+
"order": 3,
|
|
116
|
+
"width": 6,
|
|
117
|
+
"height": 4,
|
|
118
|
+
"label": "Temperature (°C)",
|
|
119
|
+
"chartType": "line",
|
|
120
|
+
"x": 700,
|
|
121
|
+
"y": 380,
|
|
122
|
+
"wires": []
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"id": "lps22hb-group-1",
|
|
126
|
+
"type": "ui_group",
|
|
127
|
+
"name": "LPS22HB Altimeter",
|
|
128
|
+
"tab": "lps22hb-tab-1",
|
|
129
|
+
"order": 1,
|
|
130
|
+
"disp": true,
|
|
131
|
+
"width": 12
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
"id": "lps22hb-tab-1",
|
|
135
|
+
"type": "ui_tab",
|
|
136
|
+
"name": "LPS22HB Demo",
|
|
137
|
+
"icon": "dashboard",
|
|
138
|
+
"order": 1,
|
|
139
|
+
"info": "This flow demonstrates the LPS22HB MEMS nano pressure sensor as an altimeter.\n\nThe device config node sets **10 Hz ODR with the ODR/20 low-pass filter enabled** — a fresh pressure sample every 100 ms with the on-chip LPF (~0.5 Hz cutoff) suppressing door-slam and HVAC noise. An inject node fires every second; each tick reads pressure (Pa) and temperature (°C). A function node converts the pressure to relative altitude using the barometric formula `44330 * (1 - (p / 101325)^(1/5.255))`.\n\nBecause atmospheric pressure drifts with the weather (~1 hPa per ~8 m of equivalent altitude), the AUTOZERO reference is refreshed every 10 s via a second inject + function node pair. This makes the altitude chart a true *relative* measurement — climb one floor (~3 m) and watch the trace shift, then return.\n\nAdjust the I²C bus, address (0x5C for SA0=GND, 0x5D for SA0=VDD), ODR, and LPF bandwidth in the device config node. Drop ODR to 1 Hz and disable the LPF for battery-powered weather monitoring instead of altimetry."
|
|
140
|
+
}
|
|
141
|
+
]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "mpl115a2-tab",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "MPL115A2 demo",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Barometer: an inject node triggers a conversion every 5 s; the periph-mpl115a2 node outputs { pressure_pa, temperature_c }; a function node converts the pressure to hPa for the debug sidebar."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "mpl115a2-device-1",
|
|
11
|
+
"type": "mpl115a2-device",
|
|
12
|
+
"name": "MPL115A2 @ i2c-1",
|
|
13
|
+
"bus": "1"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"id": "mpl115a2-read-1",
|
|
17
|
+
"type": "periph-mpl115a2",
|
|
18
|
+
"z": "mpl115a2-tab",
|
|
19
|
+
"name": "MPL115A2",
|
|
20
|
+
"device": "mpl115a2-device-1",
|
|
21
|
+
"x": 330,
|
|
22
|
+
"y": 120,
|
|
23
|
+
"wires": [["mpl115a2-hpa-1"]]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"id": "mpl115a2-inject-1",
|
|
27
|
+
"type": "inject",
|
|
28
|
+
"z": "mpl115a2-tab",
|
|
29
|
+
"name": "Every 5 seconds",
|
|
30
|
+
"topic": "",
|
|
31
|
+
"payload": "",
|
|
32
|
+
"payloadType": "date",
|
|
33
|
+
"repeat": "5",
|
|
34
|
+
"crontab": "",
|
|
35
|
+
"once": true,
|
|
36
|
+
"onceDelay": "0.1",
|
|
37
|
+
"x": 130,
|
|
38
|
+
"y": 120,
|
|
39
|
+
"wires": [["mpl115a2-read-1"]]
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"id": "mpl115a2-hpa-1",
|
|
43
|
+
"type": "function",
|
|
44
|
+
"z": "mpl115a2-tab",
|
|
45
|
+
"name": "Pa to hPa",
|
|
46
|
+
"func": "msg.payload.pressure_hpa = msg.payload.pressure_pa / 100;\nnode.status({text: msg.payload.pressure_hpa.toFixed(1) + ' hPa'});\nreturn msg;",
|
|
47
|
+
"outputs": 1,
|
|
48
|
+
"noerr": 0,
|
|
49
|
+
"x": 520,
|
|
50
|
+
"y": 120,
|
|
51
|
+
"wires": [["mpl115a2-debug-1"]]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "mpl115a2-debug-1",
|
|
55
|
+
"type": "debug",
|
|
56
|
+
"z": "mpl115a2-tab",
|
|
57
|
+
"name": "Debug output",
|
|
58
|
+
"active": true,
|
|
59
|
+
"console": "false",
|
|
60
|
+
"complete": "payload",
|
|
61
|
+
"targetType": "msg",
|
|
62
|
+
"x": 710,
|
|
63
|
+
"y": 120,
|
|
64
|
+
"wires": []
|
|
65
|
+
}
|
|
66
|
+
]
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('lps22hb-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
addr: { value: '0x5C', required: true },
|
|
9
|
+
odr: { value: '1', required: true, validate: RED.validators.number() },
|
|
10
|
+
bdu: { value: '1', required: true, validate: RED.validators.number() },
|
|
11
|
+
enLpfp: { value: '0', required: true, validate: RED.validators.number() },
|
|
12
|
+
lpfpCfg: { value: '0', required: true, validate: RED.validators.number() },
|
|
13
|
+
lcEn: { value: '0', required: true, validate: RED.validators.number() },
|
|
14
|
+
sim: { value: '0', required: true, validate: RED.validators.number() }
|
|
15
|
+
},
|
|
16
|
+
label: function() {
|
|
17
|
+
return this.name || ('LPS22HB @ ' + this.addr + ' (bus ' + this.bus + ')');
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script type="text/html" data-template-name="lps22hb-device">
|
|
23
|
+
<div class="form-row">
|
|
24
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
25
|
+
<input type="text" id="node-config-input-name" placeholder="LPS22HB">
|
|
26
|
+
</div>
|
|
27
|
+
<div class="form-row">
|
|
28
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
29
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
30
|
+
</div>
|
|
31
|
+
<div class="form-row">
|
|
32
|
+
<label for="node-config-input-addr"><i class="fa fa-microchip"></i> I²C address</label>
|
|
33
|
+
<select id="node-config-input-addr" style="width:140px">
|
|
34
|
+
<option value="0x5C" selected>0x5C (SA0=GND)</option>
|
|
35
|
+
<option value="0x5D">0x5D (SA0=VDD)</option>
|
|
36
|
+
</select>
|
|
37
|
+
</div>
|
|
38
|
+
<div class="form-row">
|
|
39
|
+
<label for="node-config-input-odr">Output data rate</label>
|
|
40
|
+
<select id="node-config-input-odr" style="width:180px">
|
|
41
|
+
<option value="0">Power-down</option>
|
|
42
|
+
<option value="1" selected>1 Hz</option>
|
|
43
|
+
<option value="2">10 Hz</option>
|
|
44
|
+
<option value="3">25 Hz</option>
|
|
45
|
+
<option value="4">50 Hz</option>
|
|
46
|
+
<option value="5">75 Hz</option>
|
|
47
|
+
</select>
|
|
48
|
+
</div>
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-config-input-bdu">Block data update</label>
|
|
51
|
+
<select id="node-config-input-bdu" style="width:120px">
|
|
52
|
+
<option value="0">Disable</option>
|
|
53
|
+
<option value="1" selected>Enable</option>
|
|
54
|
+
</select>
|
|
55
|
+
</div>
|
|
56
|
+
<div class="form-row">
|
|
57
|
+
<label for="node-config-input-enLpfp">Low-pass filter</label>
|
|
58
|
+
<select id="node-config-input-enLpfp" style="width:180px">
|
|
59
|
+
<option value="0" selected>Disabled</option>
|
|
60
|
+
<option value="1">Enabled</option>
|
|
61
|
+
</select>
|
|
62
|
+
</div>
|
|
63
|
+
<div class="form-row">
|
|
64
|
+
<label for="node-config-input-lpfpCfg">LPF bandwidth</label>
|
|
65
|
+
<select id="node-config-input-lpfpCfg" style="width:180px">
|
|
66
|
+
<option value="0" selected>ODR/9</option>
|
|
67
|
+
<option value="1">ODR/20</option>
|
|
68
|
+
</select>
|
|
69
|
+
</div>
|
|
70
|
+
<div class="form-row">
|
|
71
|
+
<label for="node-config-input-lcEn">Low-current mode</label>
|
|
72
|
+
<select id="node-config-input-lcEn" style="width:120px">
|
|
73
|
+
<option value="0" selected>Disabled</option>
|
|
74
|
+
<option value="1">Enabled</option>
|
|
75
|
+
</select>
|
|
76
|
+
</div>
|
|
77
|
+
<div class="form-row">
|
|
78
|
+
<label for="node-config-input-sim">SPI mode (3-wire)</label>
|
|
79
|
+
<select id="node-config-input-sim" style="width:120px">
|
|
80
|
+
<option value="0" selected>4-wire</option>
|
|
81
|
+
<option value="1">3-wire</option>
|
|
82
|
+
</select>
|
|
83
|
+
</div>
|
|
84
|
+
</script>
|
|
85
|
+
|
|
86
|
+
<!-- Read node: trigger → measurements -->
|
|
87
|
+
<script type="text/javascript">
|
|
88
|
+
RED.nodes.registerType('periph-lps22hb', {
|
|
89
|
+
category: 'Peripheral',
|
|
90
|
+
color: '#C084FC',
|
|
91
|
+
defaults: {
|
|
92
|
+
name: { value: '' },
|
|
93
|
+
device: { value: '', type: 'lps22hb-device', required: true }
|
|
94
|
+
},
|
|
95
|
+
inputs: 1,
|
|
96
|
+
outputs: 1,
|
|
97
|
+
icon: 'font-awesome/fa-tachometer',
|
|
98
|
+
label: function() { return this.name || 'LPS22HB'; },
|
|
99
|
+
paletteLabel: 'LPS22HB'
|
|
100
|
+
});
|
|
101
|
+
</script>
|
|
102
|
+
|
|
103
|
+
<script type="text/html" data-template-name="periph-lps22hb">
|
|
104
|
+
<div class="form-row">
|
|
105
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
106
|
+
<input type="text" id="node-input-device">
|
|
107
|
+
</div>
|
|
108
|
+
<div class="form-row">
|
|
109
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
110
|
+
<input type="text" id="node-input-name" placeholder="LPS22HB">
|
|
111
|
+
</div>
|
|
112
|
+
</script>
|
|
113
|
+
|
|
114
|
+
<script type="text/html" data-help-name="periph-lps22hb">
|
|
115
|
+
<p>Reads pressure and temperature from an LPS22HB MEMS nano absolute pressure sensor.</p>
|
|
116
|
+
<p>Any input message triggers a measurement. The device is configured via a <b>lps22hb-device</b> config node.</p>
|
|
117
|
+
|
|
118
|
+
<h3>Inputs</h3>
|
|
119
|
+
<dl class="message-properties">
|
|
120
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
121
|
+
<dd>Any incoming message triggers a measurement.</dd>
|
|
122
|
+
</dl>
|
|
123
|
+
|
|
124
|
+
<h3>Outputs</h3>
|
|
125
|
+
<dl class="message-properties">
|
|
126
|
+
<dt>payload.pressure_Pa <span class="property-type">number</span></dt>
|
|
127
|
+
<dd>Absolute pressure in pascals.</dd>
|
|
128
|
+
<dt>payload.temperature_C <span class="property-type">number</span></dt>
|
|
129
|
+
<dd>Temperature in degrees Celsius.</dd>
|
|
130
|
+
</dl>
|
|
131
|
+
|
|
132
|
+
<h3>Configuration</h3>
|
|
133
|
+
<p>Set the I²C bus number, I²C address (<code>0x5C</code> for SA0=GND or <code>0x5D</code> for SA0=VDD),
|
|
134
|
+
output data rate (1–75 Hz), block-data-update, low-pass filter enable and bandwidth (ODR/9 or ODR/20),
|
|
135
|
+
low-current mode, and SPI 3-wire mode in the device config node.
|
|
136
|
+
The 10 Hz ODR with ODR/20 LPF is a good starting point for altimeter / floor-detection applications.</p>
|
|
137
|
+
</script>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { LPS22HBFull } = require('periph/src/chips/pressure/lps22hb');
|
|
6
|
+
|
|
7
|
+
function LPS22HBDeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const addr = parseInt(config.addr) || 0x5C;
|
|
12
|
+
const connection = new I2CConnection(parseInt(config.bus), addr);
|
|
13
|
+
node.driver = new LPS22HBFull(connection);
|
|
14
|
+
node.driver.configure(
|
|
15
|
+
parseInt(config.odr) || 1,
|
|
16
|
+
parseInt(config.bdu) ? 1 : 0,
|
|
17
|
+
parseInt(config.enLpfp) ? 1 : 0,
|
|
18
|
+
parseInt(config.lpfpCfg) || 0,
|
|
19
|
+
parseInt(config.lcEn) ? 1 : 0,
|
|
20
|
+
parseInt(config.sim) ? 1 : 0
|
|
21
|
+
);
|
|
22
|
+
node.connection = connection;
|
|
23
|
+
} catch (e) {
|
|
24
|
+
node.error('LPS22HB init failed: ' + e.message);
|
|
25
|
+
}
|
|
26
|
+
node.on('close', function() {
|
|
27
|
+
if (node.connection) node.connection.close();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
RED.nodes.registerType('lps22hb-device', LPS22HBDeviceNode);
|
|
31
|
+
|
|
32
|
+
function LPS22HBReadNode(config) {
|
|
33
|
+
RED.nodes.createNode(this, config);
|
|
34
|
+
const node = this;
|
|
35
|
+
node.device = RED.nodes.getNode(config.device);
|
|
36
|
+
|
|
37
|
+
node.on('input', async function(msg, send, done) {
|
|
38
|
+
if (!node.device || !node.device.driver) {
|
|
39
|
+
node.error('No LPS22HB device configured', msg);
|
|
40
|
+
done();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const d = node.device.driver;
|
|
45
|
+
msg.payload = {
|
|
46
|
+
pressure_Pa: await d.pressure(),
|
|
47
|
+
temperature_C: await d.temperature()
|
|
48
|
+
};
|
|
49
|
+
send(msg);
|
|
50
|
+
done();
|
|
51
|
+
} catch (e) {
|
|
52
|
+
done(e);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
RED.nodes.registerType('periph-lps22hb', LPS22HBReadNode);
|
|
57
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('mpl115a2-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() }
|
|
8
|
+
},
|
|
9
|
+
label: function() {
|
|
10
|
+
return this.name || ('MPL115A2 @ 0x60 (bus ' + this.bus + ')');
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script type="text/html" data-template-name="mpl115a2-device">
|
|
16
|
+
<div class="form-row">
|
|
17
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
18
|
+
<input type="text" id="node-config-input-name" placeholder="MPL115A2">
|
|
19
|
+
</div>
|
|
20
|
+
<div class="form-row">
|
|
21
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
22
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
23
|
+
</div>
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<!-- Read node: trigger → measurements -->
|
|
27
|
+
<script type="text/javascript">
|
|
28
|
+
RED.nodes.registerType('periph-mpl115a2', {
|
|
29
|
+
category: 'Peripheral',
|
|
30
|
+
color: '#C084FC',
|
|
31
|
+
defaults: {
|
|
32
|
+
name: { value: '' },
|
|
33
|
+
device: { value: '', type: 'mpl115a2-device', required: true }
|
|
34
|
+
},
|
|
35
|
+
inputs: 1,
|
|
36
|
+
outputs: 1,
|
|
37
|
+
icon: 'font-awesome/fa-tachometer',
|
|
38
|
+
label: function() { return this.name || 'MPL115A2'; },
|
|
39
|
+
paletteLabel: 'MPL115A2'
|
|
40
|
+
});
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<script type="text/html" data-template-name="periph-mpl115a2">
|
|
44
|
+
<div class="form-row">
|
|
45
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
46
|
+
<input type="text" id="node-input-device">
|
|
47
|
+
</div>
|
|
48
|
+
<div class="form-row">
|
|
49
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
50
|
+
<input type="text" id="node-input-name" placeholder="MPL115A2">
|
|
51
|
+
</div>
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<script type="text/html" data-help-name="periph-mpl115a2">
|
|
55
|
+
<p>Reads the barometric pressure (50–115 kPa) and an approximate temperature from an NXP MPL115A2 over I²C (address 0x60).</p>
|
|
56
|
+
<p>Any input message triggers one conversion (about 5 ms). The device is configured via an <b>mpl115a2-device</b> config node.</p>
|
|
57
|
+
|
|
58
|
+
<h3>Inputs</h3>
|
|
59
|
+
<dl class="message-properties">
|
|
60
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
61
|
+
<dd>Any incoming message triggers a measurement.</dd>
|
|
62
|
+
</dl>
|
|
63
|
+
|
|
64
|
+
<h3>Outputs</h3>
|
|
65
|
+
<dl class="message-properties">
|
|
66
|
+
<dt>payload.pressure_pa <span class="property-type">number</span></dt>
|
|
67
|
+
<dd>Compensated pressure in pascals.</dd>
|
|
68
|
+
<dt>payload.temperature_c <span class="property-type">number</span></dt>
|
|
69
|
+
<dd>Approximate temperature in degrees Celsius (uncalibrated, accurate to a few degrees — use for trends only).</dd>
|
|
70
|
+
</dl>
|
|
71
|
+
|
|
72
|
+
<h3>Configuration</h3>
|
|
73
|
+
<p>Set the I²C bus number in the device config node. The per-device compensation coefficients are read once at start-up.</p>
|
|
74
|
+
</script>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { MPL115A2Full } = require('periph/src/chips/pressure/mpl115a2');
|
|
6
|
+
|
|
7
|
+
function MPL115A2DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), 0x60);
|
|
12
|
+
node.driver = new MPL115A2Full(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
|
+
node.driver.ready.catch(function(e) { node.error('MPL115A2 init failed: ' + e.message); });
|
|
15
|
+
} catch (e) {
|
|
16
|
+
node.error('MPL115A2 init failed: ' + e.message);
|
|
17
|
+
}
|
|
18
|
+
node.on('close', function() {
|
|
19
|
+
if (node.connection) node.connection.close();
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
RED.nodes.registerType('mpl115a2-device', MPL115A2DeviceNode);
|
|
23
|
+
|
|
24
|
+
function MPL115A2ReadNode(config) {
|
|
25
|
+
RED.nodes.createNode(this, config);
|
|
26
|
+
const node = this;
|
|
27
|
+
node.device = RED.nodes.getNode(config.device);
|
|
28
|
+
|
|
29
|
+
node.on('input', async function(msg, send, done) {
|
|
30
|
+
if (!node.device || !node.device.driver) {
|
|
31
|
+
node.error('No MPL115A2 device configured', msg);
|
|
32
|
+
done();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const r = await node.device.driver.read();
|
|
37
|
+
msg.payload = { pressure_pa: r.pressure_pa, temperature_c: r.temperature_c };
|
|
38
|
+
send(msg);
|
|
39
|
+
done();
|
|
40
|
+
} catch (e) {
|
|
41
|
+
done(e);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
RED.nodes.registerType('periph-mpl115a2', MPL115A2ReadNode);
|
|
46
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-pressure",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "Node-RED nodes for pressure sensor chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
"bmp581": "nodes/bmp581/bmp581.js",
|
|
20
20
|
"lps28dfw": "nodes/lps28dfw/lps28dfw.js",
|
|
21
21
|
"lps33hw": "nodes/lps33hw/lps33hw.js",
|
|
22
|
-
"
|
|
22
|
+
"lps22hb": "nodes/lps22hb/lps22hb.js",
|
|
23
|
+
"lps22df": "nodes/lps22df/lps22df.js",
|
|
24
|
+
"mpl115a2": "nodes/mpl115a2/mpl115a2.js"
|
|
23
25
|
}
|
|
24
26
|
},
|
|
25
27
|
"dependencies": {
|