Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
; ============================================================================
; Project Configuration
; ============================================================================
; default_envs limits `pio run` to the firmware targets. The `native` env builds
; host unit tests only (pio test -e native) and must never be a default build.
; ============================================================================
[platformio]
default_envs = esp32s3-dev, esp32s3-prod
; ============================================================================
; Common Configuration (shared by all environments)
; ============================================================================
; In general, it is required to always pin all the libraries and packages to the exact
; version to ensure reproducible builds.
; ============================================================================
[common]
; Platform Configuration
; NOTE: Official PlatformIO does not support Arduino 3.x yet due to issues with Espressif
; (https://github.com/platformio/platform-espressif32/issues/1225), so we use pioarduino
;
; ============================================================================
; IMPORTANT - DO NOT BUMP THIS VERSION WITHOUT AN SDKCONFIG DIFF + BENCH SOAK
; ============================================================================
; Pinned to 55.03.32 (Arduino Core 3.3.2 / ESP-IDF v5.5.1).
;
; The 2.3.0 bump to 55.03.311 (Arduino 3.3.11 / IDF 5.5.5) caused the
; 2026-08-12 fleet OTA failures: that core's baked-in sdkconfig drops
; CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y, moving WiFi/LWIP buffers from PSRAM
; to internal RAM. Measured on hardware with identical firmware: internal-heap
; low-water mark fell from a 40.9 KB floor to ~1 KB, with a 16-20 KB transient
; dip on every MQTT TLS publish. OTA HTTPS downloads then die mid-transfer
; with "esp-aes: Failed to allocate memory" (3 of 6 beta devices, job
; energyme-home-prod-ota-beta-2-3-1-20260812-120007).
;
; The sdkconfig is baked into the prebuilt core libs - application code CANNOT
; restore the flag. `pio run` RAM totals do NOT reveal this class of change
; (statics went DOWN across the bad bump).
;
; Before any bump: run source/utils/diff_platform_sdkconfig.py old new, read
; the filtered diff, then soak the bench device with a heap watch (free,
; minFree, maxAlloc during MQTT publishes). CI (platform-guard.yml) blocks
; PRs that change the platform line without a [platform-bump-ack] marker.
; ============================================================================
platform = https://github.com/pioarduino/platform-espressif32/releases/download/55.03.32/platform-espressif32.zip
board = esp32-s3-devkitc-1 ; Do not try other boards - ESP32-S3-N16R2 specific config
framework = arduino
; ESP32-S3 Hardware Configuration
; NOTE: The following config is the ONLY way to use the 2MB PSRAM of the ESP32-S3-N16R2
board_build.arduino.memory_type = qio_qspi ; Required for 2MB PSRAM on ESP32-S3-N16R2
board_build.psram_type = qio ; PSRAM configuration
board_build.flash_mode = qio ; Flash interface mode
board_upload.flash_size = 16MB ; Real flash size
board_upload.maximum_size = 16777216 ; Maximum upload size
board_build.partitions = partitions_esp32s3_n16r2.csv ; Custom partition table for ESP32-S3-N16R2
; Development Tools
monitor_speed = 115200
monitor_filters = esp32_exception_decoder, log2file ; Useful for decoding crash data and logging
; Library Configuration
lib_compat_mode = strict ; Required by ESPAsyncWebServer
lib_ldf_mode = chain ; Required by ESPAsyncWebServer
; Dependencies
lib_deps =
; === Core Libraries ===
jijio/AdvancedLogger@2.1.0 ; Queue-based logging to LittleFS/serial/callbacks (PSRAM queue is opt-in, see the logger flags)
bblanchon/ArduinoJson@7.4.3 ; JSON processing
bblanchon/StreamUtils@1.9.2 ; Bigger buffers, improving MQTT throughput
; === Network & Communication ===
esp32async/AsyncTCP@3.5.0 ; Required by ESPAsyncWebServer
esp32async/ESPAsyncWebServer@3.12.0 ; Async HTTP web server
knolleary/PubSubClient@2.8.0 ; MQTT client
miq19/eModbus@1.7.4 ; Modbus TCP support
; === Utilities ===
tobozo/ESP32-targz@1.3.1 ; Archive extraction for long-term data storage
; Embedded Files (Web Interface - shared by all environments)
board_build.embed_txtfiles =
; === Web Interface Styles ===
css/button.css
css/forms.css
css/index.css
css/reboot-wait.css
css/styles.css
css/section.css
css/tooltip.css
css/typography.css
; === Web Interface Scripts ===
js/api-client.js
js/chart-helpers.js
js/data-helpers.js
js/issues.js
js/power-flow.js
js/reboot-wait.js
js/tooltip.js
; === Web Interface Pages ===
html/ade7953-tester.html
html/calibration.html
html/channel.html
html/configuration.html
html/index.html
html/info.html
html/integrations.html
html/log.html
html/swagger.html
html/update.html
html/waveform.html
html/wifi-setup.html
html/password-setup.html
; === Resources ===
resources/favicon.svg
resources/swagger.yaml
; Common build flags
common_build_flags =
; === USB CDC (expose Serial over native USB) ===
-DARDUINO_USB_CDC_ON_BOOT=1 ; Map Serial to USB CDC; comment out if using classical TX/RX pins
; === Hardware Configuration ===
-DBOARD_HAS_PSRAM
; === Firmware image descriptor (.rodata_custom_desc) ===
; Same mechanism IDF uses for esp_app_desc: keep the otherwise-unreferenced
; descriptor section alive through --gc-sections. See src/app_image_descriptor.cpp.
-Wl,-u,ENERGYME_APP_DESC
; === Logger Configuration ===
-DADVANCED_LOGGER_ALLOCABLE_HEAP_SIZE=16384
; Opt-in PSRAM queue (internal RAM only holds the control structure; the size above is the
; fallback if PSRAM is missing). A log rotation stalls the log task for ~4.5 s, worst measured
; rate under web load is ~16 lines/s: 218 entries is ~3x that. Sized for the Home (2 MB PSRAM,
; ~950 KB free), the Pro has plenty.
-DADVANCED_LOGGER_PSRAM_QUEUE_SIZE=131072
; The library default (4096) leaves ~800 bytes free with save=INFO; LittleFS block
; allocation/compaction runs deeper and overflowed it as soon as many lines were saved
; (panic in AdvancedLogTask inside lfs, 64 KB of heap free - not a heap problem).
-DADVANCED_LOGGER_TASK_STACK_SIZE=8192
; === Environment Info ===
-D BUILD_ENV_NAME=$PIOENV ; Useful for giving directly the path to analyse the ELF file
; === Open Source Telemetry ===
; Anonymous usage statistics to help track project adoption
; Sends: SHA-256 hashed device ID, firmware version, sketch MD5 hash
; When: Once per boot after WiFi connection
; Privacy: No personal data, no tracking, no analytics beyond device count
; Implementation: See src/customwifi.cpp (_sendOpenSourceTelemetry function)
; Set to 1 to enable, set to 0 or remove to disable
-DENABLE_OPEN_SOURCE_TELEMETRY=1
; === PCB Version Fallback (community / self-built devices) ===
; Factory-provisioned devices store the PCB revision in NVS (factory_ns::pcb_revision)
; and the firmware picks the matching HardwareProfile at boot.
; For community builds where NVS is empty, uncomment and set to the packed version number
; (major*10 + minor, e.g. 50 for v5.0, 60 for v6.0, 61 for v6.1) to force a specific profile.
; NVS always wins when present - this flag only applies when factory NVS is missing/malformed.
; If unset and NVS is empty, the latest profile of the build's product (PRODUCT_FALLBACK) is used.
; -DPCB_VERSION_FALLBACK=60
; Force community mode regardless of factory NVS contents. Useful to test community
; behaviour on a fully-provisioned dev board without wiping its NVS certs/serials.
; -DFORCE_COMMUNITY_MODE ; ignore factory NVS, force community mode (local testing only)
; Suppress library warnings globally (all libraries, not source code)
; These are compiler flags applied before build_src_flags, so libraries get suppressed
common_suppress_lib_warnings =
-Wno-deprecated-declarations ; Suppress deprecation warnings from AsyncTCP, AsyncWebServer
-Wno-address ; Suppress address-of warnings from library headers
; Common compiler warnings (source-only)
; NOTE: Applies only to the current project, not the libraries
common_build_src_flags =
-Wall ; Enable most warnings
-Wextra ; Additional useful warnings
-Wformat ; Check printf/scanf format strings
-Wformat-security ; Security issues in format strings
-Wconversion ; Type conversion warnings
; ============================================================================
; Applied to every environment: generate git_rev.h for the firmware image
; descriptor (src/app_image_descriptor.cpp). Harmless on native.
; ============================================================================
[env]
extra_scripts = pre:utils/inject_git_rev.py
; Serial uploads write boot_app0.bin (the "boot app0" otadata image) at the core default
; 0xE000. In partitions_esp32s3_n16r2.csv that address is INSIDE nvs (0x9000-0x19000) and
; otadata lives at 0x1A000, so every serial flash corrupted two NVS pages (config/factory
; data silently lost: seen on the Pro bench as the commissioning marker vanishing after each
; upload) and never reset otadata (a device previously OTA'd to app1 kept booting app1).
; Must track the otadata offset in the partition table.
board_upload.arduino.boot_app0 = 0x1A000
; ============================================================================
; Development Environment (ESP32-S3)
; Use for: Development, debugging, troubleshooting
; Features: No optimization, full debug symbols, verbose logging
; ============================================================================
[env:esp32s3-dev]
; Platform Configuration
platform = ${common.platform}
board = ${common.board}
framework = ${common.framework}
; Static Analysis Tools
check_tool = cppcheck, clangtidy ; Static code analysis for better code quality
; Build Configuration
build_flags =
${common.common_suppress_lib_warnings} ; Suppress library warnings
${common.common_build_flags}
; === Compilation & Debug Options ===
-g3 ; Maximum debug information
-O0 ; No optimizations (easier debugging)
-fstack-usage ; Generate stack usage files (.su)
; === Application Defines ===
-DENV_DEV ; Development environment
; === ESP32 Debug Configuration ===
-DCORE_DEBUG_LEVEL=4 ; Verbose logging
-DDEBUG_ESP_PORT=Serial
-DDEBUG_ESP_CORE
; Source-only compiler warnings (excludes libraries)
build_src_flags =
${common.common_build_src_flags}
; Hardware Configuration
board_build.arduino.memory_type = ${common.board_build.arduino.memory_type}
board_build.psram_type = ${common.board_build.psram_type}
board_build.flash_mode = ${common.board_build.flash_mode}
board_upload.flash_size = ${common.board_upload.flash_size}
board_upload.maximum_size = ${common.board_upload.maximum_size}
board_build.partitions = ${common.board_build.partitions}
; Development Tools
monitor_speed = ${common.monitor_speed}
monitor_filters = ${common.monitor_filters}
; Library Configuration
lib_compat_mode = ${common.lib_compat_mode}
lib_ldf_mode = ${common.lib_ldf_mode}
lib_deps = ${common.lib_deps}
; Embedded Files
board_build.embed_txtfiles = ${common.board_build.embed_txtfiles}
; ============================================================================
; Development Environment, v5.0 board (ESP32-S3)
; Use for: development on a v5.0 PCB, which is not factory-provisioned and so
; has no factory_ns::pcb_revision to select a profile from.
; Identical to esp32s3-dev apart from pinning the hardware profile to v5.0.
; Without the pin it would fall back to the latest Home profile (v6.1) and
; drive entirely the wrong GPIOs - the v5 and v6 pinouts share almost nothing.
; ============================================================================
[env:esp32s3-dev-v5]
extends = env:esp32s3-dev
build_flags =
${env:esp32s3-dev.build_flags}
-DPCB_VERSION_FALLBACK=50 ; v5.0; NVS still wins if a revision is provisioned
; PCB v5.0 only has TX and RX exposed
-UARDUINO_USB_CDC_ON_BOOT
-DARDUINO_USB_CDC_ON_BOOT=0
; ============================================================================
; Development Environment, Home Pro board (ESP32-S3-WROOM-1U-N16R8)
; The Pro module has 8MB OCTAL PSRAM (vs 2MB quad on Home): the PSRAM mode is
; baked into the prebuilt core libs, so Pro needs its own memory_type and its
; own binary. Same pinned platform, same partition table (16MB flash on both).
; PRODUCT_FALLBACK=1 (homepro) so this binary never falls back to a Home
; pinout when factory NVS is missing/damaged - the product is known at build time.
; ============================================================================
[env:esp32s3-dev-pro]
extends = env:esp32s3-dev
board_build.arduino.memory_type = qio_opi ; Octal PSRAM on N16R8
board_build.psram_type = opi
build_flags =
${env:esp32s3-dev.build_flags}
-DPRODUCT_FALLBACK=1 ; homepro; NVS still wins if a valid product is provisioned
; ============================================================================
; Production Environment (ESP32-S3)
; Use for: Production deployment, releases
; Features: Size optimization, minimal logging, assertions disabled
; ============================================================================
[env:esp32s3-prod]
; Platform Configuration
platform = ${common.platform}
board = ${common.board}
framework = ${common.framework}
; Static Analysis Tools
check_tool = cppcheck, clangtidy ; Static code analysis for better code quality
; Build Configuration
build_flags =
${common.common_suppress_lib_warnings} ; Suppress library warnings
${common.common_build_flags}
; === Compilation & Optimization Options ===
-Os ; Optimize for size
-DNDEBUG ; Disable assertions
; === Logging ===
-DADVANCED_LOGGER_DISABLE_VERBOSE
; === ESP32 Debug Configuration ===
-DCORE_DEBUG_LEVEL=2 ; Error + Warning only
; Source-only compiler warnings (excludes libraries)
build_src_flags =
${common.common_build_src_flags}
; Hardware Configuration
board_build.arduino.memory_type = ${common.board_build.arduino.memory_type}
board_build.psram_type = ${common.board_build.psram_type}
board_build.flash_mode = ${common.board_build.flash_mode}
board_upload.flash_size = ${common.board_upload.flash_size}
board_upload.maximum_size = ${common.board_upload.maximum_size}
board_build.partitions = ${common.board_build.partitions}
; Development Tools
monitor_speed = ${common.monitor_speed}
monitor_filters = ${common.monitor_filters}
; Library Configuration
lib_compat_mode = ${common.lib_compat_mode}
lib_ldf_mode = ${common.lib_ldf_mode}
lib_deps = ${common.lib_deps}
; Embedded Files
board_build.embed_txtfiles = ${common.board_build.embed_txtfiles}
; ============================================================================
; Production Environment, Home Pro board (ESP32-S3-WROOM-1U-N16R8)
; See esp32s3-dev-pro for why Pro needs its own env/binary (octal PSRAM).
; ============================================================================
[env:esp32s3-prod-pro]
extends = env:esp32s3-prod
board_build.arduino.memory_type = qio_opi ; Octal PSRAM on N16R8
board_build.psram_type = opi
build_flags =
${env:esp32s3-prod.build_flags}
-DPRODUCT_FALLBACK=1 ; homepro; NVS still wins if a valid product is provisioned
; ============================================================================
; Native host environment - unit tests only: pio test -e native
; Compiles the pure libraries (e.g. lib/meter_logic) + test/ with the host
; compiler (no Arduino, no board). Never built by `pio run` (see default_envs).
; ============================================================================
[env:native]
platform = native
test_framework = unity
build_flags =
-std=c++17
-Wall
-Wextra
f4329a85eThis file is pinned to the selected release. Download the original to open it in your design tool.