Skip to content

Nazeem0/mini_project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

mini_project

🚦 Railway Safety Management System

A full-stack Railway Level Crossing Safety System that integrates ESP32 hardware sensors, a Flask backend, MongoDB, and a modern web dashboard to monitor trains, control gates, and log safety events in real time.


📌 Project Overview

This system automates railway gate operations using ultrasonic sensors and an ESP32, while providing a secure web dashboard for railway and government officers.

🔹 Key Objectives

  • Prevent accidents at railway level crossings
  • Automate gate control based on train movement
  • Detect obstacles during gate operation
  • Maintain complete activity and sensor history
  • Allow authorized manual gate override in emergencies

🧠 System Architecture

ESP32 + Sensors ↓ Flask REST API ↓ MongoDB Database ↓ Web Dashboard (HTML, CSS, JS)


⚙️ Features

🔐 Authentication & Roles

  • Secure login/signup using JWT
  • Password hashing with Werkzeug
  • Roles:
    • Government Officer
    • Railway Officer
  • Auto-generated Badge ID

🚂 Automated Gate Control (ESP32)

  • Detects:
    • Train arrival
    • Obstacles on track
    • Train departure
  • Gate behavior:
    • Slow close for safety
    • Half-close if obstacle detected
    • Resume closing after obstacle clears
    • Slow open after train departure

📊 Live Dashboard

  • Real-time sensor monitoring
  • Gate override controls (manual)
  • User profile & role display
  • System health indicators

🧾 Activity History

  • Sensor logs from ESP32
  • Manual gate override logs
  • Timestamped and stored permanently in MongoDB

🧩 Tech Stack

🖥 Backend

  • Python
  • Flask
  • Flask-CORS
  • PyJWT
  • MongoDB (PyMongo)

🌐 Frontend

  • HTML5
  • CSS3 (Glassmorphism UI)
  • JavaScript (Vanilla JS)
  • Responsive Design

🤖 Hardware

  • ESP32
  • Ultrasonic Sensors (HC-SR04)
  • Servo Motor
  • ESP32Servo Library

🗄 Database Structure (MongoDB)

Database: railway_system

Collections:

  • users – user accounts & roles
  • sensors – latest live sensor values
  • history – permanent event logs

🔌 API Endpoints

Authentication

Method Endpoint Description
POST /signup Create new user
POST /login Login & get JWT

System

| GET | /status | Server & MongoDB status |

Sensors

| POST | /sensor/update | ESP32 sensor data | | GET | /sensor/live | Live sensor data (JWT protected) |

Gate

| POST | /gate/log | Manual gate action logging |

History

| GET | /history | Last 50 system logs (JWT protected) |


🛠 Setup Instructions

1️⃣ Backend Setup

pip install flask flask-cors pymongo pyjwt werkzeug
python app.py
Ensure MongoDB is running locally:

mongod
2️⃣ Frontend Setup
Open index.html in browser

Ensure backend runs at:

http://127.0.0.1:5000
3️⃣ ESP32 Setup
Install ESP32Servo library

Connect:

Servo → Pin 13

Ultrasonic Sensors → Pins as defined in code

Upload the ESP32 .ino code

Open Serial Monitor (115200 baud)

🧪 Testing Flow
Signup & Login from dashboard

ESP32 sends sensor data

Gate auto-closes on train arrival

Obstacle triggers half-close

Gate opens after train departure

All actions logged in History tab

🔐 Security Highlights
JWT-based API protection

Password hashing

Role-based UI access

Session auto-logout on tab close

🚀 Future Enhancements
Cloud deployment (AWS / Railway / Render)

WebSockets for real-time updates

SMS/Email alerts

AI-based train detection (camera)

Multi-crossing support

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors