Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

52 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flex Sensor Exercise Dashboard Logo

Flex Sensor Exercise Dashboard

Real-time wearable exercise monitoring with ESP32 flex sensors, Flask, Socket.IO, and MongoDB.


Python Flask Socket.IO ESP32 MongoDB



Flex Sensor Exercise Dashboard Preview

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.


Features

Real-time monitoring

  • Live session controls for starting and stopping exercise sessions
  • Socket.IO dashboard updates for active session state and incoming sensor batches
  • Flex sensor graph showing live readings for three flex channels
  • 2D wrist position view using angle_x and angle_y from the incoming data stream
  • Raw response panel for debugging live packets and connection state

Exercise analytics

  • Automatic repetition counting when flex values rise above baseline and return to baseline
  • Per-sensor rep totals for Flex 1, Flex 2, and Flex 3
  • Combined total reps across all flex sensors
  • Movement interpretation banner showing whether the patient is actively flexing
  • Latest wrist angle summary for quick movement feedback

Backend + data flow

  • Flask API for session control, polling, and historical session data
  • UDP listener for incoming ESP32 or sensor gateway packets
  • HTTP /flex-data endpoint for alternate sensor ingestion
  • MongoDB storage for saved exercise batches
  • Session-specific retrieval for reviewing completed exercises

Frontend quality

  • Responsive layout for desktop and tablet-style displays
  • Clinical-style UI with cards, metrics, movement rules, and status badges
  • Accessible status text for connection, session, and movement states
  • Optimized canvas rendering for smoother live visualization
  • No backend API changes required for frontend improvements



Screenshots


Dashboard Overview
Dashboard Overview
Current session controls, live metrics, sensor rules, and visualizations

Flex Sensor Chart
Flex Sensor Chart
Live flex sensor values with baseline reference

Wrist Position Visualization
2D Wrist Position
Wrist movement mapped from angle_x and angle_y values




Technical Implementation

Core architecture

  • ESP32 or sensor client sends batches of flex sensor data
  • Flask backend manages active exercise sessions
  • UDP listener receives real-time sensor packets
  • Socket.IO broadcasts live data to connected browsers
  • MongoDB stores completed session batches for later review

Data format

  • Each sensor row uses five values:
    [flex1, flex2, flex3, angle_x, angle_y]
  • A full packet contains:
    {
      "session_id": "session_123",
      "batch_start_ms": 1000,
      "batch_end_ms": 1100,
      "data": [[15, 16, 14, 2.1, -1.4]]
    }



Project Structure

.
├── 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



Getting Started

1. Clone the repository

git clone https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git
cd YOUR_REPO_NAME

2. Create a virtual environment

python -m venv venv
source venv/bin/activate

On Windows:

python -m venv venv
venv\Scripts\activate

3. Install dependencies

pip install -r requirements.txt

Example requirements.txt:

flask
flask-socketio
pymongo
python-dotenv

4. Configure environment variables

Create 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=5005

5. Start the Flask server

python main.py

The dashboard runs at:

http://localhost:5000



API Reference

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



Socket.IO Events

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



ESP32 Sensor Packet

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]



Movement Logic

The dashboard uses a default flex baseline of:

15

A repetition is counted when:

  1. A flex sensor value rises above 15
  2. The same sensor later returns to 15 or below

This creates one return cycle for that sensor.




Recommended Improvements

Hardware + protocol

  • Add a device_id to each ESP32 packet
  • Add a batch_id or sequence number to detect duplicates
  • Consider MQTT for more reliable IoT transport
  • Add calibration mode for patient-specific baselines

Software

  • Move secrets out of code and into .env
  • Add authentication before clinical or public use
  • Add automated tests for session and packet validation
  • Add CSV export for saved exercise sessions
  • Add patient/session metadata fields



FAQ

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.



Credits

Built for real-time exercise monitoring using ESP32 sensors, Flask, Socket.IO, MongoDB, and a browser-based dashboard.


Issues Contributions


Developed by Branden Pavon, Nicolas Holasek, Serafim Sharkov, Mirzett Evans IV, Neil Artista

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages