Project tutorial
IOT2020 Access Control

IOT2020 Access Control © Apache-2.0

Integrate a Weigand-26 RFID reader with an IOT2020 for cloud-based door access control and monitoring using Node-Red.

  • 4,732 views
  • 0 comments
  • 8 respects

Components and supplies

Necessary tools and machines

Wire Strippers
Screw Driver

Apps and online services

About this project

As part of my orginal concept to create the Ultimate Co-Lo rack I thought I would start with the first critical component; The Access Controller!

  • Build Overview
  • IOT2020 Setup
  • Installing Node-Red
  • Arduino Setup
  • Webserver
  • Connecting the Relay shield

Build Overview

The concept itself is very simple; the user presents thier RFID card to the reader where the code is read and sent to a web server, if the code exists on the database and they are allowed access the response is sent back to unlock the door. This makes it very simple to control and monitor a location from a centeralised point.

From left to Right; RFID Reader, IOT2020 w/ Relay Shield, 12V Powersupply and finally the 12v Magnetic lock. Not pictured is the Arduino Nano.

I wanted to use Node-Red from the start as it looked like it would be easy to adopt ladder logic to. The IOT2020 communicates with the RFID reader using serial (RS232), however as I have could not find a reader that natively supports serial I used an Arduino Nano to convert the readers 26bit protocol to serial. The relay shield used offers 4 outputs which independately drives the magenetic lock, and LED's on the reader panel. I had considered using the arduino to drive the LED's as well but decided against it as not all reader have them integrated.

On the management side I am using a simple PHP script running on my laptop using the XAMPP software package. The script checks the request body containing the card number against a known good card number and depending on the match responds with a bit value.

Ultimately this simple test project has proven the IOT2020 to be an effective product for access control and monitoring, future developments will include using a SQLite server on the IOT2020 to store card numbers and access records for communication with a cloud based system, and adding additional functionality such as lighting control and alarm integration.

IOT2020 Setup

  • Register an account
  • Download the example image
  • Extract the *.wic image
  • Copy to SD card

Personally I use Rufus to burn image files, use whichever tool you are comfortable with. Once the SD card is setup and installed into the IOT2020 we can power it up and begin configuring.

With the example image there are two ways to connect to the IoT2020, SSH or Serial Terminal. For both I recommend using PuTTY

Serial Setup

To use the serial terminal we must first connect a UART cable to the IOT2020, via header X14. Take note of the serial port created by the adapter. (In my case it was COM9). The following settings can be used to connect to the IoT2020 with PuTTY:

SSH

Connecting to the IoT2020 via SSH requires only an ethernet connection. The default IPv4 for the example image is 192.168.200.1/24 . Make sure your computer is configured within this range (eg 192.168.200.2 / 255.255.255.0).

The default login for the IoT2020 is 'root',

(Bonus) Setup Wifi

Once logged in, type 'iot2000setup' to access the network setup, make sure to set the address of the wireless adapter to 'dhcp' (unless you statically provision).

Install Node-Red

Enter the following commands to install Node-Red and the modules required; Warning: This can take a long to install, and warning messages will show as NPM needs to build some packages from source.

npm install -g --unsafe-perm node-red
mkdir .node-red
cd .node-red
npm install node-red-dashboard
npm install node-red-contrib-modbus
npm install galileo-io

Setup the X11 Serial Port

In order to use the onboard serial pins with node-red we first need to set them up, warning: this will prevent you from being able to upload arduino sketches via the USB mini port.

Whilst logged in as root, type 'vi TTY0.setup.sh', this will drop you into the default text editor 'vi', pressing 'i' will enter vi into edit mode, at this point copy & paste the following code:

#!/bin/sh
echo -n "28" > /sys/class/gpio/export
echo -n "32" > /sys/class/gpio/export
echo -n "45" > /sys/class/gpio/export  
echo -n "out" > /sys/class/gpio/gpio28/direction 
echo -n "0" > /sys/class/gpio/gpio28/value  
echo -n "out" > /sys/class/gpio/gpio32/direction 
echo -n "1" > /sys/class/gpio/gpio32/value  
echo -n "out" > /sys/class/gpio/gpio45/direction 
echo -n "1" > /sys/class/gpio/gpio45/value

Hit 'Esc' and enter 'qw' to save the file. Once the file is saved it must be made executable, by entering the following:

chmod +x TTY0.setup.sh

Now run the file to setup the serial port for use

./TTY0.setup.sh

Arduino Setup (Optional)

If you are using a Serial based RFID reader, then this step can be skipped. The setup is quite simple, using an Arduino nano we convert the Weigand-26 protocol of the RFID reader to the serial logic Node-Red can understand. Pins 0&1 on the Arduino should be connected to Pins 1&2 of the IoT2020 for the serial logic and Pins 2&3 of the Arduino need to be connected to the Clock (CLK) and Data lines of the reader.

The sketch at the bottom of this project can be used to test the functionality.

Webserver

Although the end-goal is to a Cloud solution like the Amazon AWS, we have to test locally first. The instance of this build I used the XAMPP package to quickly install a local webserver to my computer so that I could run a simple PHP script to test functionality. Essentially all thats happening here is Node-Red requesting the page from the server whilst also passing the card number via POST headers, then taking the returned string 'answer' which is in my case can either be 1 (let user in) or 0 (reject the user). My example code is listed below:

Using the Node-Red debug tab you can find your Card number and replace the one in the IF statement to grant access.

Using the Arduino relay shield

Install the relay shield into the IOT2020, and make sure to set the power option header to 5v. The relay shield offer 4 mechanical relays that are connected to Pins 4,7,8 and 12 of the board respectifully. In this instance we are only using 3 of them. The serial data lines will also need to pass through the shield board.

Code

Arduino (Weigand - Serial) ConvertorArduino
Arduino sketch for converting Weigand 26bit to serial logic for use with the IOT2020. Based on work by Daniel Smith (www.pagemac.com)
/*
 * HID RFID Reader Wiegand Interface for Arduino Uno
 * Written by Daniel Smith, 2012.01.30
 * www.pagemac.com
 *
 */
 
 
#define MAX_BITS 100                // max number of bits
#define WEIGAND_WAIT_TIME  3000      // time to wait for another weigand pulse. 
 
unsigned char databits[MAX_BITS];    // stores all of the data bits
unsigned char bitCount;              // number of bits currently captured
unsigned char flagDone;              // goes low when data is currently being captured
unsigned int weigand_counter;        // countdown until we assume there are no more bits
 
unsigned long facilityCode=0;        // decoded facility code
unsigned long cardCode=0;            // decoded card code
 
void ISR_INT0()
{
  bitCount++;
  flagDone = 0;
  weigand_counter = WEIGAND_WAIT_TIME; 
 
}
 
void ISR_INT1()
{
  databits[bitCount] = 1;
  bitCount++;
  flagDone = 0;
  weigand_counter = WEIGAND_WAIT_TIME; 
}
 
void setup()
{
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  pinMode(2, INPUT);     // DATA0 (INT0)
  pinMode(3, INPUT);     // DATA1 (INT1)

  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  Serial.begin(9600);

  attachInterrupt(0, ISR_INT0, FALLING); 
  attachInterrupt(1, ISR_INT1, FALLING);
 
  weigand_counter = WEIGAND_WAIT_TIME;
}
 
void loop()
{
  if (!flagDone) {
    if (--weigand_counter == 0)
      flagDone = 1; 
  }

  if (bitCount > 0 && flagDone) {
    unsigned char i;
    
    if (bitCount >= 26)
    {
      for (i=2; i<14; i++)
      {
         facilityCode <<=1;
         facilityCode |= databits[i];
      }
 
      // card code = bits 15 to 34
      for (i=74; i<100; i++)
      {
         cardCode <<=1;
         cardCode |= databits[i];
      }
 
      printBits();
    }
   
     bitCount = 0;
     facilityCode = 0;
     cardCode = 0;
     for (i=0; i<MAX_BITS; i++)
     {
       databits[i] = 0;
     }
  }
}
 
void printBits()
{
      Serial.println(cardCode);
}

Schematics

Node Red Template
Basic blocks here are quite simple, our first input is a Serial block listening to our arduino via ttyS0, upon reading a card number it is formatted as a GET request and sent to our webserver. Depending on the response from the server (bit value) we trigger the lock & green LED on the reader panel or the trigger a pulse to the red LED
Node red pqvfrbczog
Arduino (Weigand - Serial) layout
Connect pins 1&2 (Serial Tx/Rx) to pin 1&2 of the relay shield [IOT2020]. Pins 2&3 connect to the reader clock and data pins respectfully.
Arduino weigand vobg2l7bxw
Relay Shield Connections
Relay shield gwov8qvqsm
PHP Sample Script
Php afrlsjco7k

Comments

Similar projects you might like

IOT2020 - RFID Real-Time Access Control

Project tutorial by SIT

  • 8,322 views
  • 2 comments
  • 28 respects

Iono access control

Project tutorial by Team sferalabs

  • 6,173 views
  • 3 comments
  • 14 respects

Ouija Board Access Control

Project tutorial by TheRiverPeople

  • 4,492 views
  • 1 comment
  • 21 respects

Security System And Access Control With Arduino And RFID

Project tutorial by Sarath P

  • 7,752 views
  • 1 comment
  • 19 respects

Grovey sLocks - Access Control Through A Smart Door Lock

Project tutorial by gerrikoio

  • 1,101 views
  • 1 comment
  • 7 respects

RFID Door Access Control with Counter

Project tutorial by sarful

  • 2,049 views
  • 0 comments
  • 6 respects
Add projectSign up / Login