Real-time wearable exercise monitoring with ESP32 flex sensors, Flask, Socket.IO, and MongoDB.
A clinical-style dashboard for tracking patient flex sensor exercises in real time.
Streams flex sensor and wrist angle data, counts repetitions, visualizes movement, and stores completed sessions.
Note
This project is a prototype exercise monitoring system. It is not a medical device and should not be used for diagnosis, treatment decisions, or emergency monitoring.
|
|
|
Core architecture
|
Data format
|
.
├── main.py # Flask, Socket.IO, UDP listener, MongoDB session storage
├── templates/
│ └── index.html # Patient dashboard UI
├── esp32-flex-sensor-client/ # ESP32 firmware / sensor sender code
├── docs/
│ └── media/
│ └── img/ # README images and dashboard screenshots
├── .env # Local environment variables, not committed
├── requirements.txt # Python dependencies
└── README.md
git clone https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
cd YOUR_REPO_NAMEpython -m venv venv
source venv/bin/activateOn Windows:
python -m venv venv
venv\Scripts\activatepip install -r requirements.txtExample requirements.txt:
flask
flask-socketio
pymongo
python-dotenvCreate a .env file:
SECRET_KEY=replace-this-with-a-random-secret
MONGO_URI=mongodb+srv://username:[email protected]/?appName=Cluster0
MONGO_DB=hackdavis
UDP_HOST=0.0.0.0
UDP_PORT=5005python main.pyThe dashboard runs at:
http://localhost:5000
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Serves the patient dashboard |
GET |
/socket-debug |
Checks Socket.IO server status and UDP configuration |
POST |
/start_exercise |
Starts a new exercise session |
POST |
/stop_exercise |
Stops the active session and saves batches to MongoDB |
POST |
/flex-data |
Accepts a flex sensor batch over HTTP |
GET |
/active-session |
Returns current active session state |
GET |
/active-session-data |
Returns buffered active session batches |
GET |
/exercise-data?session_id=... |
Loads saved session data from MongoDB |
GET |
/last-exercise-data |
Returns the latest saved exercise batch |
| Event | Direction | Description |
|---|---|---|
request_active_session |
Browser → Server | Requests the current session state and recent data |
ping_test |
Browser → Server | Tests the Socket.IO connection |
active_session_state |
Server → Browser | Sends active/inactive session state |
active_session_snapshot |
Server → Browser | Sends recent buffered session batches |
session_started |
Server → Browser | Notifies dashboard that a new session started |
flex_batch |
Server → Browser | Streams a live flex sensor batch to the dashboard |
session_stopped |
Server → Browser | Notifies dashboard that a session stopped and was saved |
The ESP32 or gateway should send JSON packets using this structure:
{
"session_id": "session_123",
"batch_start_ms": 1000,
"batch_end_ms": 1100,
"data": [
[15, 16, 14, 2.1, -1.4],
[16, 18, 15, 2.4, -1.1],
[14, 15, 15, 2.0, -0.8]
]
}The dashboard expects each row to contain:
[flex1, flex2, flex3, angle_x, angle_y]
The dashboard uses a default flex baseline of:
15
A repetition is counted when:
- A flex sensor value rises above
15 - The same sensor later returns to
15or below
This creates one return cycle for that sensor.
|
|
Does this require MongoDB?
MongoDB is used for saving completed exercise sessions. The live dashboard can still display active session data while the server is running, but historical loading depends on the database connection.
Can the sensor send data over HTTP instead of UDP?
Yes. The backend includes a
POST /flex-data endpoint that accepts the same JSON packet structure used by the UDP listener.
What does the wrist position chart show?
The wrist chart maps
angle_x to horizontal movement and angle_y to vertical movement. The center represents a neutral wrist position.
How are reps counted?
Each flex sensor has its own above-baseline state. A rep is counted when the sensor crosses above the baseline and later returns to baseline or below.
Is this ready for clinical use?
No. This is a prototype dashboard and data collection system. Clinical use would require validation, security review, privacy controls, reliability testing, and regulatory review.


