Inhaltsverzeichnis
Attendance
This project is now obsolete. Please see shackles
The whole project code is stored under https://github.com/makefu/attendance
Project Summary
This is the documentation for the attendance infrastructure formerly deployed in the shackspace. The project consists of different parts which will be described in detail on this page.
It creates the possibility for the shack members to „log into“ the shackspace and provide a way for other members to see who is currently in the shackspace. The Project is an 'opt-in', nobody has to use the infrastructure.
The project can be separated in the following parts:
- NFC Gateway
- User Suppository Server
- IRC Bot
NFC Gateway
Overview
The NFC Gateway creates the possibility for shack members to physically log into shackspace. It provides an usb nfc reader and a 2x20 character dotmatrix display. It is also part of and implemented in the Minikrebs Project as NFC Gateway
Hardware
The NFC Gateway consists of the following parts:
- TP-Link MR3020 amazon de,amazon com
- SCM SCL3711 NFC Reader amazon de
- For a stable performance, use a powered USB Hub with >2A Power Adapter
MR3020
I am using the MR3020 as a platform because it provides Wifi AND a directly usable TTL Port where the pins are already attached on the PCB.
SMC SLC3711
This is an nfc reader which „just works“ with libnfc-bin. The reader reads quite a lot of 13mhz cards.
VFD LCD
The LCD is connected directly to the MR3020 Ports. The VFD RX is connected to MR3020 TX. 5V is connected to the MR3020 USB Power and GND is connected to the MR3020 Switch GND:
Software
The NFC Gateway is running on OpenWRT with the NFC Gateway Profile of Minikrebs. The profile provides the following capabilities:
- usb + stty to write to the nfc display
- configured to connect to shack wifi
- tinc configured for the retiolum darknet
- nfc Polling software
- fortune-mod
VFD Display
We write raw display strings to the Serial Port and we use it for all the fancy stuff
The NFC Gateway Software
The software is using a very simple (→ easy to maintain) polling mechanism which uses nfc-list to look if someone has put an nfc card in front of the nfc reader. The script is running as daemon via /etc/rc.local .
The basic idea:
- Poll for NFC Card, retrieve NFC-UID
- get username and login status for NFC-UID from server-backend via HTTP (wget)
- User does not exist: error message
- User exists then log the user out or in according to their current status.
- Send welcome/bye message to the LCD VFD
Fortune-mod
When the nfc gateway is not used for logging in it shows funny fortune cookies in an interval. The script is running as a daemon started by /etc/rc.local.
See github nfc_login code for the daemon code.
Installation
git clone git@github.com:krebscode/minikrebs.git cd minikrebs ./prepare nfc_gateway ./upgrade <ip-addr-of-mr3020>
For a detailed description, see github minikrebs
Caveats/Lessons Learned
- The LCD is using a LOT of power, when connected directly to the MR3020
- pcscd is quite unstable and slow under Openwrt, it is better to just use libnfc directly.
- It looks quite fancy when booting the mr3020 because the VFD has a baud rate of 9600 but when booting the baud rate of the MR3020 is configured to 115200.
User Suppository Server
Introduction
The user suppository server is the backend of the NFC Gateway. For Storage it uses the Shack provided redis storage G.L.A.D.O.S. The user suppository is essentially a python http server which talks to the redis db to store online and offline status of the users.
API
The implemenation is an HTTP Server which provides a number of API calls:
// all returns are json ident=[0-9A-Z]+ //the unique user id - currently from RFID chips /user/online - returns all online users /user/list - returns all users /user/<ident>/online - returns if user with 'ident' is online /user/<ident>/name - returns name of user with ident /user/<ident>/login - logs user with 'ident' in /user/<ident>/logout -logs out user /user/<ident> - returns cool info about user with 'ident' /user/create/<ident>/<name> - creates a new user with 'ident' with 'name'
See the current API in github.
Redis Store
The user suppository server stores the state of the shack users.
## Scheme - always correct scheme in 'users.config' { "users": { "<uid>": { "history": " the login-logout history", "name": "the nick name", "online": "user online -expires after 1 day" }, "all": "contains all available user hashes", "config" : "this text" } }
Installation
git clone https://github.com/shackspace/user_suppository # Install python3, python-flask, python-redis cd server # edit init.py for hostnames,etc python3 ./init.py
To autostart use autostart/user_suppository.conf for supervisor. add the user usersupp to your environment
IRC Bot
Introduction
The IRC bot is currently the only way to know if a user is logged in or not. The irc bot is connected to irc.freenode.com to channel #shackspace. Also the irc bot will write to the IRC channel if a user has logged into the shack by sending a channel query.
The IRC bot implementation used is pyfibot, two modules are written to implement the
Usage
# write in #shackspace channel .online
IRC Gateway
After opening a socket on port 1234 it takes arbitrary messages and sends them to the IRC. The module opens a tcp listen socket via twisted and listens for messages. each message will be written to the irc.
IRC Online
The irc bot is using python-requests to query the user_suppository server online users (see user_suppository API).
Installation
see pyfibot installation.
the clone url is: https://github.com/krebscode/pyfibot
no additional software is required.
To autostart use autostart/onbot.conf for supervisor. add the user usersupp to your environment