node-red-contrib-periph-rfid 1.1.0 → 1.2.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
@@ -2,15 +2,23 @@
2
2
 
3
3
  Node-RED nodes for RFID and NFC peripheral 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-rfid`.
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-rfid
11
13
  ```
12
14
 
15
+ ## Nodes
16
+
17
+ | Node | Kind | Description |
18
+ |------|------|-------------|
19
+ | `periph-mfrc522` | input | Detects ISO/IEC 14443 Type A cards in the field of an NXP MFRC522 13.56 MHz RFID/NFC reader and reads their UID. The node polls the chip on the configured interval and only emits a message when the card state changes (card inserted, removed, or a different card presented). |
20
+
13
21
  ## Links
14
22
 
15
23
  - [GitHub](https://github.com/tuhde/Periph)
16
- - [All supported chips](https://github.com/tuhde/Periph#supported-chips)
24
+ - [periph JS driver](https://www.npmjs.com/package/periph)
@@ -0,0 +1,106 @@
1
+ [
2
+ {
3
+ "id": "tab.rfid.mfrc522",
4
+ "type": "tab",
5
+ "label": "MFRC522 RFID card detection",
6
+ "info": "Polls an NXP MFRC522 13.56 MHz RFID/NFC reader on the configured interval and reports card detection events. A flow function formats the UID into a human-readable string for the debug panel; another debug node shows the raw payload on every poll for troubleshooting."
7
+ },
8
+ {
9
+ "id": "inject.mfrc522.poll",
10
+ "type": "inject",
11
+ "z": "tab.rfid.mfrc522",
12
+ "name": "poll every 500 ms",
13
+ "props": [{ "p": "payload" }],
14
+ "repeat": "0.5",
15
+ "crontab": "",
16
+ "once": false,
17
+ "onceDelay": 0.1,
18
+ "topic": "",
19
+ "payload": "",
20
+ "payloadType": "date",
21
+ "x": 180,
22
+ "y": 120,
23
+ "wires": [["node.mfrc522"]]
24
+ },
25
+ {
26
+ "id": "node.mfrc522",
27
+ "type": "periph-mfrc522",
28
+ "z": "tab.rfid.mfrc522",
29
+ "name": "MFRC522 reader",
30
+ "bus": "0",
31
+ "device": "0",
32
+ "speed": "1000000",
33
+ "pollInterval": "500",
34
+ "x": 420,
35
+ "y": 120,
36
+ "wires": [["switch.mfrc522", "debug.mfrc522.raw"]]
37
+ },
38
+ {
39
+ "id": "switch.mfrc522",
40
+ "type": "switch",
41
+ "z": "tab.rfid.mfrc522",
42
+ "name": "card present?",
43
+ "property": "payload.present",
44
+ "propertyType": "msg",
45
+ "rules": [
46
+ { "t": "true" }
47
+ ],
48
+ "checkall": "true",
49
+ "repair": false,
50
+ "outputs": 1,
51
+ "x": 680,
52
+ "y": 120,
53
+ "wires": [["change.mfrc522.label"]]
54
+ },
55
+ {
56
+ "id": "change.mfrc522.label",
57
+ "type": "change",
58
+ "z": "tab.rfid.mfrc522",
59
+ "name": "format label",
60
+ "rules": [
61
+ { "t": "set", "p": "payload", "pt": "msg", "to": "(\"Card detected: \" & msg.payload.uid)", "tot": "jsonata" }
62
+ ],
63
+ "action": "",
64
+ "property": "",
65
+ "from": "",
66
+ "to": "",
67
+ "reg": false,
68
+ "x": 880,
69
+ "y": 120,
70
+ "wires": [["debug.mfrc522.detected"]]
71
+ },
72
+ {
73
+ "id": "debug.mfrc522.detected",
74
+ "type": "debug",
75
+ "z": "tab.rfid.mfrc522",
76
+ "name": "detected",
77
+ "active": true,
78
+ "tosidebar": true,
79
+ "console": false,
80
+ "tostatus": false,
81
+ "complete": "payload",
82
+ "targetType": "msg",
83
+ "statusVal": "",
84
+ "statusType": "auto",
85
+ "x": 1080,
86
+ "y": 120,
87
+ "wires": []
88
+ },
89
+ {
90
+ "id": "debug.mfrc522.raw",
91
+ "type": "debug",
92
+ "z": "tab.rfid.mfrc522",
93
+ "name": "raw payload",
94
+ "active": true,
95
+ "tosidebar": true,
96
+ "console": false,
97
+ "tostatus": false,
98
+ "complete": "payload",
99
+ "targetType": "msg",
100
+ "statusVal": "",
101
+ "statusType": "auto",
102
+ "x": 680,
103
+ "y": 200,
104
+ "wires": []
105
+ }
106
+ ]
package/index.js ADDED
@@ -0,0 +1,11 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ module.exports = function(RED) {
5
+ const nodesDir = path.join(__dirname, 'nodes');
6
+ if (!fs.existsSync(nodesDir)) return;
7
+ fs.readdirSync(nodesDir).forEach(function(chip) {
8
+ const nodeFile = path.join(nodesDir, chip, chip + '.js');
9
+ if (fs.existsSync(nodeFile)) require(nodeFile)(RED);
10
+ });
11
+ };
@@ -0,0 +1,56 @@
1
+ <script type="text/javascript">
2
+ RED.nodes.registerType('periph-mfrc522', {
3
+ category: 'Peripheral',
4
+ color: '#C084FC',
5
+ defaults: {
6
+ name: { value: '' },
7
+ bus: { value: '0', required: true, validate: RED.validators.number() },
8
+ device: { value: '0', required: true, validate: RED.validators.number() },
9
+ speed: { value: '1000000', required: true, validate: RED.validators.number() },
10
+ pollInterval:{ value: '500', validate: RED.validators.number() }
11
+ },
12
+ inputs: 0,
13
+ outputs: 1,
14
+ icon: 'font-awesome/fa-id-card',
15
+ label: function() { return this.name || 'MFRC522'; },
16
+ paletteLabel: 'MFRC522'
17
+ });
18
+ </script>
19
+
20
+ <script type="text/html" data-template-name="periph-mfrc522">
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="MFRC522">
24
+ </div>
25
+ <div class="form-row">
26
+ <label for="node-input-bus"><i class="fa fa-microchip"></i> SPI bus</label>
27
+ <input type="number" id="node-input-bus" min="0" style="width:80px">
28
+ </div>
29
+ <div class="form-row">
30
+ <label for="node-input-device"><i class="fa fa-microchip"></i> SPI device (CS)</label>
31
+ <input type="number" id="node-input-device" min="0" style="width:80px">
32
+ </div>
33
+ <div class="form-row">
34
+ <label for="node-input-speed"><i class="fa fa-cog"></i> SPI speed (Hz)</label>
35
+ <input type="number" id="node-input-speed" min="0" style="width:120px">
36
+ </div>
37
+ <div class="form-row">
38
+ <label for="node-input-pollInterval"><i class="fa fa-clock-o"></i> Poll interval (ms)</label>
39
+ <input type="number" id="node-input-pollInterval" min="0" style="width:80px">
40
+ </div>
41
+ </script>
42
+
43
+ <script type="text/html" data-help-name="periph-mfrc522">
44
+ <p>Detects ISO/IEC 14443 Type A cards in the field of an NXP MFRC522 13.56 MHz RFID/NFC reader and reads their UID. The node polls the chip on the configured interval and only emits a message when the card state changes (card inserted, removed, or a different card presented).</p>
45
+
46
+ <h3>Outputs</h3>
47
+ <dl class="message-properties">
48
+ <dt>payload.present <span class="property-type">boolean</span></dt>
49
+ <dd>True if a card is currently in the field.</dd>
50
+ <dt>payload.uid <span class="property-type">string</span></dt>
51
+ <dd>Hex-encoded UID of the card (e.g. <code>"04a1b2c3"</code>), or <code>null</code> when no card is present.</dd>
52
+ </dl>
53
+
54
+ <h3>Configuration</h3>
55
+ <p>Set the SPI bus number, the SPI device (CS) number, the SPI clock frequency (default 1 MHz), and the poll interval in milliseconds (default 500 ms).</p>
56
+ </script>
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ module.exports = function(RED) {
4
+ const { SPIConnection } = require('periph/src/connection/spi');
5
+ const { MFRC522Full } = require('periph/src/chips/rfid/mfrc522');
6
+
7
+ function MFRC522Node(config) {
8
+ RED.nodes.createNode(this, config);
9
+ const node = this;
10
+ try {
11
+ const connection = new SPIConnection(
12
+ parseInt(config.bus, 10),
13
+ parseInt(config.device, 10),
14
+ { maxSpeedHz: parseInt(config.speed, 10) || 1000000, mode: 0 }
15
+ );
16
+ node.driver = new MFRC522Full(connection);
17
+ node.connection = connection;
18
+ node.pollMs = parseInt(config.pollInterval, 10) || 500;
19
+ node._timer = null;
20
+ node._lastUid = null;
21
+
22
+ const tick = async function() {
23
+ if (!node.driver) return;
24
+ try {
25
+ const present = await node.driver.isCardPresent();
26
+ let uid = null;
27
+ if (present) {
28
+ const buf = await node.driver.readUid();
29
+ if (buf) uid = buf.toString('hex');
30
+ }
31
+ if (uid !== node._lastUid) {
32
+ node._lastUid = uid;
33
+ const msg = { payload: { present: present, uid: uid } };
34
+ node.send(msg);
35
+ }
36
+ } catch (e) {
37
+ node.error('MFRC522 poll failed: ' + e.message);
38
+ }
39
+ };
40
+
41
+ node._timer = setInterval(tick, node.pollMs);
42
+ } catch (e) {
43
+ node.error('MFRC522 init failed: ' + e.message);
44
+ }
45
+ node.on('close', function() {
46
+ if (node._timer) { clearInterval(node._timer); node._timer = null; }
47
+ if (node.connection) node.connection.close();
48
+ });
49
+ }
50
+ RED.nodes.registerType('periph-mfrc522', MFRC522Node);
51
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-rfid",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "Node-RED nodes for RFID and NFC peripheral chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -11,7 +11,9 @@
11
11
  "peripheral"
12
12
  ],
13
13
  "node-red": {
14
- "nodes": {}
14
+ "nodes": {
15
+ "mfrc522": "nodes/mfrc522/mfrc522.js"
16
+ }
15
17
  },
16
18
  "dependencies": {
17
19
  "periph": "*"