Skip to content

ttien0181/IOT_SS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Health Monitoring System

A real-time IoT-based health monitoring system that collects vital signs such as heart rate, SpO₂, body temperature, and motion using biomedical sensors and ESP32, then processes and visualizes the data through a full-stack IoT architecture (MQTT, Mobius oneM2M, nCube Thyme Nodejs, Flask Web Dashboard).


Overview

This project was built as part of the Samsung Innovation Campus - IoT Capstone Course. The system aims to enhance hospital and remote patient monitoring by enabling continuous data acquisition, real-time alerting, and historical trend visualization.


Requirements

1. Operating System

  • Linux (Ubuntu 20.04/22.04+ recommended)
  • Windows with WSL (Ubuntu) enabled

2. System Packages (Linux/WSL)

Install core tools and services:

sudo apt update
sudo apt install -y git curl build-essential python3 python3-venv python3-pip \
    mariadb-server mosquitto

Verify versions:

python3 --version
node --version || true
npm --version || true
mysql --version
mosquitto -h | head -n1

If Node.js is not installed, install LTS:

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs

3. Clone Repository

git clone https://github.com/ttien0181/IOT_SS.git
cd IOT_SS

4. Database Setup (MariaDB/MySQL)

Create required databases and users. Mobius uses mobiusdb. Flask auth uses iot02 by default.

Open MySQL shell and create DBs/users:

sudo service mysql start
mysql -u root -p -e "\
CREATE DATABASE IF NOT EXISTS mobiusdb CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; \
CREATE DATABASE IF NOT EXISTS iot02 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; \
CREATE USER IF NOT EXISTS 'mobius'@'localhost' IDENTIFIED BY 'mobius'; \
GRANT ALL PRIVILEGES ON mobiusdb.* TO 'mobius'@'localhost'; \
CREATE USER IF NOT EXISTS 'ttien'@'localhost' IDENTIFIED BY '0181'; \
GRANT ALL PRIVILEGES ON iot02.* TO 'ttien'@'localhost'; \
FLUSH PRIVILEGES;"

Import Mobius schema:

mysql -u root -p mobiusdb < Mobius/mobius/mobiusdb.sql

Create Flask auth tables in iot02:

mysql -u root -p iot02 -e "\
CREATE TABLE IF NOT EXISTS pending_users ( \
  email VARCHAR(255) PRIMARY KEY, \
  password_hash VARCHAR(255) NOT NULL, \
  otp_code VARCHAR(10) NOT NULL, \
  expires_at DATETIME NOT NULL \
) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; \
CREATE TABLE IF NOT EXISTS users ( \
  id INT AUTO_INCREMENT PRIMARY KEY, \
  email VARCHAR(255) NOT NULL UNIQUE, \
  password VARCHAR(255) NOT NULL, \
  create_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP \
) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"

5. MQTT Broker (Mosquitto)

Start broker (keep it running while testing):

sudo systemctl enable mosquitto
sudo systemctl start mosquitto

3. Hardware

Actuators

  • Led Led
  • Buzzer Buzzer

Sensor

  • MAX30100 (HR, SpO₂) MAX30100 (HR, SpO₂)
  • KY-039 (HR) KY-039 (HR)
  • DHT11 (Temp) DHT11 (Temp)
  • HC-SR501 (Motion) HC-SR501 (Motion)

Microcontroller

ESP32 (sends sensor data via MQTT) ESP32


System Architecture


Sensor Thresholds & Alerts

Sensor Normal Warning Critical
Heart Rate 60–100 bpm <55 or >110 <45 or >130
SpO₂ ≥ 95% 90% – 94% <90%
Motion Detected No Motion

Demo Screenshots

login

register

realtime

dashboard

profile

MAX30100

KY-039

HC-SR501


How to Run

1. Hardware (optional for simulation)

  • To test end-to-end without hardware, you can publish simulated MQTT messages (see step 5). For real hardware, flash ESP32 with code in ESP32/ and connect sensors.

2. Start MQTT Broker (Mosquitto)

sudo systemctl start mosquitto

3. Configure and Run Mobius (IoT Platform)

Set database and server ports via Mobius/conf.json (already created by code):

{
    "csebaseport": 7579,
    "dbhost": "localhost",
    "dbuser": "mobius",
    "dbpass": "mobius",
    "dbname": "mobiusdb"
}

Run Mobius:

cd Mobius
npm install
node mobius.js

Verify Mobius is up:

curl -s http://localhost:7579/Mobius -H "X-M2M-RI: 12345" -H "X-M2M-Origin: Sorigin" -H "Accept: application/json"

4. Run nCube-Thyme (Edge App)

Confirm it points to local Mobius in nCube-Thyme-Nodejs/conf.js:

cse = { host: 'localhost', port: '7579', name: 'Mobius', id: '/Mobius2', mqttport: '1883', wsport: '7577' };

Run:

cd nCube-Thyme-Nodejs
npm install
node thyme.js

5. Send Simulated Sensor Data via Mosquitto

Open a new terminal (keep Mobius running). Publish JSON payloads matching Flask and dashboard expectations:

TS=$(date -u +%Y-%m-%dT%H:%M:%SZ)

mosquitto_pub -h localhost -p 1883 -t "A1/1/101/spo2" -m "{\"value\": 97, \"unit\": \"%\", \"sensor_id\": \"esp32-01\", \"timestamp\": \"${TS}\"}"

mosquitto_pub -h localhost -p 1883 -t "A1/1/101/heart_rate" -m "{\"value\": 72, \"unit\": \"bpm\", \"sensor_id\": \"esp32-01\", \"timestamp\": \"${TS}\"}"

6. Run Flask Web Dashboard

cd Flask-web
python3 -m venv myvenv
source myvenv/bin/activate
pip install -r requirements.txt
python3 run.py

Open the dashboard at:

http://127.0.0.1:5000

If you use the built-in registration/login, ensure the iot02 DB and tables exist (see Requirements → Database Setup). If you prefer a single DB, you may point auth to mobiusdb in app/database/connection.py (both options supported).

Future Improvements

  • Add AI anomaly detection (arrhythmia, hypoxia)
  • Develop mobile app for doctors/nurses
  • Battery support for ESP32 + backup server
  • Cloud data storage and remote monitoring

Team members

About

IoT project of Samsung IoT class

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors