﻿# NICU RFID Scanner (KSWEB + ESP32)

This project provides a complete web app for scanning RFID tags used for premature baby records.

## Features
- Registration page for new baby/tag records
- Scan page that receives UID from ESP32 WebSocket and fetches DB info
- Sign-out action with timestamp
- History page with filters and full audit trail
- Professional responsive UI (no external CSS dependency)

## Folder Structure
- `index.php` dashboard
- `register.php` registration form
- `scan.php` live scanner screen
- `history.php` history table with filters
- `config.php` database connection + helpers
- `api/register.php` create baby record
- `api/scan.php` fetch baby by tag + log scan
- `api/ingest_scan.php` ESP fallback scan ingest endpoint
- `api/signout.php` sign out admitted baby
- `api/history.php` filtered history API
- `assets/style.css` app styles
- `assets/app.js` shared frontend helpers
- `db/schema.sql` database schema
- `esp32/esp32_rfid_fallback.ino` ESP32 sketch with HTTP fallback

## KSWEB Setup
1. Create database from `db/schema.sql` in phpMyAdmin.
2. Edit `config.php` with your MySQL username/password.
3. Open `http://127.0.0.1/nicu-scaner/` in browser (or your local KSWEB site path).

## ESP32 Integration
Your ESP32 should broadcast scanned UID over WebSocket port `81`.
Default in scan page is `ws://192.168.4.1:81/` and can be changed on page.

When no WebSocket client is connected, ESP32 can send HTTP POST fallback to:
`api/ingest_scan.php`
so scans still get logged in history.

## Notes
- This starter does not include login/auth yet.
- For real medical use, enable authentication and HTTPS.
