If you're interested to know how this stared, have a look here. This project was supposed to be a generic solution for giving EB members controlled access to lab resources. So far it's working for the laser cutter only, but has some potential to be extended!
We tried hard to used a micro-controller for this. This one worked with an Arduino Nano without the Ethernet Shield. Once we connect the Ethernet shield it won't work via SPI. And via i2c it becomes very unstable. So we tried with a Raspberry Pi models 1 and 2. Didn't work either. Tried SPI, i2c and UART. Also, after many issues dealing with RFID reader MFRC522, we decided to move to PN532. So finally we got the PN532 working with a Raspberry Pi 3 via i2c. So far it's been consistent.
The source code is available on github: https://github.com/tiagovaz/eblab/
Here is the current hardware parts for this project:
The current solution includes a few Python scripts on a local Raspberry Pi and a simple Django application server side.
Hardware
WIP:
Software
sudo apt install python3-setuptools && cd py532lib; sudo python3 setup.py install
requirements_rpi.txt
: sudo pip3 install -r requirements_rpi.txt
eblaser_gui.py
once the XOrg server is loaded.eblaser_daemon.py
: currently placed on /home/pi/py532lib/
, this script uses the pn532 library to make the RFID reading calls. Information about the resource usage is stored as a json structure in /tmp/eblaser_data.json
. This file will be constantly read by another script, which will update the screen attached to the RPi.eblaser_gui.py
: First I tried hard to have a single daemon for the whole process. However, updating the screen and reading the RFID card refused to work under a same clock. Threads didn't work neither. That's why this script exists: it constantly reads information from the json file generated by eblaser_daemon.py
and updates the RPi screen accordingly.eblaser_daemon.service
: service unit configuration file for calling eblaser_daemon.py
. Should be placed on /usr/local/lib/systemd/system
.
The django app provided along with the local scripts should be deployed as a regular django app, nothing special The dependencies are listed in the requirements_server.txt
and can be installed via pip3. This should be deployed under HTTPS using any webserver. The URL should be set on the local scripts accordingly.
For authenticating the RPi requests, you need to create a user token and add it to script eblaser_gui.py
. On the server side, do the following:
python3 manage.py drf_create_token eb
On the client side, add the generated token to self.headers
CardReader attribute:
self.headers = {'Authorization': 'Token MYSECRETTOKENGENERATEDONTHESERVER'}
API
For json responses, add format=json
to the URL.
Resource usage examples:
Possible actions:
Getting users information, mostly used for the RPi screen messages:
Getting total resource usage from a given user from their rfid: