A high-performance IoT security solution designed for campus environments. Using real-time Computer Vision (YOLOv8), this system monitors multiple security zones, enforces time-based restrictions, manages approved night extensions, and synchronizes data with cloud IoT platforms.
graph TD
A[Webcam 0] --> CM[Shared Camera Manager]
B[Webcam 1] --> CM
CM --> D1[Detector: Library]
CM --> D2[Detector: IOT Lab]
CM --> D3[Detector: Seminar Hall]
D1 & D2 & D3 --> YOLO{YOLOv8 Engine}
YOLO --> Logic{Permission Logic}
Logic -->|Allowed| Dash[Dashboard - PERMITTED]
Logic -->|Restricted| DB[(SQLite DB)]
Logic -->|Restricted| MQTT[MQTT Broker]
Logic -->|Restricted| TS[ThingSpeak Cloud]
DB --> Dash
Dash -->|Video Switching| CM
On Windows systems, hardware access to webcams is exclusive to a single thread/process. This project implements a Singleton Camera Manager that:
- Opens exactly one
cv2.VideoCaptureper physical index. - Uses a dedicated high-speed grabber thread to maintain a thread-safe frame buffer.
- Allows an unlimited number of concurrent YOLO detectors to "subscribe" to the same feed without any hardware conflicts or latency spikes.
Unlike traditional security systems that are either ON or OFF, this system supports Permission Overrides:
- Database-Driven: Checks the
extensionstable for approved student/staff IDs and timestamps. - Context Awareness: If a detection occurs at 1 AM in a restricted lab, but a "Project Deadline" extension exists, the system automatically marks it as a permitted visit instead of an intrusion.
- ThingSpeak Integration: Automatically synchronizes detection events (Zone ID, Confidence, Hour of detection) to your cloud dashboard for long-term analytics.
- MQTT Telemetry: Publishes standardized JSON payloads to
campus/zone/<id>/detectionfor integration with smart sirens or mobile notification apps.
The system features a modern, glassmorphism-inspired dashboard that provides:
- Live Stream Switching: Click any zone card to instantly swap the main monitor feed.
- Real-time Badges: Visual indicators for "Extension Active" (including reason strings), "Intrusion Detected", and "Area Clear".
- Dynamic Logging: Automatic updates for the violation history table using AJAX polling.
Returns the current status of all monitored zones, including active extensions and recent detection summaries.
Returns the last 20 detection events (Violations vs Permitted Entries).
Allows remote updates to the allowed start/end times and webcam index for a specific zone.
| Column | Type | Description |
|---|---|---|
zone_id |
TEXT (PK) | Unique identifier (e.g., zone_lib) |
zone_name |
TEXT | Human-readable name |
zone_type |
TEXT | time_restricted or forbidden_permanent |
allowed_start |
TEXT | Base permitted hour (e.g., 09:00) |
allowed_end |
TEXT | Base closing hour (e.g., 21:00) |
webcam_index |
INT | Hardware camera ID (0 or 1) |
| Column | Type | Description |
|---|---|---|
zone_id |
TEXT | Linked zone |
ext_date |
TEXT | Specific date for the extension |
ext_start |
TEXT | Start of extension window |
ext_end |
TEXT | End of extension window |
reason |
TEXT | Purpose (e.g., "AI Training") |
-
Clone & Install:
git clone https://github.com/satvikdua06-dev/IoT-Project.git pip install -r requirements.txt
-
Environment Variables (
.env):THINGSPEAK_WRITE_API_KEY=your_key MQTT_BROKER=broker.hivemq.com DETECTION_COOLDOWN_SECONDS=10
-
Launch:
python app.py
- Missing Models: The YOLOv8n权重 file (
yolov8n.pt) will automatically download on first run (approx 6MB). - Hardware Issues: If a webcam is disconnected, the Shared Camera Manager will gracefully log an error and display a "Camera Offline" placeholder on the dashboard.
- Port Conflicts: By default, the server runs on port
5050. If this is occupied, updateFLASK_PORTin your.env.
Made by Satvik Dua. Distributed under the MIT License.