node-red-contrib-periph-rfid 1.5.3 → 1.6.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 +4 -2
- package/examples/pn532/demo.json +94 -0
- package/nodes/pn532/pn532.html +77 -0
- package/nodes/pn532/pn532.js +52 -0
- package/package.json +19 -5
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# node-red-contrib-periph-rfid
|
|
2
2
|
|
|
3
|
-
Node-RED nodes for RFID and NFC peripheral chips: MFRC522 — part of the [Periph](https://github.com/tuhde/Periph) library.
|
|
3
|
+
Node-RED nodes for RFID and NFC peripheral chips: MFRC522, PN532 — part of the [Periph](https://github.com/tuhde/Periph) library.
|
|
4
4
|
|
|
5
|
-
**Supported chips (
|
|
5
|
+
**Supported chips (2):** MFRC522, PN532.
|
|
6
6
|
|
|
7
7
|
Each chip has a sensor/actuator node plus a shared `-device` config node that holds the bus settings. Importable example flows are in [`examples/`](https://github.com/tuhde/Periph/tree/main/nodejs/packages/node-red-contrib-periph-rfid/examples).
|
|
8
8
|
|
|
@@ -22,6 +22,8 @@ npm install node-red-contrib-periph-rfid
|
|
|
22
22
|
|------|------|-------------|
|
|
23
23
|
| `mfrc522-device` | config | Bus configuration for a MFRC522 |
|
|
24
24
|
| `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). |
|
|
25
|
+
| `pn532-device` | config | Bus configuration for a PN532 |
|
|
26
|
+
| `pn532` | input | Detects an ISO/IEC 14443 A card or tag (MIFARE, NTAG) with an NXP PN532 NFC controller over I²C (address 0x24) and outputs its UID, one detection per message. |
|
|
25
27
|
|
|
26
28
|
## Links
|
|
27
29
|
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "pn532-tab",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "PN532 card reader",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Polls a PN532 NFC reader once per second. Each poll runs one card detection (106 kbps ISO/IEC 14443 A) and returns the UID as a hex string, or null when no card is on the reader. The switch node passes only detections with a UID, so the debug sidebar lists every card presented. Change the inject interval to poll faster, or the read timeout on the PN532 node to wait longer per poll."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "pn532-inject",
|
|
11
|
+
"type": "inject",
|
|
12
|
+
"z": "pn532-tab",
|
|
13
|
+
"name": "1 s timer",
|
|
14
|
+
"props": [
|
|
15
|
+
{
|
|
16
|
+
"p": "payload"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"repeat": "1",
|
|
20
|
+
"crontab": "",
|
|
21
|
+
"once": false,
|
|
22
|
+
"onceDelay": 0.1,
|
|
23
|
+
"topic": "",
|
|
24
|
+
"payloadType": "date",
|
|
25
|
+
"x": 160,
|
|
26
|
+
"y": 160,
|
|
27
|
+
"wires": [
|
|
28
|
+
[
|
|
29
|
+
"pn532-node"
|
|
30
|
+
]
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "pn532-device-1",
|
|
35
|
+
"type": "pn532-device",
|
|
36
|
+
"name": "PN532",
|
|
37
|
+
"bus": "1"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"id": "pn532-node",
|
|
41
|
+
"type": "pn532",
|
|
42
|
+
"z": "pn532-tab",
|
|
43
|
+
"name": "PN532",
|
|
44
|
+
"timeout": "1.0",
|
|
45
|
+
"x": 340,
|
|
46
|
+
"y": 160,
|
|
47
|
+
"wires": [
|
|
48
|
+
[
|
|
49
|
+
"pn532-switch"
|
|
50
|
+
]
|
|
51
|
+
],
|
|
52
|
+
"device": "pn532-device-1"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"id": "pn532-switch",
|
|
56
|
+
"type": "switch",
|
|
57
|
+
"z": "pn532-tab",
|
|
58
|
+
"name": "card present",
|
|
59
|
+
"property": "payload.uid",
|
|
60
|
+
"propertyType": "msg",
|
|
61
|
+
"rules": [
|
|
62
|
+
{
|
|
63
|
+
"t": "nnull"
|
|
64
|
+
}
|
|
65
|
+
],
|
|
66
|
+
"checkall": "true",
|
|
67
|
+
"repair": false,
|
|
68
|
+
"outputs": 1,
|
|
69
|
+
"x": 520,
|
|
70
|
+
"y": 160,
|
|
71
|
+
"wires": [
|
|
72
|
+
[
|
|
73
|
+
"pn532-debug"
|
|
74
|
+
]
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"id": "pn532-debug",
|
|
79
|
+
"type": "debug",
|
|
80
|
+
"z": "pn532-tab",
|
|
81
|
+
"name": "UID",
|
|
82
|
+
"active": true,
|
|
83
|
+
"tosidebar": true,
|
|
84
|
+
"console": false,
|
|
85
|
+
"tostatus": true,
|
|
86
|
+
"complete": "payload.uid",
|
|
87
|
+
"targetType": "msg",
|
|
88
|
+
"statusVal": "payload.uid",
|
|
89
|
+
"statusType": "msg",
|
|
90
|
+
"x": 700,
|
|
91
|
+
"y": 160,
|
|
92
|
+
"wires": []
|
|
93
|
+
}
|
|
94
|
+
]
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('pn532-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 || ('PN532 @ 0x24 (bus ' + this.bus + ')');
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script type="text/html" data-template-name="pn532-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="PN532">
|
|
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, address 0x24)
|
|
23
|
+
</div>
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<!-- Read node -->
|
|
27
|
+
<script type="text/javascript">
|
|
28
|
+
RED.nodes.registerType('pn532', {
|
|
29
|
+
category: 'Peripheral',
|
|
30
|
+
color: '#C084FC',
|
|
31
|
+
defaults: {
|
|
32
|
+
name: { value: '' },
|
|
33
|
+
device: { value: '', type: 'pn532-device', required: true },
|
|
34
|
+
timeout: { value: '1.0', required: true, validate: RED.validators.number() }
|
|
35
|
+
},
|
|
36
|
+
inputs: 1,
|
|
37
|
+
outputs: 1,
|
|
38
|
+
icon: 'bridge.svg',
|
|
39
|
+
label: function() { return this.name || 'PN532'; },
|
|
40
|
+
paletteLabel: 'PN532'
|
|
41
|
+
});
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<script type="text/html" data-template-name="pn532">
|
|
45
|
+
<div class="form-row">
|
|
46
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
47
|
+
<input type="text" id="node-input-name" placeholder="PN532">
|
|
48
|
+
</div>
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
51
|
+
<input type="text" id="node-input-device">
|
|
52
|
+
</div>
|
|
53
|
+
<div class="form-row">
|
|
54
|
+
<label for="node-input-timeout"><i class="fa fa-clock-o"></i> Read timeout (s)</label>
|
|
55
|
+
<input type="number" id="node-input-timeout" min="0.01" step="0.1" style="width:80px">
|
|
56
|
+
</div>
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<script type="text/html" data-help-name="pn532">
|
|
60
|
+
<p>Detects an ISO/IEC 14443 A card or tag (MIFARE, NTAG) with an NXP PN532 NFC controller over
|
|
61
|
+
I²C (address 0x24) and outputs its UID, one detection per message.</p>
|
|
62
|
+
<h3>Inputs</h3>
|
|
63
|
+
<dl class="message-properties">
|
|
64
|
+
<dt>payload <span class="property-type">any</span></dt>
|
|
65
|
+
<dd>Any incoming message triggers one card detection (InListPassiveTarget at 106 kbps).</dd>
|
|
66
|
+
</dl>
|
|
67
|
+
<h3>Outputs</h3>
|
|
68
|
+
<dl class="message-properties">
|
|
69
|
+
<dt>payload.uid <span class="property-type">string | null</span></dt>
|
|
70
|
+
<dd>The card's UID (NFCID1, 4, 7 or 10 bytes) as an upper-case hex string, or <code>null</code>
|
|
71
|
+
when no card answered within the read timeout.</dd>
|
|
72
|
+
</dl>
|
|
73
|
+
<h3>Configuration</h3>
|
|
74
|
+
<p>The I²C bus number is set in the <b>pn532-device</b> config node; the chip must be wired for
|
|
75
|
+
I²C (I0 low, I1 high). The read timeout (default 1 s) is set on this node. The card is released
|
|
76
|
+
after each read, so a card left on the reader is reported again on the next message.</p>
|
|
77
|
+
</script>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { PN532Full } = require('periph/src/chips/rfid/pn532');
|
|
6
|
+
|
|
7
|
+
function PN532DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus, 10), 0x24);
|
|
12
|
+
node.connection = connection;
|
|
13
|
+
node.driver = new PN532Full(connection);
|
|
14
|
+
node.ready = node.driver.init();
|
|
15
|
+
node.ready.catch((e) => {
|
|
16
|
+
node.error('PN532 init failed: ' + e.message);
|
|
17
|
+
});
|
|
18
|
+
} catch (e) {
|
|
19
|
+
node.error('PN532 init failed: ' + e.message);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
node.on('close', function() {
|
|
23
|
+
if (node.connection) node.connection.close();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
RED.nodes.registerType('pn532-device', PN532DeviceNode);
|
|
27
|
+
|
|
28
|
+
function PN532ReadNode(config) {
|
|
29
|
+
RED.nodes.createNode(this, config);
|
|
30
|
+
const node = this;
|
|
31
|
+
const deviceNode = RED.nodes.getNode(config.device) || {};
|
|
32
|
+
const timeout = parseFloat(config.timeout) || 1.0;
|
|
33
|
+
|
|
34
|
+
node.on('input', async function(msg, send, done) {
|
|
35
|
+
if (!deviceNode.driver) {
|
|
36
|
+
node.error('PN532 not initialised', msg);
|
|
37
|
+
done();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
try {
|
|
41
|
+
await deviceNode.ready;
|
|
42
|
+
const uid = await deviceNode.driver.readUid(timeout);
|
|
43
|
+
msg.payload = { uid: uid ? uid.toString('hex').toUpperCase() : null };
|
|
44
|
+
send(msg);
|
|
45
|
+
done();
|
|
46
|
+
} catch (e) {
|
|
47
|
+
done(e);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
RED.nodes.registerType('pn532', PN532ReadNode);
|
|
52
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-rfid",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Node-RED nodes for RFID and NFC peripheral chips: MFRC522",
|
|
3
|
+
"version": "1.6.0",
|
|
4
|
+
"description": "Node-RED nodes for RFID and NFC peripheral chips: MFRC522, PN532",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
7
7
|
"rfid",
|
|
@@ -10,16 +10,30 @@
|
|
|
10
10
|
"i2c",
|
|
11
11
|
"peripheral",
|
|
12
12
|
"node-red-contrib",
|
|
13
|
-
"mfrc522"
|
|
13
|
+
"mfrc522",
|
|
14
|
+
"pn532"
|
|
14
15
|
],
|
|
15
16
|
"node-red": {
|
|
16
17
|
"version": ">=3.0.0",
|
|
17
18
|
"nodes": {
|
|
18
|
-
"mfrc522": "nodes/mfrc522/mfrc522.js"
|
|
19
|
+
"mfrc522": "nodes/mfrc522/mfrc522.js",
|
|
20
|
+
"pn532": "nodes/pn532/pn532.js"
|
|
19
21
|
}
|
|
20
22
|
},
|
|
21
23
|
"dependencies": {
|
|
22
24
|
"periph": "*"
|
|
23
25
|
},
|
|
24
|
-
"license": "MIT"
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=18"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/tuhde/Periph/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/tuhde/Periph/tree/main/nodejs/packages/node-red-contrib-periph-rfid#readme",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/tuhde/Periph.git",
|
|
37
|
+
"directory": "nodejs/packages/node-red-contrib-periph-rfid"
|
|
38
|
+
}
|
|
25
39
|
}
|