This project set for a while in an half-complete state (haven't we all done that?)
Revisting...
Here is the RFID gate card reader node that will open the gate by closing the "exit" button sensor on the keypad when a valid RFID tag is detected.
Raw RFID reader circuit on breadboard. This is the AdaFruit reader.
https://www.adafruit.com/?q=pn532 I have the node detecting presented cards and sending the card ID back to the Gateway as a new metric type called RFID which looks like this
Hello!
Transmitting at 433 Mhz...
RFM69_ATC Enabled (Auto Transmission Control)
Found chip PN532
Firmware ver. 1.6
Waiting for an ISO14443A Card ...
Found an ISO14443A card
UID Length: 4 bytes
UID Value: 0x50 0x07 0xDE 0x16
RFID ACK:NOK...RFID UID:5007de16 BAT:4.2v <--- I took the 4 byte UID and jammed it into a string.
Edit - Felix tells me that using hex (basically a string) has problems in that each unique code has to be predetermined and defined. This works OK with the known cards, but not the unknown cards. Therefore, it would be best to just convert to numeric equivalents of the hex strings. The strings are either 4 or 7 bytes, my cards are all 4 bytes which would yield a maximum number of 0xFFFFFFFF or 4,294,967,295. Not sure if that pushes any boundaries of data types?? On the other hand, maybe we just code the known codes and hopefully we can get a deny for any unknown ones. Experimentation will tell....
I created an RFID Mot type of node in the gateway metrics.js file with:
RFIDMote: {
label : 'RFID Sensor',
icon : 'icon_sonar.png', <-- create one
settings: { lowVoltageValue: '' }, //blank will make it inherit from global settings.json lowVoltageValue, a specific value overrides the general setting, user can always choose his own setting in the UI
},
and defined a metric in the same file so that the gateway would recognize the UID tag coming in from presented cards
RFID_UID: { name:'UID', regexp:/UID\:([0-9a-fA-F]+)/i, value:'', unit:'', },
Now I am moving on to trying to figure out how to get the gateway to respond to the presented card with either an 'accepted' or 'denied' action. The action can be matured but for now even a simple beep would suffice.
I'll start with the simple beep sound and steal from the MotionMot alert sound
motionAlert : { label:'Motion : Alert', icon:'audio', descr:'Alert sound when MOTION is detected', serverExecute:function(node) { if (node.metrics['M'] && node.metrics['M'].value == 'MOTION' && (Date.now() - new Date(node.metrics['M'].updated).getTime() < 2000)) { io.sockets.emit('PLAYSOUND', 'sounds/alert.wav'); }; } },
Maybe going with
RFIDAlert : { label:'RFID : Card Detected', icon:'audio', descr:'Alert sound when RFID Card is detected',
serverExecute:function(node) {
if (node.metrics['UID'] && node.metrics['UID'].value == '5007de16' ) {
io.sockets.emit('PLAYSOUND', 'sounds/alert.wav');
}; <-- what is with this semicolon? Can I put an 'else' clause here?
}
},
Would the 'else' look like this? Specific question about that semi-colon. At a bare minimum, I could hard-code the allowable cards. There will be 10-20 of them in typical usage.
RFIDAlert : { label:'RFID : Card Detected', icon:'audio', descr:'Alert sound when RFID Card is detected',
serverExecute:function(node) {
if (node.metrics['UID'] && node.metrics['UID'].value == '5007de16' ) {
io.sockets.emit('PLAYSOUND', 'sounds/access_granted.wav');
} else {
io.sockets.emit('PLAYSOUND', 'sounds/access_denied.wav');
}; <-- what is with this semicolon?
}
},
Here are some sounds that might be cool:
https://freesound.org/people/EthanolProductions/sounds/215004/ for Access Granted and there are many others to play with.