{"id":24017768,"url":"https://github.com/abidhasanrafi/edge-computing-anomaly-detection","last_synced_at":"2026-04-10T11:31:52.467Z","repository":{"id":270744601,"uuid":"911329519","full_name":"AbidHasanRafi/edge-computing-anomaly-detection","owner":"AbidHasanRafi","description":"This repository is part of an ongoing research initiative.","archived":false,"fork":false,"pushed_at":"2025-01-02T20:03:04.000Z","size":294,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T20:43:53.698Z","etag":null,"topics":["anomaly-detection","edge-computing","esp32","express-js","mongodb","mongoose","tailwind-css","wokwi"],"latest_commit_sha":null,"homepage":"https://anomaly-detection-server.vercel.app","language":"C++","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/AbidHasanRafi.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":"2025-01-02T19:00:35.000Z","updated_at":"2025-01-03T17:48:02.000Z","dependencies_parsed_at":"2025-01-11T11:32:00.711Z","dependency_job_id":null,"html_url":"https://github.com/AbidHasanRafi/edge-computing-anomaly-detection","commit_stats":null,"previous_names":["abidhasanrafi/edge-computing-anomaly-detection"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AbidHasanRafi/edge-computing-anomaly-detection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbidHasanRafi%2Fedge-computing-anomaly-detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbidHasanRafi%2Fedge-computing-anomaly-detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbidHasanRafi%2Fedge-computing-anomaly-detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbidHasanRafi%2Fedge-computing-anomaly-detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AbidHasanRafi","download_url":"https://codeload.github.com/AbidHasanRafi/edge-computing-anomaly-detection/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AbidHasanRafi%2Fedge-computing-anomaly-detection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31641114,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-10T07:40:12.752Z","status":"ssl_error","status_checked_at":"2026-04-10T07:40:11.664Z","response_time":98,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["anomaly-detection","edge-computing","esp32","express-js","mongodb","mongoose","tailwind-css","wokwi"],"created_at":"2025-01-08T09:43:02.158Z","updated_at":"2026-04-10T11:31:52.461Z","avatar_url":"https://github.com/AbidHasanRafi.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Test Framework for Edge Computing and Anomaly Detection\n\nThis repository contains two main components:\n\n1. **Anomaly Detection Server**: An Express.js server for testing POST requests and handling anomaly data.\n2. **ESP32 Anomaly Detection Server**: An ESP32 microcontroller project that simulates sending anomaly detection data to the server.\n\n## Directory Structure\n\n```\nAbidHasanRafi-edge-computing-anomaly-detection/\n├── README.md\n├── anomaly-detection-server/\n│   ├── package-lock.json\n│   ├── package.json\n│   ├── api/\n│   │   ├── data.js\n│   │   └── index.js\n│   └── public/\n│       └── index.html\n├── assets/\n│   └── anomaly-detected.png\n└── esp32-anomaly-detection-server/\n    ├── diagram.json\n    ├── libraries.txt\n    ├── sketch.ino\n    └── wokwi-project.txt\n```\n\n---\n\n## 1. Anomaly Detection Server\n\nThe `anomaly-detection-server` is an Express.js application designed to simulate a server capable of receiving and handling POST requests with anomaly detection data.\n\n### Directory Structure\n\n```\nanomaly-detection-server/\n├── api/\n│   ├── data.js       # (Optional) Handles database interaction\n│   └── index.js      # Main server logic\n└── public/\n    └── index.html    # Frontend interface for displaying anomalies\n```\n\n### Features\n\n- Accepts and stores anomaly data using a RESTful API.\n- Fetches and displays real-time data on the frontend.\n- Easy to deploy and test.\n\n### Installation and Usage\n\n1. **Navigate to the directory:**\n\n   ```bash\n   cd anomaly-detection-server\n   ```\n\n2. **Install dependencies:**\n\n   ```bash\n   npm install\n   ```\n\n3. **Set up environment variables:**\n   Create a `.env` file in the `anomaly-detection-server` directory with the following keys:\n\n   ```env\n   DB_USER=\u003cYour MongoDB User\u003e\n   DB_PASSWORD=\u003cYour MongoDB Password\u003e\n   CLUSTER_URL=\u003cYour MongoDB Cluster URL\u003e\n   DB_NAME=\u003cYour Database Name\u003e\n   APP_NAME=\u003cYour Application Name\u003e\n   PORT=3000\n   ```\n\n4. **Run the server:**\n\n   ```bash\n   node api/index.js\n   ```\n\n5. **Access the application:**\n   Open your browser and navigate to `http://localhost:3000`.\n\n### Server User Interface\n\nThe figure below shows the server's user interface, which displays the data received from the ESP-32. It includes anomaly information and power readings, providing a clear overview of the system's current status.\n\n![Server User Interface](https://raw.githubusercontent.com/AbidHasanRafi/edge-computing-anomaly-detection/main/assets/server-ui.png)\n\n_Figure: The server UI displaying data received from the ESP-32._\n\n### API Endpoints\n\n#### `POST /api/data`\n\n- **Description:** Saves anomaly data to the database.\n- **Request Body:**\n  ```json\n  {\n    \"meterId\": \"string\",\n    \"time\": \"Date\",\n    \"anomalousPowerReading\": \"number\"\n  }\n  ```\n\n#### `GET /api/data`\n\n- **Description:** Fetches all saved anomaly data.\n- **Response Example:**\n  ```json\n  [\n    {\n      \"_id\": \"string\",\n      \"meterId\": \"string\",\n      \"time\": \"Date\",\n      \"anomalousPowerReading\": \"number\"\n    }\n  ]\n  ```\n\n---\n\n## 2. ESP32 Anomaly Detection Server\n\nThe `esp32-anomaly-detection-server` is an Arduino-based project designed to simulate anomaly data transmission from an ESP32 microcontroller.\n\n### Directory Structure\n\n```\nesp32-anomaly-detection-server/\n├── diagram.json        # Circuit diagram (Wokwi format)\n├── libraries.txt       # Required libraries for the ESP32 project\n├── sketch.ino          # Main Arduino code for the ESP32\n└── wokwi-project.txt   # Wokwi project link\n```\n\n### Features\n\n- Simulates anomaly detection by generating and sending data to the server.\n- Provides a practical demonstration of IoT and edge computing concepts.\n\n### View or Run the Project\n\n- **View the Wokwi Project:** [ESP32 Anomaly Detection Server on Wokwi](https://wokwi.com/projects/418995936898646017)\n- **Run on Wokwi:** [Wokwi Simulator](https://wokwi.com)\n\n### Installation and Usage\n\n1. **Upload the Sketch:**\n\n   - Open `sketch.ino` in the Arduino IDE.\n   - Install required libraries listed in `libraries.txt`.\n   - Connect your ESP32 and upload the code.\n\n2. **Circuit Setup:**\n\n   - Use the `diagram.json` to set up your circuit in Wokwi or on a physical breadboard.\n\n3. **Simulate Data:**\n   - The ESP32 will send POST requests with anomaly data to the server.\n\nHere’s the updated README text with a detailed explanation of which light is lit based on the status shown in the figures:\n\n---\n\n### ESP-32 Circuit Simulation\n\nThe figure below shows the circuit simulation when the ESP-32 detects normal power readings. The green LED is lit to indicate normal operation, signaling that no anomalies are currently detected.\n\n![Circuit Simulation For Normal Reading](https://raw.githubusercontent.com/AbidHasanRafi/edge-computing-anomaly-detection/main/assets/normal-reading.png)\n\n_Figure: The circuit simulation for normal reading of ESP-32. The green LED is on, representing normal power consumption._\n\n---\n\nThe figure below shows the circuit simulation when the ESP-32 detects an anomaly in the power readings. The blue LED is lit to signify an anomaly, alerting the user to unusual power consumption.\n\n![Anomaly Detected Circuit Simulation](https://raw.githubusercontent.com/AbidHasanRafi/edge-computing-anomaly-detection/main/assets/anomaly-detected.png)\n\n_Figure: The anomaly detected circuit simulation of ESP-32. The blue LED is on, indicating an anomalous power reading._\n\n### ESP-32 Server Functionality\n\nThe ESP-32 server is designed to simulate power readings from an electric meter and send anomaly data to a remote server via HTTP POST requests. It also hosts a local web server to manage LED states and display real-time data on an OLED screen. Key features include:\n\n1. **Wi-Fi Connectivity**:\n\n   - Connects to a predefined Wi-Fi network (`WIFI_SSID` and `WIFI_PASSWORD`).\n   - Retrieves and prints the ESP-32's IP address on successful connection.\n\n2. **Power Reading Simulation**:\n\n   - Generates random power readings between 500 and 1000 units.\n   - Uses the `isAnomaly()` function to randomly flag anomalies (30% probability).\n   - Anomalies are marked for further processing and visualization.\n\n3. **Anomaly Data Transmission**:\n\n   - Sends detected anomalies and their associated power readings to a remote server via an HTTP POST request.\n   - Data is structured in JSON format using the ArduinoJson library.\n\n4. **Local Web Server**:\n\n   - Hosts a web server accessible from the ESP-32's local IP address.\n   - Provides an interactive HTML page to toggle the state of two LEDs (blue and red).\n   - URL patterns are dynamically handled using the `UriBraces` feature.\n\n5. **LED Indications**:\n\n   - Blue LED: Indicates an anomaly in power readings.\n   - Green LED: Indicates normal power readings.\n   - Red LED: Reserved for additional notifications or error signals.\n\n6. **OLED Display**:\n\n   - Displays the current power reading and its status (normal or anomalous) on an Adafruit SSD1306 OLED screen.\n   - Provides visual feedback for both simulated data and anomaly detection.\n\n7. **Data Streaming**:\n\n   - Streams power readings and anomaly statuses for two minutes or until 10 anomalies are detected.\n   - After the streaming period, the LEDs are turned off to conserve power.\n\n8. **HTTP Server Routes**:\n   - `/`: Returns an HTML interface to toggle LED states and view their status.\n   - `/toggle/{LED}`: Toggles the state of the specified LED (blue or red).\n\n### How It Works\n\n1. **Setup Phase**:\n\n   - Initializes Wi-Fi, OLED display, and GPIO pins for LEDs.\n   - Starts the HTTP server and waits for client requests.\n\n2. **Power Reading Loop**:\n\n   - Simulates power readings at 10-second intervals.\n   - Flags readings as anomalies using a probabilistic function.\n   - Sends the flagged data to a remote server and updates the OLED display.\n\n3. **Client Interaction**:\n\n   - Users can toggle LED states using the provided web interface.\n   - The server dynamically updates the HTML page to reflect the current LED states.\n\n4. **End Condition**:\n   - Stops streaming data after two minutes or 10 anomalies.\n   - Resets LED states to off.\n\n### How to Test the ESP-32 Server\n\n1. **Setup Environment**:\n\n   - Connect the ESP-32 to a Wi-Fi network.\n   - Upload the sketch to the ESP-32 using the Arduino IDE.\n\n2. **Access Web Interface**:\n\n   - Open the ESP-32's IP address in a web browser.\n   - Use the interface to toggle LED states.\n\n3. **Monitor OLED Display**:\n\n   - Observe real-time power readings and anomaly detection statuses.\n\n4. **Check Server Integration**:\n   - Update the `serverUrl` with the actual API endpoint.\n   - Verify that anomaly data is being sent and received correctly.\n\n---\n\n## Disclaimer\n\nThis repository is part of an ongoing research initiative. Unauthorized use, duplication, or modification of the resources provided here without the explicit consent of the author is **strictly prohibited**.\n\nFor inquiries, please contact:  \n📧 **ahr16.abidhasanrafi@gmail.com**\n\n© **Test Framework for Edge Computing and Anomaly Detection - All rights reserved.**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabidhasanrafi%2Fedge-computing-anomaly-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabidhasanrafi%2Fedge-computing-anomaly-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabidhasanrafi%2Fedge-computing-anomaly-detection/lists"}