|
| 1 | +# WLED - ESP32/ESP8266 LED Controller Firmware |
| 2 | + |
| 3 | +WLED is a fast and feature-rich implementation of an ESP32 and ESP8266 webserver to control NeoPixel (WS2812B, WS2811, SK6812) LEDs and SPI-based chipsets. The project consists of C++ firmware for microcontrollers and a modern web interface. |
| 4 | + |
| 5 | +Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here. |
| 6 | + |
| 7 | +## Working Effectively |
| 8 | + |
| 9 | +### Initial Setup |
| 10 | +- Install Node.js 20+ (specified in `.nvmrc`): Check your version with `node --version` |
| 11 | +- Install dependencies: `npm ci` (takes ~5 seconds) |
| 12 | +- Install PlatformIO for hardware builds: `pip install -r requirements.txt` (takes ~60 seconds) |
| 13 | + |
| 14 | +### Build and Test Workflow |
| 15 | +- **ALWAYS build web UI first**: `npm run build` -- takes 3 seconds. NEVER CANCEL. |
| 16 | +- **Run tests**: `npm test` -- takes 40 seconds. NEVER CANCEL. Set timeout to 2+ minutes. |
| 17 | +- **Development mode**: `npm run dev` -- monitors file changes and auto-rebuilds web UI |
| 18 | +- **Hardware firmware build**: `pio run -e [environment]` -- takes 15+ minutes. NEVER CANCEL. Set timeout to 30+ minutes. |
| 19 | + |
| 20 | +### Build Process Details |
| 21 | +The build has two main phases: |
| 22 | +1. **Web UI Generation** (`npm run build`): |
| 23 | + - Processes files in `wled00/data/` (HTML, CSS, JS) |
| 24 | + - Minifies and compresses web content |
| 25 | + - Generates `wled00/html_*.h` files with embedded web content |
| 26 | + - **CRITICAL**: Must be done before any hardware build |
| 27 | + |
| 28 | +2. **Hardware Compilation** (`pio run`): |
| 29 | + - Compiles C++ firmware for various ESP32/ESP8266 targets |
| 30 | + - Common environments: `nodemcuv2`, `esp32dev`, `esp8266_2m` |
| 31 | + - List all targets: `pio run --list-targets` |
| 32 | + |
| 33 | +## Before Finishing Work |
| 34 | + |
| 35 | +**CRITICAL: You MUST complete ALL of these steps before marking your work as complete:** |
| 36 | + |
| 37 | +1. **Run the test suite**: `npm test` -- Set timeout to 2+ minutes. NEVER CANCEL. |
| 38 | + - All tests MUST pass |
| 39 | + - If tests fail, fix the issue before proceeding |
| 40 | + |
| 41 | +2. **Build at least one hardware environment**: `pio run -e esp32dev` -- Set timeout to 30+ minutes. NEVER CANCEL. |
| 42 | + - Choose `esp32dev` as it's a common, representative environment |
| 43 | + - See "Hardware Compilation" section above for the full list of common environments |
| 44 | + - The build MUST complete successfully without errors |
| 45 | + - If the build fails, fix the issue before proceeding |
| 46 | + - **DO NOT skip this step** - it validates that firmware compiles with your changes |
| 47 | + |
| 48 | +3. **For web UI changes only**: Manually test the interface |
| 49 | + - See "Manual Testing Scenarios" section below |
| 50 | + - Verify the UI loads and functions correctly |
| 51 | + |
| 52 | +**If any of these validation steps fail, you MUST fix the issues before finishing. Do NOT mark work as complete with failing builds or tests.** |
| 53 | + |
| 54 | +## Validation and Testing |
| 55 | + |
| 56 | +### Web UI Testing |
| 57 | +- **ALWAYS validate web UI changes manually**: |
| 58 | + - Start local server: `cd wled00/data && python3 -m http.server 8080` |
| 59 | + - Open `http://localhost:8080/index.htm` in browser |
| 60 | + - Test basic functionality: color picker, effects, settings pages |
| 61 | +- **Check for JavaScript errors** in browser console |
| 62 | + |
| 63 | +### Code Validation |
| 64 | +- **No automated linting configured** - follow existing code style in files you edit |
| 65 | +- **Code style**: Use tabs for web files (.html/.css/.js), spaces (2 per level) for C++ files |
| 66 | +- **C++ formatting available**: `clang-format` is installed but not in CI |
| 67 | +- **Always run tests before finishing**: `npm test` |
| 68 | +- **MANDATORY: Always run a hardware build before finishing** (see "Before Finishing Work" section below) |
| 69 | + |
| 70 | +### Manual Testing Scenarios |
| 71 | +After making changes to web UI, always test: |
| 72 | +- **Load main interface**: Verify index.htm loads without errors |
| 73 | +- **Navigation**: Test switching between main page and settings pages |
| 74 | +- **Color controls**: Verify color picker and brightness controls work |
| 75 | +- **Effects**: Test effect selection and parameter changes |
| 76 | +- **Settings**: Test form submission and validation |
| 77 | + |
| 78 | +## Common Tasks |
| 79 | + |
| 80 | +### Repository Structure |
| 81 | +``` |
| 82 | +wled00/ # Main firmware source (C++) |
| 83 | + ├── data/ # Web interface files |
| 84 | + │ ├── index.htm # Main UI |
| 85 | + │ ├── settings*.htm # Settings pages |
| 86 | + │ └── *.js/*.css # Frontend resources |
| 87 | + ├── *.cpp/*.h # Firmware source files |
| 88 | + └── html_*.h # Generated embedded web files (DO NOT EDIT) |
| 89 | +tools/ # Build tools (Node.js) |
| 90 | + ├── cdata.js # Web UI build script |
| 91 | + └── cdata-test.js # Test suite |
| 92 | +platformio.ini # Hardware build configuration |
| 93 | +package.json # Node.js dependencies and scripts |
| 94 | +.github/workflows/ # CI/CD pipelines |
| 95 | +``` |
| 96 | + |
| 97 | +### Key Files and Their Purpose |
| 98 | +- `wled00/data/index.htm` - Main web interface |
| 99 | +- `wled00/data/settings*.htm` - Configuration pages |
| 100 | +- `tools/cdata.js` - Converts web files to C++ headers |
| 101 | +- `wled00/wled.h` - Main firmware configuration |
| 102 | +- `platformio.ini` - Hardware build targets and settings |
| 103 | + |
| 104 | +### Development Workflow |
| 105 | +1. **For web UI changes**: |
| 106 | + - Edit files in `wled00/data/` |
| 107 | + - Run `npm run build` to regenerate headers |
| 108 | + - Test with local HTTP server |
| 109 | + - Run `npm test` to validate build system |
| 110 | + |
| 111 | +2. **For firmware changes**: |
| 112 | + - Edit files in `wled00/` (but NOT `html_*.h` files) |
| 113 | + - Ensure web UI is built first (`npm run build`) |
| 114 | + - Build firmware: `pio run -e [target]` |
| 115 | + - Flash to device: `pio run -e [target] --target upload` |
| 116 | + |
| 117 | +3. **For both web and firmware**: |
| 118 | + - Always build web UI first |
| 119 | + - Test web interface manually |
| 120 | + - Build and test firmware if making firmware changes |
| 121 | + |
| 122 | +## Build Timing and Timeouts |
| 123 | + |
| 124 | +**IMPORTANT: Use these timeout values when running builds:** |
| 125 | + |
| 126 | +- **Web UI build** (`npm run build`): 3 seconds typical - Set timeout to 30 seconds minimum |
| 127 | +- **Test suite** (`npm test`): 40 seconds typical - Set timeout to 120 seconds (2 minutes) minimum |
| 128 | +- **Hardware builds** (`pio run -e [target]`): 15-20 minutes typical for first build - Set timeout to 1800 seconds (30 minutes) minimum |
| 129 | + - Subsequent builds are faster due to caching |
| 130 | + - First builds download toolchains and dependencies which takes significant time |
| 131 | +- **NEVER CANCEL long-running builds** - PlatformIO downloads and compilation require patience |
| 132 | + |
| 133 | +**When validating your changes before finishing, you MUST wait for the hardware build to complete successfully. Set the timeout appropriately and be patient.** |
| 134 | + |
| 135 | +## Troubleshooting |
| 136 | + |
| 137 | +### Common Issues |
| 138 | +- **Build fails with missing html_*.h**: Run `npm run build` first |
| 139 | +- **Web UI looks broken**: Check browser console for JavaScript errors |
| 140 | +- **PlatformIO network errors**: Try again, downloads can be flaky |
| 141 | +- **Node.js version issues**: Ensure Node.js 20+ is installed (check `.nvmrc`) |
| 142 | + |
| 143 | +### When Things Go Wrong |
| 144 | +- **Clear generated files**: `rm -f wled00/html_*.h` then rebuild |
| 145 | +- **Force web UI rebuild**: `npm run build -- --force` or `npm run build -- -f` |
| 146 | +- **Clean PlatformIO cache**: `pio run --target clean` |
| 147 | +- **Reinstall dependencies**: `rm -rf node_modules && npm install` |
| 148 | + |
| 149 | +## Important Notes |
| 150 | + |
| 151 | +- **DO NOT edit `wled00/html_*.h` files** - they are auto-generated |
| 152 | +- **Always commit both source files AND generated html_*.h files** |
| 153 | +- **Web UI must be built before firmware compilation** |
| 154 | +- **Test web interface manually after any web UI changes** |
| 155 | +- **Use VS Code with PlatformIO extension for best development experience** |
| 156 | +- **Hardware builds require appropriate ESP32/ESP8266 development board** |
| 157 | + |
| 158 | +## CI/CD Pipeline |
| 159 | + |
| 160 | +**The GitHub Actions CI workflow will:** |
| 161 | +1. Installs Node.js and Python dependencies |
| 162 | +2. Runs `npm test` to validate build system (MUST pass) |
| 163 | +3. Builds web UI with `npm run build` (automatically run by PlatformIO) |
| 164 | +4. Compiles firmware for ALL hardware targets listed in `default_envs` (MUST succeed for all) |
| 165 | +5. Uploads build artifacts |
| 166 | + |
| 167 | +**To ensure CI success, you MUST locally:** |
| 168 | +- Run `npm test` and ensure it passes |
| 169 | +- Run `pio run -e esp32dev` (or another common environment from "Hardware Compilation" section) and ensure it completes successfully |
| 170 | +- If either fails locally, it WILL fail in CI |
| 171 | + |
| 172 | +**Match this workflow in your local development to ensure CI success. Do not mark work complete until you have validated builds locally.** |
0 commit comments