{"id":23702992,"url":"https://github.com/yassinekader/drawniness_iot_project","last_synced_at":"2026-02-10T06:32:16.584Z","repository":{"id":270044576,"uuid":"908598507","full_name":"YassineKADER/Drawniness_Iot_Project","owner":"YassineKADER","description":"Real-time IoT-based driver drowsiness detection system using YOLOv8, Arduino, FastAPI, and Grafana for alerts, data logging, and analysis.","archived":false,"fork":false,"pushed_at":"2025-02-11T19:25:52.000Z","size":57433,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-22T23:11:29.221Z","etag":null,"topics":["arduino","drowsiness-detection","fastapi","grafana-dashboard","influxdb","iot-application","yolov8"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YassineKADER.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-26T13:18:20.000Z","updated_at":"2025-02-11T19:25:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"e7483560-13a5-4a42-a4e8-fdf8b4d57d23","html_url":"https://github.com/YassineKADER/Drawniness_Iot_Project","commit_stats":null,"previous_names":["yassinekader/drawniness_iot_project"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/YassineKADER/Drawniness_Iot_Project","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YassineKADER%2FDrawniness_Iot_Project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YassineKADER%2FDrawniness_Iot_Project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YassineKADER%2FDrawniness_Iot_Project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YassineKADER%2FDrawniness_Iot_Project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YassineKADER","download_url":"https://codeload.github.com/YassineKADER/Drawniness_Iot_Project/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YassineKADER%2FDrawniness_Iot_Project/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261789227,"owners_count":23209774,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino","drowsiness-detection","fastapi","grafana-dashboard","influxdb","iot-application","yolov8"],"created_at":"2024-12-30T13:00:24.351Z","updated_at":"2026-02-10T06:32:16.537Z","avatar_url":"https://github.com/YassineKADER.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Real-Time Drowsiness Detection \u0026 Driver Safety System\r\n\r\n\u003cp align=\"center\"\u003e\r\n  \u003cimg src=\"https://avatars.githubusercontent.com/u/80207770\" alt=\"Project Banner\" width=\"199\"\u003e\r\n\u003c/p\u003e\r\n\r\n## Overview\r\n\r\nThis project is a comprehensive IoT solution designed to enhance driver safety by detecting drowsiness in real-time. Leveraging computer vision, machine learning, and cloud services, this system not only detects drowsiness but also triggers alerts and notifications to prevent potential accidents. This system includes a drowsiness detection model, backend API, database integration, and Arduino-based hardware.\r\n\r\n## Features\r\n\r\n-   **Real-Time Drowsiness Detection:** Utilizes a trained YOLOv8 model to analyze video streams and detect drowsiness.\r\n-   **Backend API:** A FastAPI-based backend server handles user authentication, event tracking, and SOS alerts, integrated with InfluxDB for data storage.\r\n-   **Data Visualization:** Uses Grafana to visualize and analyze driver behavior data.\r\n-   **Cloud Integration:** Data is stored in an InfluxDB database with the capability to integrate with external APIs for event notifications.\r\n-   **Arduino Integration:** Controls physical alerts through an Arduino board, triggering LED blinking.\r\n-   **Comprehensive System:** It covers the whole pipeline, from computer vision to hardware alerts, ensuring a complete safety solution.\r\n\r\n## Architecture\r\n\r\nThe project follows this architecture:\r\n\r\n1.  **Video Capture:** An RTMP stream provides real-time video input.(you can use just your webcame if you want to work with rtmp like me you should setup a rtmp server like nginx with nginx-rtmp-module or MonaServer if your using windows)\r\n2.  **YOLOv8 Model:** A pre-trained YOLOv8 model detects drowsy and other states.\r\n3.  **Backend API:** A FastAPI server handles:\r\n    -   User authentication (via JWT).\r\n    -   Event recording into InfluxDB (drowsiness, active, inactive, sleep).\r\n    -   SOS alerts and location information.\r\n    -   External API integration (for future HTTP event handling).\r\n4.  **InfluxDB:** Time-series database for storing event and SOS data.\r\n5.  **Grafana:** Visualizes data from InfluxDB for analysis.\r\n6.  **Arduino:** Receives commands via serial communication to trigger physical alerts (LED blinking).\r\n\r\n## Getting Started\r\n\r\nFollow these steps to set up and run the project:\r\n\r\n### Prerequisites\r\n\r\n-   Python 3.10+\r\n-   InfluxDB\r\n-   RTMP server (e.g., nginx-rtmp-module)\r\n-   Arduino IDE\r\n-   Nodejs (for Grafana)\r\n-   Basic knowledge of Linux command-line\r\n\r\n### Setup\r\n\r\n1.  **Clone the repository:**\r\n\r\n    ```bash\r\n    git clone https://github.com/your-username/realtime_detection.git\r\n    cd realtime_detection\r\n    ```\r\n\r\n2.  **Create and Activate the Virtual Environment:**\r\n\r\n    ```bash\r\n    python3 -m venv venv\r\n    source venv/bin/activate  # On Linux/macOS\r\n    venv\\Scripts\\activate  # On Windows\r\n    ```\r\n\r\n3.  **Install Dependencies:**\r\n\r\n    ```bash\r\n    pip install -r req.txt\r\n    ```\r\n\r\n4.  **Configure Environment Variables:**\r\n\r\n    -   Create a `.env` file in the root directory.\r\n    -   Add the necessary environment variables:\r\n\r\n        ```env\r\n        INFLUXDB_HOST=your_influxdb_host\r\n        INFLUXDB_PORT=8086\r\n        INFLUXDB_USERNAME=your_influxdb_username\r\n        INFLUXDB_PASSWORD=your_influxdb_password\r\n        INFLUXDB_DATABASE=your_influxdb_database\r\n        API_URL=http://localhost:8000\r\n        RTMP_STREAM_URL=rtmp://localhost:1935/live/1\r\n        MODEL_PATH=./yolo/best_with_100_epochs.pt\r\n        SECRET_KEY=your_secret_jwt_key\r\n        LOGIN_EMAIL=your_email\r\n        LOGIN_PASSWORD=your_password\r\n        ```\r\n        \r\n        Replace placeholder values with your actual values.\r\n        Make sure to replace `your_secret_jwt_key` with a strong and randomly generated secret key.\r\n\r\n5.  **Run InfluxDB and Grafana:**\r\n\r\n    -   Ensure InfluxDB is running and configured with the provided credentials.\r\n    -   Import the Grafana dashboard (`grafana/dashboard.json`) for easy visualization of the data.\r\n    -   For Grafana setup, use the following command to install all the required packages:\r\n        ```bash\r\n        sudo npm install -g @grafana/toolkit\r\n        ```\r\n        Then run\r\n        ```bash\r\n        grafana-cli plugins install grafana-influxdb-datasource\r\n        ```\r\n        and\r\n        ```bash\r\n        grafana-server\r\n        ```\r\n\r\n6.  **Start the RTMP server**\r\n\r\n    -   Configure and start your RTMP server. Make sure that you have `ffmpeg` installed.\r\n    -   To simulate an rtmp stream run this command:\r\n\r\n        ```bash\r\n        ffmpeg -re -stream_loop -1 -i video.mp4 -c copy -f flv rtmp://localhost:1935/live/1\r\n        ```\r\n\r\n        Note: replace video.mp4 with your video.\r\n7.  **Run the Backend API:**\r\n\r\n    ```bash\r\n    python server.py # or  python server_run.py if you want the server to run on a different port\r\n    ```\r\n\r\n8.  **Run the Main Application:**\r\n\r\n    ```bash\r\n    python main.py\r\n    ```\r\n\r\n9.  **Upload Arduino code to the board:**\r\n\r\n    - Open `arduino_code/main.ino` in Arduino IDE\r\n    - Select the correct port\r\n    - Upload the code\r\n\r\n### Using the System\r\n\r\n1.  **Log in with provided credentials.**\r\n2.  **Start the video stream using RTMP.**\r\n3.  The system will detect drowsiness and send events/SOS alerts to the backend server.\r\n4.  If drowsiness is detected, the Arduino will trigger an LED to blink.\r\n\r\r\n## Development\r\n\r\n-   The drowsiness detection model was trained using YOLOv8, please check the notebook to reproduce the training.\r\n-   Feel free to contribute to this project by opening issues, requesting features, or submitting pull requests.\r\n\r\n## Test\r\n\r\n-   `test.py` contains simple requests to the API to test the functionality.\r\n-   You can simulate data using `faker.py`.\r\n\r\n## Additional Resources\r\n\r\n-   YOLOv8: [https://github.com/ultralytics/ultralytics](https://github.com/ultralytics/ultralytics)\r\n-   FastAPI: [https://fastapi.tiangolo.com/](https://fastapi.tiangolo.com/)\r\n-   InfluxDB: [https://www.influxdata.com/](https://www.influxdata.com/)\r\n-   Grafana: [https://grafana.com/](https://grafana.com/)\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to open issues or submit pull requests.\r\n\r\n## Arduino Code\r\n\r\nThe Arduino code `arduino_code/main.ino` controls the physical alerts using an LED. It communicates via serial with the main application. Here is a basic overview:\r\n\r\n-   **Motor Control**: Defines pins for motor control, but they are not used in this version.\r\n-   **LED**: Defines a pin for the LED (pin 13) for visual alert.\r\n-   **Serial Communication**: Listens for commands via serial (baud rate 9600).\r\n-   **Commands**:\r\n    -  `\"STOP\"`:\r\n       - On the first \"STOP\" command, it slows down motors (not used in this version).\r\n       - On the second \"STOP\" command, it stops the motors (not used in this version) and start blinking the LED.\r\n    -   `\"START\"`: Resets the system, stop blinking the LED (if blinking), and resumes motors (not used in this version)\r\n-   **Blinking LED**: Blinks the LED until a `\"START\"` command is received.\r\n\n\u003cp align=\"center\"\u003e\r\n  Made with ❤️ by Yassine Kader (EROS)\r\n\r\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyassinekader%2Fdrawniness_iot_project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyassinekader%2Fdrawniness_iot_project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyassinekader%2Fdrawniness_iot_project/lists"}