This file provides guidance to agents when working with code in this repository.
- ESP32 firmware (PlatformIO/Arduino): root-level
src/,include/,test/ - Angular 21 web UI:
growui/src/app/— built todata/angular-www/via PlatformIO post-build hook (ngbuild.py)
pio run # build firmware
pio run -t upload # upload to device
pio monitor # serial monitor @ 115200- Compile-time sensor flags (in
platformio.inibuild_flags):-DSENSOR_BME280=1,-DSENSOR_ENS160AHT21=1,-DUSE_SDCARD,-DMYSSID="...",-DGOVEE_BTH5179=1. These #ifdef-gate entire modules insrc/main.cppand source files. - Partition scheme: Uses
custom_partitions.csv(not standard ESP32 partitions). - Monitor filter:
esp32_exception_decoderis configured — stack traces will be demangled automatically.
cd growui && npm install
npm run start # dev server (proxies API to device per src/proxy.conf.json)
npm run build # production build → outputs to ../data/angular-www/- No test files exist in
test/directory — it is empty. Angular unit tests can be run withnpm run watch(triggersng build --watch).
PlatformIO's post-build hook (ngbuild.py) automatically runs npm run build --production inside growui/, then cleans up license/route files from the output. Running pio run alone builds both firmware and embeds the Angular assets.
- Naming: snake_case for functions/variables (
sendSocketMsg(),g_timeZoneOffset), PascalCase for classes (MyWebServer,FanController). - Includes: angle brackets
< >for system/framework, quotes" "for local headers. Conditional includes guarded by#ifdef. - Global state: Static globals prefixed with
g_(e.g.,g_timeZoneOffset). Module-level globals use file-scopestaticor unnamed namespace where appropriate. - Logging: Use ESP32 log macros (
log_i,log_e, etc.) from esp_log.h — notSerial.printffor general logging (though Serial.printf is used in WebSocket callbacks). - I²C addresses: Hardcoded as compile-time defines in
platformio.ini:BME_I2C_ADD=119,i2c_pwn_addr=95,i2c_light_addr=94. These are decimal values (not shifted).
- Strict mode enabled:
"strict": trueintsconfig.json;noImplicitOverride,strictTemplatesalso on. - Component pattern: Standalone Angular 21 components with
@component()decorators, signal-based inputs/outputs where applicable. - SCSS styles: Per-component scoped styles (
.scssfiles alongside.ts). - Proxy config: API calls to device are proxied via
src/proxy.conf.json— paths/settings,/flashspiffs,/2026,/ws(WebSocket).
- WiFiManager (
src/WiFiManager.cpp) handles AP/client mode with fallback credentials compiled intoplatformio.ini. - NVS storage: Preferences stored in ESP32 NVS under namespaces like
"Voltage",NVS_WIFI_NS. UseMyPreferences_*()helpers — do not access Preferences directly. - WebSocket real-time: AsyncWebSocket on
/wspushes sensor/device state to UI via JSON (socketmsg). SeesendSocketMsg(). - SPIFFS vs partition: Firmware uses custom partition layout (not SPIFFS by default). SD card logging is optional (
#ifdef USE_SDCARD).