node-red-contrib-periph-temperature 1.3.3 → 1.5.0

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 CHANGED
@@ -17,6 +17,7 @@ npm install node-red-contrib-periph-temperature
17
17
  | Node | Kind | Description |
18
18
  |------|------|-------------|
19
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-tmp102` | input | Reads the temperature from a TMP102 12-bit digital temperature sensor over I²C. |
20
21
  | `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
22
 
22
23
  ## Links
@@ -0,0 +1,64 @@
1
+ [
2
+ {
3
+ "id": "tab-tmp102-demo",
4
+ "type": "tab",
5
+ "label": "TMP102 Temperature Demo",
6
+ "disabled": false,
7
+ "info": "An Inject node fires every second, triggering the periph-tmp102 node to read the temperature (12-bit, 0.0625 °C resolution, 4 Hz conversion rate). A Function node formats the reading as \"%.2f °C\" and a Debug node shows it in the sidebar. Change the conversion rate or the I²C address in the node's configuration panel (0x48-0x4B depending on the ADD0 strap)."
8
+ },
9
+ {
10
+ "id": "inj-read",
11
+ "type": "inject",
12
+ "name": "Read temperature (1s)",
13
+ "topic": "",
14
+ "payload": "",
15
+ "payloadType": "date",
16
+ "repeat": "1",
17
+ "crontab": "",
18
+ "once": true,
19
+ "onceDelay": 1,
20
+ "z": "tab-tmp102-demo",
21
+ "x": 160,
22
+ "y": 100,
23
+ "wires": [["tmp102-node"]]
24
+ },
25
+ {
26
+ "id": "tmp102-node",
27
+ "type": "periph-tmp102",
28
+ "name": "TMP102",
29
+ "bus": "1",
30
+ "address": "0x48",
31
+ "conversionRate": "4",
32
+ "z": "tab-tmp102-demo",
33
+ "x": 380,
34
+ "y": 100,
35
+ "wires": [["fn-format"]]
36
+ },
37
+ {
38
+ "id": "fn-format",
39
+ "type": "function",
40
+ "name": "format %.2f °C",
41
+ "func": "msg.payload = msg.payload.temperature.toFixed(2) + ' °C';\nreturn msg;",
42
+ "outputs": 1,
43
+ "noerr": 0,
44
+ "z": "tab-tmp102-demo",
45
+ "x": 600,
46
+ "y": 100,
47
+ "wires": [["dbg-temp"]]
48
+ },
49
+ {
50
+ "id": "dbg-temp",
51
+ "type": "debug",
52
+ "name": "Temperature",
53
+ "active": true,
54
+ "tosidebar": true,
55
+ "console": false,
56
+ "tostatus": true,
57
+ "complete": "payload",
58
+ "targetType": "msg",
59
+ "z": "tab-tmp102-demo",
60
+ "x": 820,
61
+ "y": 100,
62
+ "wires": []
63
+ }
64
+ ]
@@ -0,0 +1,65 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-tmp102', {
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
+ conversionRate: { value: '4' }
10
+ },
11
+ inputs: 1,
12
+ outputs: 1,
13
+ icon: 'font-awesome/fa-thermometer-half',
14
+ label: function() { return this.name || 'TMP102'; },
15
+ paletteLabel: 'TMP102'
16
+ });
17
+ </script>
18
+
19
+ <script type="text/html" data-template-name="periph-tmp102">
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="TMP102">
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-map-marker"></i> I²C address</label>
30
+ <select id="node-input-address" style="width:200px">
31
+ <option value="0x48">0x48 (ADD0 = GND)</option>
32
+ <option value="0x49">0x49 (ADD0 = V+)</option>
33
+ <option value="0x4A">0x4A (ADD0 = SDA)</option>
34
+ <option value="0x4B">0x4B (ADD0 = SCL)</option>
35
+ </select>
36
+ </div>
37
+ <div class="form-row">
38
+ <label for="node-input-conversionRate"><i class="fa fa-clock-o"></i> Conversion rate</label>
39
+ <select id="node-input-conversionRate" style="width:200px">
40
+ <option value="0.25">0.25 Hz</option>
41
+ <option value="1">1 Hz</option>
42
+ <option value="4">4 Hz</option>
43
+ <option value="8">8 Hz</option>
44
+ </select>
45
+ </div>
46
+ </script>
47
+
48
+ <script type="text/html" data-help-name="periph-tmp102">
49
+ <p>Reads the temperature from a TMP102 12-bit digital temperature sensor over I²C.</p>
50
+
51
+ <h3>Inputs</h3>
52
+ <dl class="message-properties">
53
+ <dt>payload <span class="property-type">any</span></dt>
54
+ <dd>Any incoming message triggers a temperature read.</dd>
55
+ </dl>
56
+
57
+ <h3>Outputs</h3>
58
+ <dl class="message-properties">
59
+ <dt>payload.temperature <span class="property-type">number</span></dt>
60
+ <dd>Temperature in °C (0.0625 °C resolution).</dd>
61
+ </dl>
62
+
63
+ <h3>Configuration</h3>
64
+ <p>Set the I²C bus number, the address selected by the board's ADD0 strap (<code>0x48</code>–<code>0x4B</code>) and the conversion rate (0.25, 1, 4 or 8 Hz; default 4 Hz).</p>
65
+ </script>
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { I2CConnection } = require('periph/src/connection/i2c');
5
+ const { TMP102Full } = require('periph/src/chips/temperature/tmp102');
6
+
7
+ function TMP102Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+
11
+ try {
12
+ const address = parseInt(config.address, 16) || TMP102Full.I2C_ADDRESS;
13
+ const connection = new I2CConnection(parseInt(config.bus, 10), address);
14
+ node.driver = new TMP102Full(connection);
15
+ node.connection = connection;
16
+
17
+ const rate = parseFloat(config.conversionRate);
18
+ node.driver.setConversionRate(isNaN(rate) ? 4 : rate)
19
+ .catch((e) => node.error('TMP102 init failed: ' + e.message));
20
+ } catch (e) {
21
+ node.error('TMP102 init failed: ' + e.message);
22
+ }
23
+
24
+ node.on('input', async function(msg, send, done) {
25
+ if (!node.driver) { done(); return; }
26
+ try {
27
+ msg.payload = { temperature: await node.driver.readTemperature() };
28
+ send(msg);
29
+ done();
30
+ } catch (e) {
31
+ done(e);
32
+ }
33
+ });
34
+
35
+ node.on('close', async function(removed, done) {
36
+ try {
37
+ if (node.connection) await node.connection.close();
38
+ } catch (e) {
39
+ // bus may already be gone; nothing more to do on close
40
+ } finally {
41
+ done();
42
+ }
43
+ });
44
+ }
45
+ RED.nodes.registerType('periph-tmp102', TMP102Node);
46
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-temperature",
3
- "version": "1.3.3",
3
+ "version": "1.5.0",
4
4
  "description": "Node-RED nodes for temperature sensor chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -13,6 +13,7 @@
13
13
  "node-red": {
14
14
  "nodes": {
15
15
  "mcp9808": "nodes/mcp9808/mcp9808.js",
16
+ "tmp102": "nodes/tmp102/tmp102.js",
16
17
  "tmp117": "nodes/tmp117/tmp117.js"
17
18
  }
18
19
  },