Skip to content
habiwanPublic

About

custom made Punchcard-System with NFC cards

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

148 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PiClock

Custom-made replacement for traditional punchcard systems using NFC cards, barcodes, and a Raspberry Pi.

PiClock Hardware Prototype

Overview & Evolution

PiClock started as a lightweight hardware clock-in terminal built from a Raspberry Pi 2, a PN532 NFC HAT, a 3.5" TFT display, and a buzzer—housed right inside the cardboard box the NTAG215 NFC cards shipped in.

  • v1 (Prototyping): Logged NFC swipes to local CSV files (times.csv), synced them over the network to a NAS/Ubuntu VM, and analyzed them via Excel formulas/Pivot Tables or a standalone PHP page.
  • v2 (Current Architecture): Fully modernized to run all-in-one on a Raspberry Pi using an ARM64 Docker LAMP stack (managed via Portainer with MySQL and Adminer), eliminating clunky CSV syncing. It also includes mobile Web NFC / Barcode scanning (scanner.html) and motionEye security camera integration.

Repository Structure

  • nfc/: Python scripts for reading NFC tags via I2C, triggering the confirmation buzzer, and recording swipes + CPU temperature.
  • piservices/: Docker Compose LAMP stack (www, MySQL, Adminer), systemd unit files (clockpy.service, avahi-alias.service), and motionEye automation scripts (log_motion.sh, motion_sync.sh). (See piservices/README.md for full service setup.)
  • www/: PHP/HTML web dashboard for staff management, barcode generation (JsBarcode), attendance reporting, and mobile NFC scanning (scanner.html).
  • TODO.md: Security hardening roadmap (e.g., fail2ban implementation, HTTPS enforcement).

Hardware Materials Required

  • Raspberry Pi 2 (32-bit) (Note: Tested originally on Pi 2; newer 64-bit boards ran too fast for legacy timing loops without adjustment, though the backend Docker stack now supports ARM64).
  • Raspberry Pi PSU
  • USB Wi-Fi Dongle (Required if using a Pi 2 without built-in wireless)
  • NFC HAT (e.g., Waveshare PN532 NFC HAT configured for I2C)
  • LCD Screen HAT (e.g., ELEGOO 3.5" 480x320 TFT Display HAT)
  • Mini Speaker / Active Buzzer (for audio swipe confirmation)
  • 100x NFC Cards (NTAG215 — Tip: Cut a window in the front of the shipping box for the LCD screen and a slot on the side to swipe cards!)

Hardware & OS Setup (Raspberry Pi)

Broad steps taken to configure the physical Pi terminal (adjust as needed for your Pi OS release):

  1. Install Raspberry Pi OS Legacy (32-bit Bullseye).
  2. Run sudo raspi-config to enable SSH, SPI, I2C, and GPIO.
  3. (Optional) Add your SSH public key to ~/.ssh/authorized_keys for passwordless access.
  4. Update the system:
    sudo apt update && sudo apt upgrade -y
  5. Install required system packages and build tools:
    sudo apt install python3-serial* libusb-dev libpcsclite-dev libtool automake autoconf gpiod python3-pip samba ntp inotify-tools python3-setuptools -y
  6. Install Python dependencies:
    sudo pip3 install git+https://github.com/nicmcd/vcgencmd.git
    sudo pip3 install -e .
  7. Download Waveshare PN532 drivers/examples and clone libnfc & mfoc:
    wget https://files.waveshare.com/upload/8/85/Pn532test.zip
    wget https://files.waveshare.com/upload/6/66/Pn532-nfc-hat-code.7z
    git clone https://github.com/nfc-tools/libnfc.git
    git clone https://github.com/nfc-tools/mfoc.git
  8. Compile and install libnfc:
    autoreconf -vis
    ./configure --prefix=/usr --sysconfdir=/etc
    make
    sudo make install
  9. Verify GPIO and NFC hardware detection:
    gpioinfo
    nfc-list
  10. Configure the Python scripts in nfc/ to communicate over I2C (UART and SPI proved unreliable during testing).

Minimalist Kiosk Desktop Tweaks

To keep the Pi lean and turn the 3.5" TFT into a clean digital clock display:

  • Set the desktop background color to solid black.
  • Keep only the top panel (black background, white text) and remove all applets except the Digital Clock.
  • Maximize the top panel height and font size to fill the 480x320 screen.

Backend, Web App & Extensions

1. Docker LAMP Stack (piservices/)

Instead of relying on an external server and CSV transfers, deploy the included docker-compose.yml via Portainer on your Pi:

  • Runs the PHP web interface (www/), MySQL (lamp-db), and Adminer (ARM64-friendly replacement for phpMyAdmin).
  • Optionally enable avahi-alias.service so staff and admins can reach the dashboard at http://piclock.local or http://piclock.
  • Check piservices/README.md for full deployment details.

2. Mobile Web NFC & Barcode Support (www/)

  • Staff Barcodes: The staff management interface generates scannable barcodes alongside NFC card UIDs.
  • Mobile Scanner (scanner.html): Allows an Android phone running Chrome to act as a portable NFC punch terminal, writing timestamps directly to MySQL. (Note: Chrome's Web NFC API requires HTTPS—e.g., via a reverse proxy with DuckDNS + Let's Encrypt certificates).

3. MotionEye Security Integration (piservices/)

PiClock can also log physical room activity alongside a motionEye webcam setup:

  • log_motion.sh (see piservices/log_motion.md): Logs motion-end events and Pi CPU thermal readings directly into the PiClock MySQL database (with a 60-second debounce).
  • motion_sync.sh (see piservices/motion_sync.md): Remuxes .mkv captures to .mp4, enforces a 9 GB local cap, and syncs footage to Box cloud storage every minute for off-site tamper protection.

Legacy Excel Prototype Formulas (Archived Reference)

Before migrating to MySQL and PHP, raw times.csv exports were parsed in Excel using the following formulas:

  • Extract Clean Card ID:
    =SUBSTITUTE(CONCAT(MID(B2,6,1),MID(C2,5,2),MID(D2,5,2),MID(E2,5,2),MID(F2,5,2),MID(G2,5,1),MID(H2,5,2)),"'","")
    
  • Extract Day/Month:
    =CONCAT(MID(J2,11,2),"/",MID(J2,8,2))
    
  • Extract Time (HH:MM):
    =MID(J2,14,5)
    
  • Staff Name Lookup:
    =XLOOKUP([@CARD],Info!$A$2:$A$101,Info!$B$2:$B$101,"UNREGISTERED")
    

Roadmap & Security

See TODO.md for upcoming security hardening tasks, including implementing fail2ban and tightening endpoint access controls.


Credits & License

Prototyped, Projected, and Created by F. Javier "habiwan" Puig Diaz (github.com/habiwan).

  • All custom software is licensed under the GNU General Public License (GPL) and is provided without warranty.
  • Third-Party Exception: JsBarcode v3.11.5 | (c) Johan Lindell | MIT License.

About

custom made Punchcard-System with NFC cards

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages