A Python application to log entry and exit times based on card IDs using PostgreSQL and an PN532 NFC/RFID Reader.
- Hardware Integration: Supports PN532 RFID reader via I2C on Raspberry Pi.
- LED Indicator: Visual feedback for entry/exit events.
- Dockerized: Easy deployment with Docker and Docker Compose.
- FastAPI Service: REST API for remote management.
- CLI Tool: On-device interface for scanning.
- Raspberry Pi (3, 4, or Zero W)
- PN532 NFC/RFID Module
- LED (optional, for visual feedback)
- PN532 Module: I2C (SDA to Pin 3, SCL to Pin 5, VCC to 3.3V/5V, GND to GND)
- LED: Connected to GPIO 17 (Pin 11) with appropriate current-limiting resistor (220-330Ω recommended)
- LED anode (+) → GPIO 17 (through resistor)
- LED cathode (-) → GND
- Entry (Clock In): LED blinks 2 times
- Exit (Clock Out): LED blinks 3 times
- Clone the repository to your Raspberry Pi.
- Enable I2C on your Pi (
sudo raspi-config-> Interface Options -> I2C). - Build and run the container:
docker-compose up --build -d
The system includes a dedicated continuous listener service that automatically scans and logs cards 24/7:
Run as a service (auto-start with Docker):
docker-compose up -dBoth the API server and card listener will start automatically. The listener will continuously wait for cards.
View listener logs:
docker logs -f loop_shift_listenerStop the listener:
docker-compose stop card_listenerTo use the CLI with menu options inside the running container:
docker exec -it loop_shift_app python cli.pyOptions:
- Continuous Scan Mode: Automatically listens for cards (Ctrl+C to return to menu)
- Single Scan: One-time card scan
- Add Card: Register a new card
- View History: See access logs
Run the continuous listener directly:
docker exec -it loop_shift_app python card_listener.pyThe API is available at http://<raspberry-pi-ip>:8000.
- Docs:
/docs - Health Check:
/
- Database: Set via
DATABASE_URLindocker-compose.yml. - I2C Device: Mapped automatically as
/dev/i2c-1. - LED Pin: Default is GPIO 17, can be changed in
led_controller.py.
-
Deploy everything:
docker-compose up -d
-
Watch card scans in real-time:
docker logs -f loop_shift_listener
-
Register a new card (in a separate terminal):
docker exec -it loop_shift_app python cli.py # Select option 3: "Add New Card"
That's it! The system will now continuously listen for cards and automatically log entries/exits with LED feedback.
- API Service (
loop_shift_app): FastAPI server on port 8000 - Card Listener (
loop_shift_listener): Background service that continuously scans cards - Database: PostgreSQL (external)
- Hardware: PN532 RFID reader + LED indicator