Repository navigation
Keep the configuration JSON generator off the ESP8266 stack - #1344
Merged
Merged
Conversation
Opening the configuration page on an ESP8266 reader rebooted it on 2.6.0 with a varying reset reason (WDT, soft WDT, software restart). The generator that replaced configurationJson() held its 768-byte scratch buffer and every config struct in one 2816-byte frame, against a 4 kB stack for the whole loop; 2.5.7's handler used 1904 bytes. Allocate the scratch buffer on the heap and read each section's config structs in their own block. The frame is now 1296 bytes on ESP8266. The emitted JSON is unchanged. Refs #1342 Co-Authored-By: Claude Opus 5.5 <[email protected]>
🔧 PR Build ArtifactsVersion: All environments built successfully. Download the zip files:
|
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.
Why
On 2.6.0, opening the configuration page on an ESP8266 reader (reported on a Pow-K) reboots the device. The reset reason varies between WDT reset, soft WDT reset and software restart. 2.5.7 is stable on the same device, and ESP32 readers are not affected.
The configuration JSON moved into
AmsJsonGenerator::generateConfigurationJson()(#1169). That function keeps its 768-byte scratch buffer and all 15 config structs in a single stack frame. The ESP8266 has a 4 kB stack for the wholeloop()call chain. AddhandleClient(), the request handler,snprintf_P(with float formatting) andsendContent(), and the stack overflows. The memory next to it gets corrupted, which explains why the reset reason changes from one reboot to the next.Stack frame sizes from
-fstack-usageon theesp8266env:AmsWebServer::configurationJson()generateConfigurationJson(…, JsonSink&)Changes
malloc()for the duration of the call. If the allocation fails, the generator returns without emitting anything instead of crashing.MeterConfigagain for the HAN pins.The JSON sections, their order and their arguments are unchanged.
Verification
pio run -e esp8266 -e esp32builds.-fstack-usagebefore and after (numbers above).EMIT(...)calls from 2.6.0 and from this branch and compared them: all 18 are identical.Refs #1342
🤖 Generated with Claude Code