|
| 1 | +# OpenEVSE ESP32 Firmware |
| 2 | + |
| 3 | +OpenEVSE ESP32 Firmware is an ESP32-based WiFi gateway for OpenEVSE charging stations that provides web UI control, MQTT integration, solar divert functionality, and OCPP support. |
| 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 | +### Bootstrap the repository: |
| 10 | +- `git submodule update --init --recursive` |
| 11 | +- `cd gui-v2` |
| 12 | +- `npm install` -- takes ~20 seconds. |
| 13 | +- `npm run build` -- takes ~10 seconds. |
| 14 | +- `cd ..` |
| 15 | + |
| 16 | +### Build and test the repository: |
| 17 | +- `pip install --upgrade platformio` -- install PlatformIO build system |
| 18 | +- `pio run -e openevse_wifi_v1` -- build default environment. **NEVER CANCEL**. First build takes 15-45 minutes (downloads ESP32 toolchain ~500MB). Set timeout to 60+ minutes. |
| 19 | +- **Common Build Failure**: "HTTPClientError" indicates network restrictions blocking PlatformIO registry (api.registry.platformio.org) |
| 20 | +- Alternative boards: `pio run -e adafruit_huzzah32`, `pio run -e nodemcu-32s`, `pio run -e olimex_esp32-gateway-e` |
| 21 | +- **Full CI Build**: Tests 15+ board configurations, takes ~60+ minutes total |
| 22 | + |
| 23 | +### Test the repository: |
| 24 | +- `cd divert_sim` |
| 25 | +- `pip install -r requirements.txt` |
| 26 | +- `pytest -v` -- runs Python-based divert simulation tests. Takes ~5 seconds. |
| 27 | +- HTTP API tests available in `test/*.http` files (require VS Code REST Client extension) |
| 28 | + |
| 29 | +### Development environment setup: |
| 30 | +- Install Node.js (v20+) and npm for GUI development |
| 31 | +- Install Python 3.x for build scripts and testing |
| 32 | +- Install PlatformIO for ESP32 firmware compilation |
| 33 | +- Git submodules are required for GUI source code |
| 34 | + |
| 35 | +## Critical Build Dependencies |
| 36 | + |
| 37 | +### Network Requirements: |
| 38 | +- **CRITICAL**: PlatformIO requires internet access to download ESP32 platform packages and libraries |
| 39 | +- First-time builds download ~500MB of ESP32 toolchain and libraries |
| 40 | +- If you encounter "HTTPClientError" or connection timeouts, this indicates network restrictions blocking PlatformIO registry access |
| 41 | +- **WORKAROUND**: If builds fail due to network restrictions, focus on GUI development and testing components that work offline |
| 42 | + |
| 43 | +### GUI Build Process (REQUIRED before firmware): |
| 44 | +- The web GUI is built separately as static assets then embedded into ESP32 firmware |
| 45 | +- GUI source is in git submodule `gui-v2` (separate repository) |
| 46 | +- **ALWAYS** run GUI build before firmware build: |
| 47 | + 1. `git submodule update --init --recursive` |
| 48 | + 2. `cd gui-v2 && npm install && npm run build` |
| 49 | + 3. Return to project root for firmware build |
| 50 | + |
| 51 | +### Build Timing Expectations: |
| 52 | +- **GUI npm install**: ~20 seconds |
| 53 | +- **GUI npm run build**: ~10 seconds |
| 54 | +- **ESP32 first build**: 15-45 minutes (downloads toolchain) |
| 55 | +- **ESP32 incremental builds**: 2-5 minutes |
| 56 | +- **NEVER CANCEL** long-running builds - ESP32 compilation is inherently slow |
| 57 | + |
| 58 | +## Validation |
| 59 | + |
| 60 | +### What You CAN Test Without Hardware: |
| 61 | +- **GUI Development**: Full web interface build and preview |
| 62 | +- **Configuration Logic**: Python-based config validation tests |
| 63 | +- **Divert Algorithm**: Solar divert simulation testing |
| 64 | +- **Build Process**: Firmware compilation (when network allows) |
| 65 | + |
| 66 | +### What You CANNOT Test Without Hardware: |
| 67 | +- **Runtime Functionality**: ESP32 firmware execution |
| 68 | +- **API Endpoints**: HTTP/MQTT communication |
| 69 | +- **OTA Updates**: Over-the-air firmware updates |
| 70 | +- **Hardware Features**: LCD display, RFID, temperature sensors |
| 71 | + |
| 72 | +### MANDATORY Validation Steps After Any Changes: |
| 73 | +1. **Test GUI Build**: `cd gui-v2 && npm run build` -- must complete without errors |
| 74 | +2. **Verify Submodules**: `git submodule status` -- must show clean state |
| 75 | +3. **Run Python Tests**: `cd divert_sim && pytest -v` -- must pass when dependencies available |
| 76 | +4. **Check Build Config**: Review `platformio.ini` for any new board configurations |
| 77 | + |
| 78 | +### Complete Validation Workflow: |
| 79 | +```bash |
| 80 | +# 1. Verify git submodules are initialized |
| 81 | +git submodule status |
| 82 | + |
| 83 | +# 2. Build and verify GUI assets |
| 84 | +cd gui-v2 |
| 85 | +npm install |
| 86 | +npm run build |
| 87 | +ls -la dist/ # Should contain assets |
| 88 | +cd .. |
| 89 | + |
| 90 | +# 3. Test Python components (if dependencies available) |
| 91 | +cd divert_sim |
| 92 | +pip install -r requirements.txt |
| 93 | +python3 -c "import test_config; print('Config tests importable')" |
| 94 | +cd .. |
| 95 | + |
| 96 | +# 4. Attempt ESP32 build (will fail with network restrictions) |
| 97 | +pio run -e openevse_wifi_v1 # Expected to fail with HTTPClientError in restricted environments |
| 98 | +``` |
| 99 | + |
| 100 | +### Expected Validation Results: |
| 101 | +- **GUI build**: Always succeeds (~10 seconds) |
| 102 | +- **Python imports**: Always succeed when pytest installed |
| 103 | +- **ESP32 build**: Fails in network-restricted environments, succeeds with internet access |
| 104 | + |
| 105 | +## Common Tasks |
| 106 | + |
| 107 | +### Adding new web UI features: |
| 108 | +1. Navigate to `gui-v2/src/` for Svelte components |
| 109 | +2. Make changes to UI components |
| 110 | +3. Test with `npm run dev` (starts development server) |
| 111 | +4. Build with `npm run build` |
| 112 | +5. Rebuild ESP32 firmware to embed new assets |
| 113 | + |
| 114 | +### Modifying firmware behavior: |
| 115 | +1. Edit source code in `src/` directory |
| 116 | +2. Key files: `src/app_config.cpp` (configuration), `src/web_server.cpp` (HTTP endpoints) |
| 117 | +3. Build specific board: `pio run -e your_board_name` |
| 118 | +4. Upload to hardware: `pio run -e your_board_name -t upload` |
| 119 | + |
| 120 | +### Working with configuration: |
| 121 | +- Board configurations in `platformio.ini` with 15+ supported ESP32 variants |
| 122 | +- **Default environment**: `openevse_wifi_v1` (ESP32 with NeoPixel LEDs, MCP9808 temperature sensor) |
| 123 | +- **Common development boards**: |
| 124 | + - `adafruit_huzzah32` - Adafruit Feather ESP32 |
| 125 | + - `nodemcu-32s` - NodeMCU-32S development board |
| 126 | + - `espressif_esp-wrover-kit` - Espressif development kit |
| 127 | + - `olimex_esp32-gateway-e` - Olimex Gateway with Ethernet |
| 128 | +- **Debug environments**: Add `_dev` suffix for debug builds (e.g., `openevse_wifi_v1_dev`) |
| 129 | +- **TFT Display**: `openevse_wifi_tft_v1` for boards with LCD touchscreen |
| 130 | +- **Ethernet Support**: `olimex_esp32-gateway-e`, `wt32-eth01`, `olimex_esp32-poe-iso` |
| 131 | + |
| 132 | +## Repository Structure |
| 133 | + |
| 134 | +### Key directories: |
| 135 | +- `src/` - ESP32 firmware source code (C++) |
| 136 | +- `gui-v2/` - Web UI source (Svelte/JavaScript, git submodule) |
| 137 | +- `docs/` - User and developer documentation |
| 138 | +- `test/` - HTTP API test files |
| 139 | +- `divert_sim/` - Python-based simulation and testing |
| 140 | +- `scripts/` - Build automation scripts |
| 141 | +- `.github/workflows/` - CI/CD pipeline definitions |
| 142 | + |
| 143 | +### Important files: |
| 144 | +- `platformio.ini` - Build configuration for all board variants |
| 145 | +- `src/app_config.cpp` - Device configuration management |
| 146 | +- `gui-v2/package.json` - Web UI dependencies and build scripts |
| 147 | +- `readme.md` - Project overview and requirements |
| 148 | + |
| 149 | +### Build outputs: |
| 150 | +- ESP32 firmware: `.pio/build/{board_name}/firmware.bin` |
| 151 | +- GUI assets: `gui-v2/dist/` (embedded into firmware) |
| 152 | +- Python test results: `divert_sim/output/` |
| 153 | + |
| 154 | +## Troubleshooting Common Issues |
| 155 | + |
| 156 | +### "HTTPClientError" or "Could not resolve host: api.registry.platformio.org": |
| 157 | +- **Cause**: Network firewall blocking PlatformIO package registry |
| 158 | +- **Impact**: Cannot download ESP32 platform packages (~500MB) or library dependencies |
| 159 | +- **Workaround**: Focus on GUI development and Python testing components |
| 160 | +- **Alternative**: Download pre-built firmware binaries from GitHub releases |
| 161 | + |
| 162 | +### "Warning: GUI files not found" during build: |
| 163 | +- **Cause**: Git submodules not initialized OR GUI not built |
| 164 | +- **Solution**: `git submodule update --init --recursive && cd gui-v2 && npm install && npm run build` |
| 165 | + |
| 166 | +### "Warning: Node.JS and NPM required to update the UI": |
| 167 | +- **Cause**: Node.js not installed or not in PATH |
| 168 | +- **Solution**: Install Node.js v20+ and ensure `node` and `npm` commands are available |
| 169 | + |
| 170 | +### ESP32 upload failures ("Failed to connect to ESP32"): |
| 171 | +- **Cause**: Hardware not connected, wrong USB port, or ESP32 not in bootloader mode |
| 172 | +- **Solution**: Check connections, try different USB port, manually enter bootloader mode |
| 173 | +- **Bootloader Mode**: Hold BOOT button, press RESET button, release RESET, release BOOT |
| 174 | + |
| 175 | +### Long build times or apparent hangs: |
| 176 | +- **ESP32 builds take 15-45 minutes** on first build (downloads toolchain) |
| 177 | +- **NEVER CANCEL** builds that appear stuck - ESP32 compilation is inherently slow |
| 178 | +- Monitor `.platformio` directory size growth to confirm download progress |
| 179 | +- Subsequent builds are faster (2-5 minutes) using cached dependencies |
| 180 | + |
| 181 | +## API and Development References |
| 182 | + |
| 183 | +- **API Documentation**: https://openevse.stoplight.io/docs/openevse-wifi-v4/ |
| 184 | +- **User Guide**: `docs/user-guide.md` |
| 185 | +- **Developer Guide**: `docs/developer-guide.md` |
| 186 | +- **MQTT API**: `docs/mqtt.md` |
| 187 | +- **CI/CD Pipeline**: `.github/workflows/build.yaml` |
0 commit comments