Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ jobs:
target: esp32s3
- path: 'components/qwiicnes/example'
target: esp32
- path: 'components/remote_debug/example'
target: esp32s3
- path: 'components/rmt/example'
target: esp32s3
- path: 'components/rtsp/example'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/upload_components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ jobs:
components/qmi8658
components/qtpy
components/qwiicnes
components/remote_debug
components/rmt
components/rtsp
components/runqueue
Expand Down
5 changes: 5 additions & 0 deletions components/remote_debug/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
idf_component_register(
INCLUDE_DIRS "include"
SRC_DIRS "src"
REQUIRES esp_http_server driver adc base_component file_system timer
)
76 changes: 76 additions & 0 deletions components/remote_debug/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Remote Debug

[![Badge](https://components.espressif.com/components/espp/remote_debug/badge.svg)](https://components.espressif.com/components/espp/remote_debug)

Web-based remote debugging interface providing GPIO control, real-time ADC
monitoring, and optional console log viewing over HTTP. Uses `espp::Timer` for
efficient, configurable periodic updates.

https://github.com/user-attachments/assets/ee806c6c-0f6b-4dd0-a5b0-82b80410b5bc

<img width="607" height="2048" alt="image" src="https://github.com/user-attachments/assets/5977033c-eee8-4be2-a9c4-634fd3100480" />

## Features

- **GPIO Control**: Configure pins as input/output, read states, control outputs via web interface
- **ADC Monitoring**: Real-time visualization of ADC channels with configurable sample rates
- **Console Log Viewer**: Optional stdout redirection to web-viewable log with ANSI color support
- **Efficient Updates**: Uses `espp::Timer` for optimal performance with configurable priority
- **RESTful API**: JSON endpoints for programmatic access
- **Responsive UI**: Modern web interface that works on desktop and mobile
- **Multi-client Support**: Optimized for multiple concurrent clients through batched updates

## Performance

The component has been optimized for efficiency:

- Uses `espp::Timer` for precise, lightweight periodic updates
- Configurable task priority and stack size
- Batched ADC data updates reduce HTTP overhead
- Ring buffer implementation for efficient data management
- Efficient JSON generation minimizes processing overhead

## Dependencies

- `espp::Timer` - Periodic task execution
- `espp::Adc` - ADC channel management
- `espp::FileSystem` - LittleFS for optional log storage
- ESP HTTP Server - Web interface hosting

## Console Logging

When `enable_log_capture` is enabled in the config, stdout is redirected to a file
viewable in the web interface. The log viewer supports ANSI color codes.

**Important**: For real-time log updates, enable LittleFS file flushing:

```
CONFIG_LITTLEFS_FLUSH_FILE_EVERY_WRITE=y
```

## API Endpoints

The component exposes the following HTTP endpoints:

- `GET /` - Main web interface (HTML page)
- `GET /api/gpio/get` - Get all GPIO states and configurations (JSON)
- `POST /api/gpio/set` - Set GPIO output state (JSON: `{"pin": N, "value": 0|1}`)
- `POST /api/gpio/config` - Configure GPIO direction (JSON: `{"pin": N, "mode": 1|3}`)
- Mode values: `1` = INPUT, `3` = INPUT_OUTPUT (OUTPUT is promoted to INPUT_OUTPUT for safety)
- `GET /api/adc/data` - Get ADC readings and plot data (JSON with ring buffer indices)
- `GET /api/logs` - Get console log contents (text/plain with ANSI colors)
- `POST /api/logs/start` - Start log capture (redirects stdout to file)
- `POST /api/logs/stop` - Stop log capture (restores stdout to /dev/console)

Set this in your `sdkconfig.defaults` or via `idf.py menuconfig` → Component
config → LittleFS. Without this, logs only appear after the buffer fills.

## Example

See the example in the `example/` folder for a complete demonstration with WiFi
connection, GPIO control, ADC monitoring, and console log viewing.

## External Resources

- [ESP-IDF HTTP Server Documentation](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/protocols/esp_http_server.html)
- [ADC Continuous Mode](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc_continuous.html)
22 changes: 22 additions & 0 deletions components/remote_debug/example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# The following lines of boilerplate have to be in your project's CMakeLists
# in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.20)

set(ENV{IDF_COMPONENT_MANAGER} "0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)

# add the component directories that we want to use
set(EXTRA_COMPONENT_DIRS
"../../../components/"
)

set(
COMPONENTS
"main esptool_py remote_debug task timer nvs_flash wifi"
CACHE STRING
"List of components to include"
)

project(remote_debug_example)

set(CMAKE_CXX_STANDARD 20)
100 changes: 100 additions & 0 deletions components/remote_debug/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Remote Debug Example

This example demonstrates the `espp::RemoteDebug` component, providing a
web-based interface for GPIO control, real-time ADC monitoring, and console log
viewing.

https://github.com/user-attachments/assets/ee806c6c-0f6b-4dd0-a5b0-82b80410b5bc

<img width="607" height="2048" alt="image" src="https://github.com/user-attachments/assets/5977033c-eee8-4be2-a9c4-634fd3100480" />

## How to use example

### Hardware Required

This example can run on any ESP32 development board. For testing:
- Connect LEDs or other peripherals / inputs to GPIO pins
- Connect analog sensors to ADC-capable pins

### Configure the project

```
idf.py menuconfig
```

Navigate to `Remote Debug Example Configuration`:
- WiFi credentials (SSID and password)
- Server configuration (port, title)
- GPIO configuration (number of pins, pin numbers, labels)
- ADC configuration (channels, attenuation, labels, sample rate, buffer size)
- Console logging (enable/disable, buffer size)

**Important**: If enabling console logging, you must also set:
- Component config → LittleFS → `CONFIG_LITTLEFS_FLUSH_FILE_EVERY_WRITE=y`

This ensures real-time log updates on the web interface.

### Build and Flash

Build the project and flash it to the board, then run monitor tool to view serial output:

```
idf.py -p PORT flash monitor
```

(Replace PORT with the name of the serial port to use.)

(To exit the serial monitor, type ``Ctrl-]``.)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

### Access the Interface

1. Device connects to configured WiFi network
2. Check serial monitor for assigned IP address
3. Open web browser to `http://<device-ip>:<port>` (default port: 8080)
4. Use the interface to control GPIOs, monitor ADCs, and view console logs

## Example Output

<img width="1396" height="460" alt="CleanShot 2026-01-27 at 00 13 39@2x" src="https://github.com/user-attachments/assets/bc129b24-24c0-4ed0-9976-33035eef5630" />

Screenshots:
<img width="1764" height="2274" alt="CleanShot 2026-01-27 at 00 12 32@2x" src="https://github.com/user-attachments/assets/5a22eb67-8cad-468e-b214-117ff70ed73e" />
<img width="1764" height="2274" alt="CleanShot 2026-01-27 at 00 13 06@2x" src="https://github.com/user-attachments/assets/f893a8b2-35f6-4bc6-81ca-24e500e12232" />

## Web Interface Features

- **GPIO Control**
- Configure pins as input or output
- Read current states in real-time
- Set output pins HIGH or LOW
- Visual state indicators

- **ADC Monitoring**
- Real-time plotting with automatic updates
- Multiple channels displayed simultaneously
- Voltage display (converted from raw values)
- Configurable sample rate and buffer size

- **Console Log Viewer** (when enabled)
- Live stdout output
- ANSI color code support
- Auto-scrolling display
- Configurable buffer size

## API Endpoints

Programmatic access via JSON REST API:

```
GET /api/gpio/get - Get all GPIO states and configurations
POST /api/gpio/set - Set GPIO output state (JSON: {"pin": N, "value": 0|1})
POST /api/gpio/config - Configure GPIO direction (JSON: {"pin": N, "mode": 1|3})
GET /api/adc/data - Get ADC readings and plot data
POST /api/logs/start - Start log capture (redirects stdout to file)
POST /api/logs/stop - Stop log capture (restores stdout to /dev/console)
GET /api/logs - Get console log content (text/plain with ANSI colors)
```

Note: GPIO mode values are `1` for INPUT and `3` for INPUT_OUTPUT. OUTPUT mode (2) is automatically promoted to INPUT_OUTPUT for safety.
3 changes: 3 additions & 0 deletions components/remote_debug/example/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
idf_component_register(SRC_DIRS "."
INCLUDE_DIRS "."
PRIV_REQUIRES remote_debug wifi nvs file_system timer)
Loading