{"id":15063337,"url":"https://github.com/pcurz/fallwatcher","last_synced_at":"2025-03-15T16:13:11.171Z","repository":{"id":257147912,"uuid":"857033465","full_name":"pcurz/FallWatcher","owner":"pcurz","description":"A complete IoT-based system for detecting falls in real-time using ESP8266 devices, an MQTT broker, and a Flutter mobile application.","archived":false,"fork":false,"pushed_at":"2024-11-13T17:10:02.000Z","size":447,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T16:13:07.192Z","etag":null,"topics":["android","esp8266","esp8266-projects","flutter","iot","mqtt","node"],"latest_commit_sha":null,"homepage":"","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/pcurz.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-09-13T17:06:59.000Z","updated_at":"2024-11-13T17:10:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"72b34de0-0d89-4fa1-a87d-dbf9e6aac649","html_url":"https://github.com/pcurz/FallWatcher","commit_stats":{"total_commits":2,"total_committers":1,"mean_commits":2.0,"dds":0.0,"last_synced_commit":"00b81ce6e03b7660014bd37cd69765bd20409fd5"},"previous_names":["pcurz/fallwatcher"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcurz%2FFallWatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcurz%2FFallWatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcurz%2FFallWatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcurz%2FFallWatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pcurz","download_url":"https://codeload.github.com/pcurz/FallWatcher/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243754092,"owners_count":20342542,"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":["android","esp8266","esp8266-projects","flutter","iot","mqtt","node"],"created_at":"2024-09-24T23:55:08.881Z","updated_at":"2025-03-15T16:13:11.154Z","avatar_url":"https://github.com/pcurz.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FallWatcher\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/images/white_mode_preview.jpg\" alt=\"White Mode Preview\" width=\"125\"/\u003e\n  \u003cimg src=\"assets/images/alert_preview.jpg\" alt=\"Alert Preview\" width=\"125\"/\u003e\n  \u003cimg src=\"assets/images/app_demo.gif\" alt=\"App Demo GIF\" width=\"125\"/\u003e\n\u003c/p\u003e\n\n**FallWatcher** is an academic project that encompasses a complete IoT-based system for real-time fall detection. The solution was developed using ESP8266 devices, an MQTT broker, and a Flutter mobile application. This system integrates various components to achieve efficient communication and instant notifications. I was responsible for orchestrating the development and integration of all components, while the rest of the team constructed the physical device using IMU sensors and a 3D-printed casing. The system is composed of the following components:\n\n1. **ESP8266 Fall Detection Device**: Firmware running on ESP8266 devices that detects falls and registers with the MQTT broker.\n2. **MQTT Broker (Node.js)**: A broker built using **Aedes** and **Node.js**, which manages the communication between devices and the Flutter app. It also generates a QR code for each device's MAC address when they register.\n3. **Web Server (Express)**: Serves the generated QR code that contains the device's MAC address so it can be scanned and registered in the Flutter app.\n4. **Flutter Mobile Application**: A mobile app that allows users to receive fall detection notifications, manage the devices, and confirm their status.\n\n## System Components\n\n### 1. **ESP8266 Fall Detection Device**\n- The ESP8266 devices are responsible for detecting falls using sensors like an accelerometer.\n- When a device detects a fall, it sends a message to the MQTT broker.\n- When a device registers with the broker, the MAC address is used to generate a QR code, which can be scanned by the mobile app.\n- The firmware is located in the `esp8266/` directory.\n\n### 2. **MQTT Broker (Node.js)**\n- Built using **Aedes**, a lightweight MQTT broker, the MQTT broker handles all messages between the ESP8266 devices and the Flutter app.\n- It listens for device registration on the topic `devices/register`.\n- Upon receiving a registration message with the device’s MAC address, the broker generates a QR code that represents the MAC address and stores it.\n- The broker runs on port `1883`.\n\n### 3. **Express Web Server (Node.js)**\n- The **Express server** is responsible for serving the QR codes generated by the MQTT broker.\n- It exposes a route `/qrcode/:mac`, where `:mac` is the MAC address of the device.\n- The mobile app scans this QR code to register the device and start receiving fall detection notifications.\n- The server is configured to run on port `80` by default.\n\n### 4. **Flutter Mobile Application**\n- The **Flutter app** displays the list of devices, shows notifications when a fall is detected, and allows the user to confirm that the device is OK after a fall.\n- Devices are added by scanning the QR code generated by the MQTT broker.\n- The app subscribes to MQTT topics to receive real-time updates about the status of each device.\n\n## System Architecture\n\nThe following diagram illustrates how the system components interact with each other:\n\n```mermaid\ngraph LR\n    A[ESP8266 Device] --\u003e|Register via MAC| B(MQTT Broker)\n    B --\u003e|Generate QR Code| C[Express Web Server]\n    C --\u003e|Serve QR to Mobile App| D[Flutter App]\n    A --\u003e|Send Fall Detection| B\n    B --\u003e|Send Status Updates| D\n    D --\u003e|Confirm Device OK| B\n```\n\n### System Flow\n\n1. **Device Registration**: When a new device (ESP8266) powers up, it sends its MAC address to the MQTT broker using the topic `devices/register`.\n2. **QR Code Generation**: The broker generates a QR code using the MAC address and stores it.\n3. **QR Code Scanning**: The Express server serves the QR code, and the user can scan it with the Flutter app to register the device.\n4. **Fall Detection**: When a device detects a fall, it sends a message to the broker, which forwards the information to the Flutter app. The app displays a notification to the user.\n5. **Acknowledge Status**: The user can confirm the status of the device in the app, and the confirmation is sent back to the MQTT broker.\n\n## Setup Instructions\n\n### 1. ESP8266 Fall Detection Device\n1. Navigate to the `esp8266/` folder to access the device firmware.\n2. Flash the firmware to the ESP8266 devices.\n3. Configure the Wi-Fi credentials and the MQTT broker IP in the firmware.\n4. The device will send its MAC address to the broker when it starts.\n\n### 2. MQTT Broker Setup\n1. Navigate to the `mqtt-server/` directory.\n2. Install the dependencies:\n\n   ```bash\n   npm install\n   ```\n\n3. Start the MQTT broker:\n\n   ```bash\n   node index.js\n   ```\n\n4. The MQTT broker will now run on port `1883` and listen for device registrations and fall detection messages.\n\n### 3. Web Server Setup\n1. The web server is also part of the `mqtt-server/` folder.\n2. It will start automatically when you run the `node index.js` command.\n3. The server will be available at `http://localhost:80` and serve QR codes at the route `/qrcode/:mac`.\n\n### 4. Flutter Mobile Application Setup\n1. Navigate to the `fallwatcherapp/` folder.\n2. Install the Flutter dependencies:\n\n   ```bash\n   flutter pub get\n   ```\n\n3. Configure the MQTT broker IP in `mqtt_service.dart`:\n\n   ```dart\n   static final MqttServerClient client = MqttServerClient('', '');\n   ```\n\n   Replace with the actual IP address of your broker.\n\n4. Run the app:\n\n   ```bash\n   flutter run\n   ```\n\n## MQTT Configuration\n\nThe ESP8266 devices register with the broker using the topic:\n\n```\ndevices/register\n```\n\nThe broker listens on port `1883` for incoming messages. When a fall is detected, the device sends a message to the topic:\n\n```\nnodemcu/{device_mac}/fall\n```\n\nThe mobile app subscribes to this topic to receive real-time updates and display fall detection notifications.\n\n## Flutter App Pattern\n\nThe Flutter app uses the **Bloc/Cubit pattern** for managing the app’s state. Here is a breakdown of the architecture:\n- **Cubit**: The Cubits handle the state of the device list, device status updates, and fall detection notifications.\n- **BlocBuilder**: The UI rebuilds based on the state changes managed by the Cubits.\n- **MQTT Integration**: The app uses MQTT to receive messages about device statuses and fall detections in real time.\n\n### Features:\n- **Device Management**: Devices are added by scanning a QR code with the device’s MAC address.\n- **Notifications**: The app notifies the user when a fall is detected by any device.\n- **Acknowledge Fall**: The user can confirm that the device is OK after a fall is detected.\n\n## License\n\nThis project is licensed under the GPL v3 License. See the [LICENSE](LICENSE) file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcurz%2Ffallwatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpcurz%2Ffallwatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcurz%2Ffallwatcher/lists"}