node-red-contrib-periph-rfid 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 CHANGED
@@ -16,7 +16,8 @@ npm install node-red-contrib-periph-rfid
16
16
 
17
17
  | Node | Kind | Description |
18
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). |
19
+ | `mfrc522-device` | config | Bus configuration for a MFRC522 |
20
+ | `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
21
 
21
22
  ## Links
22
23
 
@@ -10,7 +10,11 @@
10
10
  "type": "inject",
11
11
  "z": "tab.rfid.mfrc522",
12
12
  "name": "poll every 500 ms",
13
- "props": [{ "p": "payload" }],
13
+ "props": [
14
+ {
15
+ "p": "payload"
16
+ }
17
+ ],
14
18
  "repeat": "0.5",
15
19
  "crontab": "",
16
20
  "once": false,
@@ -20,20 +24,35 @@
20
24
  "payloadType": "date",
21
25
  "x": 180,
22
26
  "y": 120,
23
- "wires": [["node.mfrc522"]]
27
+ "wires": [
28
+ [
29
+ "node.mfrc522"
30
+ ]
31
+ ]
32
+ },
33
+ {
34
+ "id": "mfrc522-device-1",
35
+ "type": "mfrc522-device",
36
+ "name": "MFRC522",
37
+ "device": "0",
38
+ "speed": "1000000",
39
+ "bus": "0",
40
+ "pollInterval": "500"
24
41
  },
25
42
  {
26
43
  "id": "node.mfrc522",
27
- "type": "periph-mfrc522",
44
+ "type": "mfrc522",
28
45
  "z": "tab.rfid.mfrc522",
29
46
  "name": "MFRC522 reader",
30
- "bus": "0",
31
- "device": "0",
32
- "speed": "1000000",
33
- "pollInterval": "500",
47
+ "device": "mfrc522-device-1",
34
48
  "x": 420,
35
49
  "y": 120,
36
- "wires": [["switch.mfrc522", "debug.mfrc522.raw"]]
50
+ "wires": [
51
+ [
52
+ "switch.mfrc522",
53
+ "debug.mfrc522.raw"
54
+ ]
55
+ ]
37
56
  },
38
57
  {
39
58
  "id": "switch.mfrc522",
@@ -43,14 +62,20 @@
43
62
  "property": "payload.present",
44
63
  "propertyType": "msg",
45
64
  "rules": [
46
- { "t": "true" }
65
+ {
66
+ "t": "true"
67
+ }
47
68
  ],
48
69
  "checkall": "true",
49
70
  "repair": false,
50
71
  "outputs": 1,
51
72
  "x": 680,
52
73
  "y": 120,
53
- "wires": [["change.mfrc522.label"]]
74
+ "wires": [
75
+ [
76
+ "change.mfrc522.label"
77
+ ]
78
+ ]
54
79
  },
55
80
  {
56
81
  "id": "change.mfrc522.label",
@@ -58,7 +83,13 @@
58
83
  "z": "tab.rfid.mfrc522",
59
84
  "name": "format label",
60
85
  "rules": [
61
- { "t": "set", "p": "payload", "pt": "msg", "to": "(\"Card detected: \" & msg.payload.uid)", "tot": "jsonata" }
86
+ {
87
+ "t": "set",
88
+ "p": "payload",
89
+ "pt": "msg",
90
+ "to": "(\"Card detected: \" & msg.payload.uid)",
91
+ "tot": "jsonata"
92
+ }
62
93
  ],
63
94
  "action": "",
64
95
  "property": "",
@@ -67,7 +98,11 @@
67
98
  "reg": false,
68
99
  "x": 880,
69
100
  "y": 120,
70
- "wires": [["debug.mfrc522.detected"]]
101
+ "wires": [
102
+ [
103
+ "debug.mfrc522.detected"
104
+ ]
105
+ ]
71
106
  },
72
107
  {
73
108
  "id": "debug.mfrc522.detected",
@@ -1,7 +1,7 @@
1
+ <!-- Config node: one instance per physical device -->
1
2
  <script type="text/javascript">
2
- RED.nodes.registerType('periph-mfrc522', {
3
- category: 'Peripheral',
4
- color: '#C084FC',
3
+ RED.nodes.registerType('mfrc522-device', {
4
+ category: 'config',
5
5
  defaults: {
6
6
  name: { value: '' },
7
7
  bus: { value: '0', required: true, validate: RED.validators.number() },
@@ -9,6 +9,44 @@
9
9
  speed: { value: '1000000', required: true, validate: RED.validators.number() },
10
10
  pollInterval:{ value: '500', validate: RED.validators.number() }
11
11
  },
12
+ label: function() {
13
+ return this.name || 'MFRC522';
14
+ }
15
+ });
16
+ </script>
17
+
18
+ <script type="text/html" data-template-name="mfrc522-device">
19
+ <div class="form-row">
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="MFRC522">
22
+ </div>
23
+ <div class="form-row">
24
+ <label for="node-config-input-bus"><i class="fa fa-microchip"></i> SPI bus</label>
25
+ <input type="number" id="node-config-input-bus" min="0" style="width:80px">
26
+ </div>
27
+ <div class="form-row">
28
+ <label for="node-config-input-device"><i class="fa fa-microchip"></i> SPI device (CS)</label>
29
+ <input type="number" id="node-config-input-device" min="0" style="width:80px">
30
+ </div>
31
+ <div class="form-row">
32
+ <label for="node-config-input-speed"><i class="fa fa-cog"></i> SPI speed (Hz)</label>
33
+ <input type="number" id="node-config-input-speed" min="0" style="width:120px">
34
+ </div>
35
+ <div class="form-row">
36
+ <label for="node-config-input-pollInterval"><i class="fa fa-clock-o"></i> Poll interval (ms)</label>
37
+ <input type="number" id="node-config-input-pollInterval" min="0" style="width:80px">
38
+ </div>
39
+ </script>
40
+
41
+ <!-- Read node -->
42
+ <script type="text/javascript">
43
+ RED.nodes.registerType('mfrc522', {
44
+ category: 'Peripheral',
45
+ color: '#C084FC',
46
+ defaults: {
47
+ name: { value: '' },
48
+ device: { value: '', type: 'mfrc522-device', required: true }
49
+ },
12
50
  inputs: 0,
13
51
  outputs: 1,
14
52
  icon: 'font-awesome/fa-id-card',
@@ -17,30 +55,18 @@
17
55
  });
18
56
  </script>
19
57
 
20
- <script type="text/html" data-template-name="periph-mfrc522">
58
+ <script type="text/html" data-template-name="mfrc522">
21
59
  <div class="form-row">
22
60
  <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
23
61
  <input type="text" id="node-input-name" placeholder="MFRC522">
24
62
  </div>
25
63
  <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">
64
+ <label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
65
+ <input type="text" id="node-input-device">
40
66
  </div>
41
67
  </script>
42
68
 
43
- <script type="text/html" data-help-name="periph-mfrc522">
69
+ <script type="text/html" data-help-name="mfrc522">
44
70
  <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
71
 
46
72
  <h3>Outputs</h3>
@@ -4,7 +4,7 @@ module.exports = function(RED) {
4
4
  const { SPIConnection } = require('periph/src/connection/spi');
5
5
  const { MFRC522Full } = require('periph/src/chips/rfid/mfrc522');
6
6
 
7
- function MFRC522Node(config) {
7
+ function MFRC522DeviceNode(config) {
8
8
  RED.nodes.createNode(this, config);
9
9
  const node = this;
10
10
  try {
@@ -31,7 +31,7 @@ module.exports = function(RED) {
31
31
  if (uid !== node._lastUid) {
32
32
  node._lastUid = uid;
33
33
  const msg = { payload: { present: present, uid: uid } };
34
- node.send(msg);
34
+ node.emit('periph-data', msg);
35
35
  }
36
36
  } catch (e) {
37
37
  node.error('MFRC522 poll failed: ' + e.message);
@@ -47,5 +47,20 @@ module.exports = function(RED) {
47
47
  if (node.connection) node.connection.close();
48
48
  });
49
49
  }
50
- RED.nodes.registerType('periph-mfrc522', MFRC522Node);
50
+ RED.nodes.registerType('mfrc522-device', MFRC522DeviceNode);
51
+
52
+ // Reader node: forwards each card-present / card-removed event polled by the device node.
53
+ function MFRC522ReadNode(config) {
54
+ RED.nodes.createNode(this, config);
55
+ const node = this;
56
+ const deviceNode = RED.nodes.getNode(config.device);
57
+ if (!deviceNode) {
58
+ node.error('No MFRC522 device configured');
59
+ return;
60
+ }
61
+ const onData = (msg) => node.send(msg);
62
+ deviceNode.on('periph-data', onData);
63
+ node.on('close', () => deviceNode.removeListener('periph-data', onData));
64
+ }
65
+ RED.nodes.registerType('mfrc522', MFRC522ReadNode);
51
66
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-rfid",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "Node-RED nodes for RFID and NFC peripheral chips",
5
5
  "keywords": [
6
6
  "node-red",
package/index.js DELETED
@@ -1,11 +0,0 @@
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
- };