A comprehensive classroom monitoring system that uses computer vision to detect when fans are left running in empty classrooms and sends real-time notifications to administrators and staff.
This system consists of three main components:
- Sensor Service (Python): Computer vision service using YOLOv8 for person detection
- Server (Node.js): RESTful API backend with MongoDB database
- Client (React Native): Mobile application for receiving and managing notifications
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Sensor Service โ HTTP โ Server โ HTTP โ Mobile Client โ
โ (Python) โโโโโโโโโโถโ (Node.js) โโโโโโโโโโโ (React Native) โ
โ - YOLOv8 โ โ - Express โ โ - Expo โ
โ - OpenCV โ โ - MongoDB โ โ - Axios โ
โ - Camera โ โ - JWT Auth โ โ - AsyncStorage โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ โ
โ Detects people โ Stores data โ Displays
โ Sends snapshots โ Manages users โ notifications
โ โ โ
- Real-time person detection using YOLOv8
- Configurable alert delays
- Automatic snapshot capture
- Visual monitoring dashboard
- Alert logging
- User authentication with JWT
- Role-based access control (Admin/Staff)
- Notification management API
- MongoDB database integration
- CORS-enabled for cross-origin requests
- Separate user and admin dashboards
- Real-time notification display
- Snapshot image viewing
- Mark as read/unread functionality
- Delete notifications (admin only)
- Auto-refresh every 10 seconds
- Pull-to-refresh support
- Python 3.8+ (for sensor service)
- Node.js 16+ (for server)
- MongoDB 4.4+ (for database)
- Expo CLI (for mobile client)
- Webcam (for sensor service)
-
Clone the repository:
git clone https://github.com/ikeshav26/auto_detection_.git cd auto_detection_ -
Setup Server:
cd server npm install # Create .env file echo PORT=4000 > .env echo MONGODB_URI=mongodb://localhost:27017/auto_detection >> .env echo JWT_SECRET=your-secret-key >> .env npm run dev
-
Setup Sensor Service:
cd ../sensor_service pip install -r requirements.txt # Edit config.py if needed python main.py
-
Setup Client:
cd ../client npm install # Edit constants/config.js to set server URL npm start
auto_detection_/
โโโ client/ # React Native mobile app
โ โโโ app/ # App screens (admin, auth, user)
โ โโโ components/ # Reusable components
โ โโโ constants/ # Configuration files
โ โโโ context/ # React context
โ โโโ README.md
โโโ server/ # Node.js backend
โ โโโ src/
โ โ โโโ config/ # Database configuration
โ โ โโโ models/ # MongoDB models
โ โ โโโ controller/ # Business logic
โ โ โโโ routes/ # API routes
โ โ โโโ middlewares/ # Auth middleware
โ โโโ index.js # Server entry point
โ โโโ README.md
โโโ sensor_service/ # Python vision service
โ โโโ main.py # Main detection script
โ โโโ config.py # Configuration
โ โโโ telegram_alert.py # Notification sender
โ โโโ logs/ # Alert logs
โ โโโ snapshots/ # Captured images
โ โโโ README.md
โโโ README.md # This file
PORT=4000
MONGODB_URI=mongodb://localhost:27017/auto_detection
JWT_SECRET=your-super-secret-key
NODE_ENV=developmentSERVER_URL = "http://localhost:4000/api/notifications/create"
ALERT_DELAY = 600 # 10 minutes
FAN_STATUS = True
SNAPSHOT_DIR = "snapshots"
LOG_FILE = "logs/logfile.log"export const API_URI = "http://localhost:4000/api"POST /api/user/signup- Register new userPOST /api/user/login- User loginPOST /api/admin/register- Register user (admin only)
POST /api/notifications/create- Create notificationGET /api/notifications- Get all notificationsGET /api/notifications/unread- Get unread notificationsPATCH /api/notifications/:id/read- Mark as readPATCH /api/notifications/read-all- Mark all as readDELETE /api/notifications/:id- Delete notificationDELETE /api/notifications- Delete all notifications
- Detection: Sensor service monitors classroom via webcam
- Analysis: YOLOv8 detects number of people in frame
- Alert Trigger: If room empty + fan ON for configured time
- Notification: Snapshot sent to server with metadata
- Storage: Server stores in MongoDB
- Display: Client polls server and displays notifications
- Action: User marks as read or admin deletes
# Terminal 1 - Start MongoDB
mongod
# Terminal 2 - Start Server
cd server
npm run dev
# Terminal 3 - Start Sensor Service
cd sensor_service
python main.py
# Terminal 4 - Start Client
cd client
npm startTest Server:
curl http://localhost:4000/
# Expected: Hello, World!Test Sensor Service:
- Ensure camera is connected
- Press 'q' to quit
- Check
logs/logfile.logfor events
Test Client:
- Scan QR code with Expo Go app
- Login with test credentials
- Navigate to notifications screen
MongoDB Connection Failed:
# Start MongoDB service
# Windows: mongod
# macOS: brew services start mongodb-community
# Linux: sudo systemctl start mongodCamera Not Detected:
- Check camera permissions
- Try different camera index in main.py
- Ensure no other app is using camera
Client Can't Connect to Server:
- Check server is running on port 4000
- Update API_URI in client config
- For physical devices, use computer's IP instead of localhost
- Check firewall settings
Notifications Not Appearing:
- Verify server is running
- Check MongoDB is connected
- Ensure sensor service is sending to correct URL
- Check network connectivity
# Server logs
cd server
tail -f logs/server.log # if logging configured
# Sensor service logs
cd sensor_service
cat logs/logfile.logcd sensor_service/snapshots
ls -lt # View latest snapshots- Set environment variables
- Connect to MongoDB Atlas
- Deploy from Git repository
Build for production:
cd client
# Android
expo build:android
# iOS
expo build:ios
# Or use EAS Build
eas build --platform allRun as system service on local machine or edge device.
- JWT authentication for API access
- Password hashing with bcrypt
- Role-based access control
- CORS configuration for production
- Environment variables for secrets
This project is licensed under the MIT License.
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Keshav - @ikeshav26
For support, email or open an issue in the repository.
- WebSocket for real-time notifications
- Push notifications on mobile
- Cloud storage for snapshots (AWS S3)
- IoT integration for actual fan control
- Analytics dashboard
- Email notifications
- Multiple camera support
- Dark mode in client app
- Notification search and filters
- Export reports
- YOLOv8 by Ultralytics
- Expo for React Native framework
- OpenCV community
- MongoDB and Express.js teams