Skip to content
cic1337xdaPublic

About

Smart AR Hand Physiotherapy & Wireless MyoWare 2.0 EMG Biofeedback Platform

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

ArtiQ Smart AR Physiotherapy Logo

ArtiQ

Smart AR Hand Physiotherapy & Wireless MyoWare 2.0 EMG Biofeedback Platform

Architecture MediaPipe Hands FastAPI PostgreSQL MQTT Docker

ArtiQ is an interactive smart physiotherapy rehabilitation platform combining client-side MediaPipe Hands AR tracking with an ESP32 + MyoWare 2.0 wireless surface EMG biofeedback node. It delivers real-time %MVC muscle activation telemetry over MQTT, green-screen Chroma Key exercise guidance, and clinical session logging inside an Apple-grade Liquid Glass desktop web portal backed by FastAPI, PostgreSQL 15, and Resend OTP security.


πŸ“‘ Language Options / Pilihan Bahasa


πŸ›οΈ High-Level System Architecture

+---------------------------------------------------------------------------------------------------+
|                                      ARTIQ SYSTEM ARCHITECTURE                                    |
+---------------------------------------------------------------------------------------------------+

      [ CLINICAL EDGE HARDWARE ]                                      [ CLOUD & SERVER STACK ]
      Folder: esp32/                                                  Folder: ArtiQ/

 +----------------------------------+                            +----------------------------------+
 |       ESP32 EMG SENSOR NODE      |                            |        ECLIPSE MOSQUITTO         |
 |  - MyoWare 2.0 (ENV Pin @ GPIO32)|    MQTT (TCP / Port 1883)  |       MQTT BROKER (v2.0)         |
 |  - 12-bit Oversampled ADC (1kHz) | <========================> |  - artiq/emg/data/{MAC} (20 Hz)  |
 |  - Attack/Decay Envelope Filter  |     KeepAlive 15s / LWT    |  - artiq/emg/status/{MAC} (LWT)  |
 |  - Auto Baseline & 3s MVC Peak   |                            |  - artiq/emg/command/{MAC}       |
 +----------------------------------+                            +----------------------------------+
                                                                                  |
                                                                                  v
 +----------------------------------+                            +----------------------------------+
 |   DESKTOP BROWSER EDGE AI CLIENT |                            |       FASTAPI BACKEND (8830)     |
 |  - MediaPipe Hands 21-Landmarks  |   HTTPS + HttpOnly JWT     |  - Modular App (Core/API/Models) |
 |  - Euclidean Grip Rep Counter    | <========================> |  - Security Headers & CSRF Guard |
 |  - Chroma Key Guide Video Engine |   50ms Telemetry Polling   |  - Rate Limit & 15m Lockout      |
 |  - Liquid Glass UI (Min 900px)   |                            |  - Resend 6-Digit OTP Dispatcher |
 +----------------------------------+                            +----------------------------------+
                                                                           |              |
                                                                           v              v
                                                                 +--------------+  +----------------+
                                                                 | POSTGRESQL 15|  |   RESEND API   |
                                                                 |  (Port 5450) |  | mail.flowkraft |
                                                                 | Asia/KL (+8) |  | OTP + CID Logo |
                                                                 +--------------+  +----------------+

πŸ”Œ Hardware Circuit & Wiring Schematic

The physical wiring for the ArtiQ EMG Node (Rev 1.0)β€”interconnecting the ESP32 microcontroller and MyoWare 2.0 Muscle Sensorβ€”is verified in the circuit schematic below:

ArtiQ ESP32 and MyoWare 2.0 Hardware Circuit Schematic

Hardware Pinout Summary Table

Subsystem Component / Pin ESP32 GPIO Operating Voltage Signal Description
Power Supply MyoWare 2.0 VIN (Pin 1) 3V3 3.3V DC Regulated 3.3V output from ESP32 onboard LDO
Ground MyoWare 2.0 GND (Pin 2) GND 0V Common ground reference
EMG Envelope MyoWare 2.0 ENV (Pin 3) GPIO 32 (D32) 0.0V – 3.3V Analog ADC1_CH4 12-bit (0–4095) hardware-rectified envelope

✨ Key Features & Algorithmic Highlights

1. MyoWare 2.0 1000Hz Envelope & %MVC Normalization

  • Samples the MyoWare 2.0 ENV pin at 1000 Hz on Wi-Fi-safe ADC1_CH4 (GPIO 32) using an 8-sample oversampling filter (readSmoothedADC()) to eliminate ADC spike jitter.
  • Auto-calibrates the resting muscle baseline (0%) at boot and captures the 3-second Maximum Voluntary Contraction (mvcValue) peak via remote "calibrate" command, streaming normalized %MVC (0–150%) to the portal at 20 Hz.

2. Client-Side MediaPipe Hands AR Rep Counter

  • Processes desktop webcam feeds locally in the browser with MediaPipe Hands (zero video uploaded to servers).
  • Computes the average Euclidean distance from wrist (landmark 0) to index (8), middle (12), and ring (16) fingertips: engaging grip below 0.15 and counting a completed repetition on release above 0.20 with an 800 ms anti-ghosting cooldown.

3. Real-Time Chroma Key Exercise Guidance

  • Composites guide.mp4 dynamically onto an HTML5 <canvas> via per-pixel alpha green-screen masking so patients follow target grip form alongside live AR landmarks.

4. Bidirectional MQTT & Hardware LWT Watchdog

  • ESP32 nodes register a retained Last Will and Testament (LWT) on artiq/emg/status/{MAC} ("online" / "offline"), allowing the dashboard to reflect hardware connectivity instantaneously.

5. Modular FastAPI Security & Liquid Glass Desktop Portal

  • Implements Bcrypt password hashing, HS256 JWT HttpOnly/Secure/SameSite=Lax cookies, cryptographic 6-digit Resend OTPs (10-minute expiry, 5 max attempts, single-use) for registration and password reset, 15-minute brute-force account lockout, CSRF Origin/Referer validation, HTTP security headers, and Asia/Kuala_Lumpur (GMT+8) synchronization.
  • Includes a Liquid Glass Mobile Blocker (<= 900 px), dedicated privacy.html, branded 404.html, robots.txt, sitemap.xml, and llms.txt.

πŸ“‚ Repository Structure

.
β”œβ”€β”€ README.md                           # Master Project Documentation (English)
β”œβ”€β”€ README_MY.md                        # Master Project Documentation (Bahasa Melayu)
β”œβ”€β”€ Schematic_artiq_2026-11-12.png      # Rendered Hardware Circuit Schematic
β”œβ”€β”€ Schematic_artiq_2026-11-12.pdf      # Printable Hardware CAD Schematic (Rev 1.0)
β”œβ”€β”€ logo.svg                            # Vector Project Logo
β”œβ”€β”€ favicon.svg                         # Vector Browser Favicon
β”œβ”€β”€ favicon.ico                         # Multi-Resolution ICO Favicon
β”œβ”€β”€ .env.example                        # Environment Variable Template
β”œβ”€β”€ .gitignore                          # Git Exclusion Rules
β”‚
β”œβ”€β”€ esp32/                              # ESP32 Firmware & Hardware Documentation
β”‚   β”œβ”€β”€ README.md / README_MY.md        # Hardware Overview & BOM
β”‚   β”œβ”€β”€ PINOUT_AND_WIRING.md / _MY.md   # Pinout Table, Electrodes & Safety
β”‚   β”œβ”€β”€ MQTT_SPECIFICATION.md / _MY.md  # Topics, JSON Payloads & LWT Protocol
β”‚   β”œβ”€β”€ FLASHING_AND_SETUP.md / _MY.md  # Toolchain, Libraries & Pairing Guide
β”‚   └── artiq_emg_node/
β”‚       └── artiq_emg_node.ino          # Production MyoWare 2.0 Firmware Sketch
β”‚
└── ArtiQ/                              # Containerized Server & Liquid Glass Web Stack
    β”œβ”€β”€ README.md / README_MY.md        # Server Stack Overview
    β”œβ”€β”€ API_DOCUMENTATION.md / _MY.md   # REST Endpoints & JSON Envelopes
    β”œβ”€β”€ DOCKER_AND_SERVICES.md / _MY.md # Docker Topology, Ports & Timezone
    β”œβ”€β”€ SECURITY_AND_ARCHITECTURE.md / _MY.md # Auth, CSRF, Lockout & Edge AI Logic
    β”œβ”€β”€ docker-compose.yml              # 3-Container Orchestration (DB, API, MQTT)
    β”œβ”€β”€ .env.example                    # Container Environment Template
    β”œβ”€β”€ mosquitto/config/mosquitto.conf # Mosquitto Broker Configuration
    β”œβ”€β”€ backend/                        # Modular FastAPI Application (Non-Root Docker)
    β”‚   β”œβ”€β”€ Dockerfile
    β”‚   β”œβ”€β”€ requirements.txt
    β”‚   └── app/
    β”‚       β”œβ”€β”€ main.py
    β”‚       β”œβ”€β”€ core/                   # Config, Database, Security, Middleware
    β”‚       β”œβ”€β”€ models/                 # User, OTPRecord, ExerciseSession
    β”‚       β”œβ”€β”€ schemas/                # Auth, Session & Common Response Schemas
    β”‚       β”œβ”€β”€ api/                    # Dependencies & v1 Routers (Auth, Sessions, EMG, Health)
    β”‚       └── services/               # Resend Email & MQTT Telemetry Engine
    └── frontend/                       # Liquid Glass Clinical Web Portal
        β”œβ”€β”€ index.html                  # Auth Wall + Desktop Webcam AR Dashboard
        β”œβ”€β”€ privacy.html                # Privacy Policy Page
        β”œβ”€β”€ 404.html                    # Custom Branded 404 Page
        β”œβ”€β”€ style.css                   # Liquid Glass Optics & Mobile Blocker
        β”œβ”€β”€ app.js                      # MediaPipe Hands, Chroma Key & Telemetry Polling
        β”œβ”€β”€ logo.png / favicon.ico / favicon.svg
        β”œβ”€β”€ guide.mp4
        β”œβ”€β”€ robots.txt / sitemap.xml / llms.txt

πŸ“– Subsystem Documentation Directory

πŸ”Œ Embedded Hardware (esp32/)

🐳 Server, Docker & Web Stack (ArtiQ/)


πŸš€ Quick Start Guide

1. Deploy the Server & MQTT Stack

cd ArtiQ
cp .env.example .env
# Edit .env with PostgreSQL credentials, RESEND_API_KEY, and SECRET_KEY
docker network inspect pwn20wnd-network >/dev/null 2>&1 || docker network create pwn20wnd-network
docker compose up -d --build

2. Flash & Provision the ESP32 MyoWare 2.0 Node

  1. Install PubSubClient and WiFiManager (by tzapu) in Arduino IDE, then configure mqtt_server in esp32/artiq_emg_node/artiq_emg_node.ino.
  2. Flash to your ESP32 (GPIO 32 connected to MyoWare 2.0 ENV at 3.3V). If no saved Wi-Fi is found within 20 seconds, connect to the ArtiQ-EMG-Setup captive portal to enter your Wi-Fi credentials, then note the MAC address printed on Serial Monitor (115200 baud).

3. Open the Clinical Dashboard

  1. Visit http://localhost:8830 on a desktop/laptop browser (>= 900 px width with webcam access).
  2. Register an admin account with 6-digit email OTP verification and sign in.
  3. Open Settings, link your ESP32 MAC address, and click Calibrate to capture your 3-second MVC peak.

πŸ“œ License

  • Developed for Educational Purposes Only.

About

Smart AR Hand Physiotherapy & Wireless MyoWare 2.0 EMG Biofeedback Platform

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages