Make MO_CONFIG_MAX_VALSTRSIZE override-able via -D#450
Open
RAR wants to merge 1 commit intomatth-x:mainfrom
Open
Make MO_CONFIG_MAX_VALSTRSIZE override-able via -D#450RAR wants to merge 1 commit intomatth-x:mainfrom
RAR wants to merge 1 commit intomatth-x:mainfrom
Conversation
Wrap the existing 128-byte default in #ifndef so consumers can raise the ceiling via a build flag (`-DMO_CONFIG_MAX_VALSTRSIZE=256` etc.) without patching the header. Default is unchanged. Same shape as the surrounding MO_CONFIG_EXT_PREFIX / MO_CONFIG_TYPECHECK guards. Motivation: the OCPP 1.6 MeterValuesSampledData advertised list overflows 128 chars once the optional measurands (Temperature, SoC, Frequency, Power.Factor) are bound — Configuration::setString silently rejects the write and the CSMS-side default permanently overrides ours.
RAR
added a commit
to RAR/esphome-ocpp-server
that referenced
this pull request
Apr 26, 2026
Switches the fork pin from the single-patch valstrsize SHA (5ac8e0e) to a branch (ocpp-server) that combines: - MO_CONFIG_MAX_VALSTRSIZE override (PR matth-x/MicroOcpp#450) - Time.cpp Clock::now() delta cap from PR matth-x/MicroOcpp#447 The Time.cpp guard is defence-in-depth against the 32-bit tick-counter overflow that produces ~12 h timestamp jumps in OCPP messages. The upstream PR has both an espidf-only fix (Platform.cpp) and a platform-agnostic guard (Time.cpp); we cherry-pick only the latter since we're on MO_PLATFORM_ARDUINO and millis() wraps at ~49.7 days. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Wraps the existing
MO_CONFIG_MAX_VALSTRSIZE#definein an#ifndefguard so it can be overridden via a build flag (-DMO_CONFIG_MAX_VALSTRSIZE=256) without patching the header. The default stays 128. Same shape as the surroundingMO_CONFIG_EXT_PREFIXandMO_CONFIG_TYPECHECKguards.Motivation
The OCPP 1.6
MeterValuesSampledDataadvertised list overflows the 128-byte ceiling once the optional measurands are bound. A typical configuration that includes the four mandatory measurands plusTemperature,SoC,Frequency, andPower.Factor:…is 138 chars.
Configuration::setStringinConfigurationKeyValue.cpp:203rejects writes longer thanMO_CONFIG_MAX_VALSTRSIZEand silently returnsfalse, so the CSMS-side default permanently overrides the value the CP advertised. Without source-level access this manifests as the CSMS's shorter list winning, with no log message hinting that a write was rejected.I hit this on a CP that mirrors HA-side measurands (vehicle SoC, grid frequency, PF) into OCPP MeterValues — the rejection meant evcc never saw the extra rows even though the CP was sampling them every 30 s.
Why I think the default was 128
I assume this ceiling was sized for the original target (ESP8266, ~80 KB RAM) where every declared
Configuration<const char*>carries an inline value buffer, so cumulative cost across ~30–50 standard config keys mattered. For the typical CP that publishes 4–5 measurands, 128 chars is comfortable. Modern targets (ESP32, BK7231N, etc.) and CPs that surface optional measurands hit the wall.Why a guard, not a bump
Bumping the default would change static RAM cost for every existing user. Adding the
#ifndefguard is non-invasive: existing builds compile identically. Consumers who need more pay only for what they ask for via-D.Verification
Built and flashed against a
BK7231N(LibreTinybk72xx) CP with-DMO_CONFIG_MAX_VALSTRSIZE=256. The 138-char advertised list now survivessetString(verified by reading backMeterValuesSampledDataoverGetConfigurationand seeing all 10 entries) and the CSMS subsequently honors it on the next ChangeConfiguration round-trip.Test plan
-Dset → existing 128 kept)-DMO_CONFIG_MAX_VALSTRSIZE=256raises the ceiling andsetStringaccepts a 138-charMeterValuesSampledDataarduino-picoArduino core (BK7231N via LibreTiny)🤖 Generated with Claude Code