CuriousJames / DIYAC

Raspberry Pi Python code & PCB design project to control door access (access control) via a wiegand card and/or keypad reader, handles a doorbell too
6 stars 2 forks source link
access-control access-management card door door-controller door-lock door-sensor doorbell facility-security nfc nfc-card-reader physical-security python raspberry-pi reader rfid wiegand

DIYAC - Do-It-Yourself Access Control

Warning

This is a work in progress as a personal hobby, however it has been running without any problems for the project owners use 24/7 for over a year.

That said of course, use at your own risk.

Purpose

This python code allows a Raspberry Pi to be used to allow access to a door using a Wiegand keypad/ RFID reader, and a door strike It also rings a doorbell in a (possibly) nice fashion Also included in 'Extras' is the Fritzing pcb/breadboard design

Pre-requisits

Installing the service

The hard way (hopefully there will be a script to do this and more soon!)

  1. If '/home/pi/diyac' IS your diyac folder location:
    cp /home/pi/DIYAC/diyac.service_example /home/pi/DIYAC/diyac.service && sudo systemctl link /home/pi/DIYAC/diyac.service && sudo systemctl enable diyac.service
  2. If '/home/pi/diyac' is NOT your diyac folder location:
    1. change the 'ExecStart' line in 'diyac.service' to 'ExecStart=/usr/bin/python3 /your/diyac/folder/location/main.py'
    2. sudo systemctl link /your/diyac/folder/location/diyac.service
  3. sudo systemctl enable diyac.service
  4. sudo reboot
  5. Done - The service will now run on startup of the Pi

Settings

Settings are stored in settings.json which must be made by the user - you may copy settings.json_example to get you started if you wish.

This is the structure of the settings.json file:

AllowedTokens

Allowed (or authorised) tokens are stored in allowedTokens.json which must be made by the user - you may copy allowedTokens.json_example to get you started if you wish.

This file is how you store what tokens (be they cards or codes) are allowed to enter the door

Each entry in this list must contain 3 items:

The token handler takes hex tokens and changes them to lowercase and removes colons. This means hex tokens can be upper or lower case, and can include colons or not.

Logging

Log levels are as follows:

All levels are equivalent to linux syslog levels.

Redacting

It is possible to redact values of a specified key, by key name, in the logged 'data' (it does NOT redact the message)

So if you want to redact all values of the key 'token' you can add 'token' to the global or destination (display or file) context in settings and then no token values will display -REDACTED- and nothing else, see settings.json_example for it's implementation

code notes

systemHandler

Because systemHandler is designed to be used by various things, it's a bit flexible. Importantly, the quit function and signal handlers can be set up with a callback, so that project specific instructions can be defined in the main body of code without having to change anything within systemHandler (hopefully)

Resources

Systemd integration - https://www.freedesktop.org/software/systemd/man/systemd.service.html