ProjekteEmbedded

ESP-Pin-spectrum-monitor

Real-time GPIO monitoring for ESP32/Arduino with secure WebSocket streaming, oscilloscope, and FFT analysis.

Repository
7
Sterne
0
Forks
Apr. 2026
Erstellt
vor 6 Monaten
Letzter Push

Readme

Dieses Readme enthält 4 Bilder von GitHub. Sie laden erst nach einem Klick unten.

ESP Pin Spectrum Monitor

Arduino ESP32 Python JavaScript

Note: This repository is for private testing and evaluation purposes.

A real-time GPIO monitoring and spectrum analysis tool for Arduino and ESP32 boards. This version includes significant performance optimizations and security hardening.

Current Version: 1.0.1

Features

  • Real-time GPIO Monitoring: Visualize analog and digital pin states in real-time.
  • Spectrum Analysis: High-performance FFT-based frequency analysis with LUT optimizations.
  • Multi-board Support: Native support for Arduino Uno and ESP32.
  • Detailed Instructions: See the User Manual (MANUAL.md) for safety limits and usage.
  • Security Hardened: Protected against CSWH, shell injection, and command injection.
  • Optimized Performance: Allocation-free rendering pipeline for smooth visualization.

Architecture

Arduino/ESP32 -> Serial (115200 baud) -> Python Bridge -> WebSocket -> Browser

Quick Start

1. Installation

The project uses a virtual environment to manage dependencies securely. Run the installation script once:

./install.sh

Note: This will create a .venv directory and install all required Python packages.

2. Flash the Firmware

Connect your board via USB and flash the monitoring firmware:

# For Arduino Uno
./flash.sh --board arduino-uno --port /dev/ttyUSB0

# For ESP32
./flash.sh --board esp32 --port /dev/ttyUSB0

3. Start the Bridge Server

Simply run the startup script. It will automatically activate the virtual environment:

./start-server.sh

This will:

  • Auto-detect your serial port.
  • Start the WebSocket server on port 8765 (Localhost only).
  • Serve the web interface on http://localhost:8080.
  • Open your browser automatically.

Project Structure

.
├── install.sh            # Automated venv and dependency setup
├── start-server.sh       # Launch bridge and UI (uses venv)
├── flash.sh              # Firmware flashing script
├── MANUAL.md             # Voltage safety and usage guide
├── CHANGELOG.md          # Version history
├── findings-report.md    # Security and code review findings
├── backend/              # Python bridge server
│   ├── bridge.py         # Entry point
│   ├── serial_handler.py # Serial communication
│   ├── ws_server.py      # WebSocket + Secure HTTP server
│   └── requirements.txt  # Python dependencies
├── firmware/             # Microcontroller firmware
│   ├── arduino-uno/      # C++ source for Arduino
│   └── esp32/            # Rust source for ESP32
└── frontend/             # Web interface (Vanilla JS)
    ├── app.js            # Main logic and state
    ├── charts.js         # Optimized canvas rendering
    ├── fft.js            # FFT with LUT optimizations
    └── index.html        # UI structure

Protocol

The firmware communicates using a simple CSV-based protocol:

  • Firmware -> Host: millis,val1,val2,... (one line per sample)
  • Host -> Firmware: Commands like RATE <ms>, START, STOP.

Requirements

Software

  • Python 3.7+
  • For Arduino: arduino-cli
  • For ESP32: Rust + espflash

Hardware

  • Arduino Uno or compatible board.
  • ESP32 development board.
  • USB cable for programming and data.

License

MIT License - see LICENSE file for details.

Änderungen

CHANGELOG.md

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[1.0.1] - 2024-04-16

Added

  • Created install.sh script for automated virtual environment (venv) and dependency management.
  • Created MANUAL.md with hardware voltage limits and detailed usage instructions.
  • Implemented Twiddle Factor Look-Up Tables (LUT) in fft.js for significantly improved CPU efficiency.
  • Added forEachLast to RingBuffer in charts.js for allocation-free rendering, eliminating GC pauses.

Security

  • Hardened start-server.sh against shell injection via command-line arguments.
  • Implemented Origin checks in WebSocket server to prevent Cross-Site WebSocket Hijacking (CSWH).
  • Added strict regex-based sanitization for all incoming WebSocket commands.
  • Implemented Content Security Policy (CSP) and security headers (HSTS, X-Frame-Options, etc.).
  • Restricted server bindings to 127.0.0.1 by default.

Changed

  • Refactored start-server.sh to strictly use the virtual environment.
  • Removed os.chdir() from ws_server.py to prevent global process state mutation.
  • Removed all emojis from the entire codebase, UI, and documentation for a professional text-only experience.
  • Updated README.md with new installation instructions and a link to the manual.

Fixed

  • Corrected board validation regex in flash.sh.
  • Fixed memory leaks and excessive allocations in the frontend rendering pipeline.

Ganze Datei auf GitHub