Normal RFID Lock: a device which prevents something such as a door being opened and which you can only open with some specific RFID Tags.
RFID IoT Lock: a RFID lock connected to internet with some additional features:
- Access permission is managed by a server which allows flexibility in managing the system especially with multi-door and multi-user.
- The accessed history is stored in database
This video introduces a demonstration of unlocking the door of manager’s room.
Working flowA normal lock using RFID:
RFID IoT Lock:
Normal RFID lock is simple to implement. It does not require internet connection and database query as well. However, it has some drawbacks. Memory of embedded system is limited. The number keys are, therefore, limited. In the other hand, it’s inflexible to add/remove a key to/from the system (when loosing key, changing key or adding new key for new user) and change the privilege as well. In comparison with the normal RFID Lock, the RFID IoT lock is a little more complicated. However, it overcomes all drawbacks of the normal RFID lock. Additionally, history of access is stored, allowing to monitor/check who opens the door when needed.
Wiring Between PHPoC and Adafruit PN532For the sake of simplicity, I design only two simple tables in database without any FOREIGN KEY constraint.
Key table: to store key id and privilege. Key id in this example has a dual role: key identification and user identification. (It had better to divide this table into key table and user table). The privilege is to specify:
- -|----Field---------|-----Type----------|
- -| key_id | VARCHAR(20) |
- -| privilege | INTEGER |
History table: to keep history of opening door.
- -|----Field----------|-----Type----------|
- -| index_ | INTEGER |
- -| key_id | VARCHAR(20) |
- -| door_id | VARCHAR(20)|
- -| date_time |DATETIME |
Mysql script for creating database and tables.
CREATE DATABASE iot_lock;
USE iot_lock;
CREATE TABLE tbl_key (key_id VARCHAR(20) NOT NULL PRIMARY KEY, privilege INTEGER NOT NULL);
CREATE TABLE tbl_history (index_ INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY, key_id VARCHAR(20) NOT NULL, door_id VARCHAR(20) NOT NULL, date_time DATETIME(0) NOT NULL);
Mysql script for adding the key. In my case, I have two keys:
- A RFID tag with UID: FE65B0AB is set as a key of manager (privilege = 2)
- A RFID tag with UID: BD1E1D00 is set as a key of normal employee (privilege = 1)
SET @key_id='FE65B0AB', @privilege=2; /*This is a key of manager. change it according to UID of your card */
INSERT INTO tbl_key (key_id, privilege) VALUES (@key_id, @privilege);
SET @key_id='BD1E1D00', @privilege=1; /*This is a key of normal employee. change it according to UID of your card */
INSERT INTO tbl_key (key_id, privilege) VALUES (@key_id, @privilege);
Libraries
- Mysql library: Official Library of PHPoC
- PN532 library
To buy electronic components, you can order them from from DIYables
Comments