pslockout/doorcontrol
2018-12-04 01:15:03 -07:00
..
.gitignore Add script to push card data to auth server 2018-12-04 01:05:17 -07:00
pushcards.py Add script to push card data to auth server 2018-12-04 01:05:17 -07:00
README.md Fix supervisor issue and README spelling 2018-12-04 01:15:03 -07:00
requirements.txt Add script to push card data to auth server 2018-12-04 01:05:17 -07:00
settings.json.example Add script to push card data to auth server 2018-12-04 01:05:17 -07:00

Protospace lockout card updater

Runs on the door controller and updates the auth server with member cards.

Setup

Cloning

Clone to user pi's home directory. If you'd like to place it elsewhere, adjust the supervisor config below.

$ cd
$ git clone https://gogs.tannercollin.com/tanner/pslockout

Python

$ sudo apt install python3 python3-pip python3-virtualenv   # for Debian
$ cd ~pi/pslockout/doorcontrol
$ virtualenv -p python3 env
$ . env/bin/activate
(env) $ pip install -r requirements.txt
(env) $ deactivate

Supervisor

Supervisor is used to keep the script always running.

$ sudo apt install supervisor

Create a file named /etc/supervisor/conf.d/pushcards.conf and add:

[program:pushcards]
user=pi
directory=/home/pi/pslockout/doorcontrol
command=/bin/bash -c 'source env/bin/activate && python pushcards.py'
autostart=true
autorestart=true
stderr_logfile=/var/log/pushcards.log
stderr_logfile_maxbytes=1MB
stdout_logfile=/var/log/pushcards.log
stdout_logfile_maxbytes=1MB

settings.json

Copy the example and insert a lockout admin's auth token:

$ cd ~pi/pslockout/doorcontrol
$ cp settings.json.example settings.json
$ vim settings.json

You can find your auth token by requesting it with curl:

$ curl -d username=tanner.collin -d password=supersecret http://tools-auth.protospace.ca/login/

{
        "token": "9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
}

Launch

Reload supervisor to start pushcards:

$ sudo supervisorctl reread
$ sudo supervisorctl update

Theory of Operation

Every ten seconds the script checks to see if the card database has changed.

If it was modified, it reads the card numbers into a Python object.

It then sends the object (modified or not) to the auth server which updates the cards for any users found in the system.