Skip to content

JG03dev/IoT-UrbanPulse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

IoT-UrbanPulse 🚦

An intelligent IoT-based urban traffic monitoring and congestion prediction system that leverages computer vision, edge computing, and real-time data analytics to provide comprehensive traffic insights for smart cities.

🎯 Overview

UrbanPulse is a complete IoT ecosystem designed to monitor urban traffic conditions in real-time. The system captures images from ESP32-CAM devices, processes them using machine learning models for vehicle detection and congestion analysis, and provides real-time traffic updates through a mobile application.

πŸ—οΈ System Architecture

The project consists of four main components working together:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚   IoT Devices   │───▢│  Edge Gateway   │───▢│  Cloud Backend  │───▢│  Mobile App     β”‚
β”‚   (ESP32-CAM)   β”‚    β”‚   (BLE Client)  β”‚    β”‚  (ML + API)     β”‚    β”‚   (React Native)β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“± Components

πŸ”§ Device (/Device)

  • Platform: ESP32-CAM with AI-Thinker module
  • Technology: Arduino C++, PlatformIO
  • Features:
    • High-quality image capture
    • Bluetooth Low Energy (BLE) communication
    • Authentication system for secure access
    • Power management and camera reset functionality

🌐 Edge Gateway (/Edge)

  • Technology: Python with asyncio and BLE
  • Features:
    • BLE communication with ESP32 devices
    • Image preprocessing and optimization
    • Local caching and batch processing
    • Multi-device management support

☁️ Cloud Infrastructure (/Cloud)

ML Service (cloud-run-service)

  • Technology: Flask, ONNX Runtime, OpenCV
  • Features:
    • YOLOv5 vehicle detection model
    • Real-time congestion analysis
    • Accident detection algorithms
    • Google Cloud Storage integration
    • PostgreSQL database connectivity

Backend API (UrbanPulse-backend)

  • Technology: Node.js, Express, PostgreSQL
  • Features:
    • RESTful API for traffic data
    • Real-time status updates
    • News and alerts management
    • Google Cloud SQL integration

πŸ“± Mobile Application (/UrbanPulse)

  • Technology: React Native, Expo
  • Features:
    • Real-time traffic status visualization
    • Interactive charts and statistics
    • Traffic news and alerts
    • Multi-city support
    • Responsive design with custom themes

πŸš€ Getting Started

Prerequisites

  • Node.js (v18+)
  • Python (3.8+)
  • PlatformIO CLI
  • Google Cloud SDK
  • Expo CLI
  • PostgreSQL

Device Setup

  1. Hardware Requirements:

    • ESP32-CAM AI-Thinker module
    • MicroSD card (optional)
    • Power supply (5V)
  2. Installation:

    cd Device
    pio run -t upload

Edge Gateway Setup

  1. Install dependencies:

    cd Edge
    pip install -r requirements.txt
  2. Configure environment:

    cp .env.example .env
    # Edit .env with your configuration
  3. Run the gateway:

    python main.py

Cloud Deployment

ML Service

  1. Setup:

    cd Cloud/cloud-run-service
    pip install -r requirements.txt
  2. Deploy to Google Cloud Run:

    gcloud run deploy urbanpulse-ml \
      --source . \
      --platform managed \
      --region europe-southwest1

Backend API

  1. Setup:

    cd Cloud/UrbanPulse-backend
    npm install
  2. Deploy:

    gcloud run deploy urbanpulse-api \
      --source . \
      --platform managed \
      --region europe-southwest1

Mobile App Setup

  1. Install dependencies:

    cd UrbanPulse
    npm install
  2. Start development server:

    npm start
  3. Run on device:

    npm run android  # For Android
    npm run ios      # For iOS

πŸ”¬ Machine Learning Model

The system uses a custom-trained YOLOv5 model for vehicle detection with the following capabilities:

  • Vehicle Detection: Cars, trucks, motorcycles
  • Congestion Analysis: Real-time traffic density calculation
  • Accident Detection: Unusual vehicle patterns and collisions
  • Traffic Flow: Movement analysis and predictions

Model Performance

  • Classes: Vehicle types (cars, trucks, motorcycles)
  • Input: 640x640 RGB images
  • Format: ONNX for cross-platform compatibility
  • Inference: Real-time processing on CPU/GPU

πŸ“Š API Endpoints

Traffic Status

  • GET /traffic/status - Current traffic conditions
  • GET /traffic/news - Traffic news and alerts
  • POST /upload - Image upload and processing

Health Monitoring

  • GET /health - Service health check

πŸ› οΈ Configuration

Environment Variables

# Cloud ML Service
BUCKET_NAME=your-gcs-bucket
MODEL_PATH=app/yolov5su.onnx
DB_HOST=your-cloud-sql-instance
DB_USER=your-db-user
DB_PASS=your-db-password
DB_NAME=urbanpulse

# Backend API
NODE_ENV=production
DB_HOST=your-cloud-sql-instance
DB_USER=your-db-user
DB_PASS=your-db-password
DB_NAME=urbanpulse

# Mobile App
REACT_APP_BACKEND_URL=https://your-api-domain.com

πŸ™οΈ Supported Cities

Currently deployed in:

  • Sant Cugat del VallΓ¨s (Catalonia, Spain)
  • Monitoring locations:
    • AP-7 (Km 230, Km 200)
    • Rotonda Pere I
    • C/ Costa i Llobera

πŸ“ˆ Features

Real-time Monitoring

  • βœ… Live traffic status updates
  • βœ… Vehicle counting and classification
  • βœ… Congestion level analysis (Fluid/Dense/Stopped)
  • βœ… Accident detection and alerts

Data Analytics

  • βœ… Historical traffic patterns
  • βœ… Peak hours analysis
  • βœ… Traffic flow predictions
  • βœ… Statistical reporting

User Experience

  • βœ… Intuitive mobile interface
  • βœ… Real-time notifications
  • βœ… Interactive charts and graphs
  • βœ… Multi-language support

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • University: Universitat AutΓ²noma de Barcelona (UAB)
  • Course: IoT Systems and Applications
  • YOLOv5: Ultralytics for the base detection model
  • Google Cloud: Infrastructure and ML services
  • Expo: React Native development platform

πŸ“§ Contact

Project Team: JG03dev Institution: Universitat AutΓ²noma de Barcelona (UAB)


UrbanPulse Logo

Made with ❀️ for Smart Cities

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors