Repository navigation
Apply vendor board configuration only when the board type is known - #1268
Merged
Merged
Conversation
handleSave() discarded the return value of HwTools::applyBoardConfig(), leaving "success" hardcoded to true, so if(success) and both success ? ... : ... were dead branches. This regressed in 67e6a51, which lifted the per-board switch out of handleSave() into applyBoardConfig(); the original switch had a "default: success = false" arm that was lost in the move. Because clearGpio() runs before the call, an unmatched board type persisted a wiped GPIO config together with vendorConfigured = true: apPin, ledPin, ledPinRed/Green/Blue and vccPin all stayed 0xFF, leaving the LED and AP button dead and the emergency factory reset unreachable. The GUI preselects the current board type and filters on chip, but the empty option is selected when the stored type is not among the chip's options, and the endpoint accepted any value from a hand-made POST. The profile is now applied to a local GpioConfig that is only copied into the live one on success, so a rejected board type leaves neither EEPROM nor the running configuration touched. Three related issues along the same path: - clear() preserves boardType and vendorConfigured, but clearMeter() then reset rxPin, txPin and rxPinPullup, which are dictated by that same board type. Board profiles are only re-applied on boot for boardType < 20, so generic boards lost their HAN pin on every factory reset and whenever "Clear all other configuration" was used. clear() now carries those three pins across. - The reset button guard in setup() tested apPin >= 0, always true for a uint8_t. With no AP pin configured, boot spent five seconds walking a hold sequence that can never complete on an invalid pin, flashing the green and red LEDs on the way. Now tests != 0xFF, as the two other apPin call sites already do. - The vendor page navigated away regardless of the response, so a rejected board type was invisible. sysinfo is not polled unconditionally, so the vndcfg redirect did not necessarily bring the user back. It now stays put and reports the failure. Reported by Egil. Co-Authored-By: Claude Opus 5 (1M context) <[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.
Reported by Egil, who noticed it while documenting board types in the wiki.
The bug
handleSave()discarded the return value ofHwTools::applyBoardConfig(), leavingsuccesshardcoded totrue, soif(success)and bothsuccess ? … : …were dead branches:This regressed in 67e6a51 ("Force board profiles on boot"), which lifted the per-board
switchout ofhandleSave()intoapplyBoardConfig(). The original switch (from ab7128c) had adefault: success = false;arm, and the extraction dropped the wiring —applyBoardConfig()returnsbooland falls through toreturn falsefor an unknown board type, but the caller ignored it.Because
clearGpio()runs before the call, an unmatched board type persisted a wiped GPIO config together withvendorConfigured = true:apPin,ledPin,ledPinRed/Green/BlueandvccPinall stayed0xFF. The LED and AP button go dead, and with noapPinthe emergency factory reset is unreachable. The device is not bricked — the web UI still works and/vendorcan be used to pick the right type — but nothing pointed the user there.Via the GUI this is unlikely, since the select preselects the current board type and filters on chip. But the empty
<option value={-1}>is selected when the stored board type is not among that chip's options, the select has norequired, and the endpoint accepted any value from a hand-made POST.Fix
The profile is applied to a local
GpioConfig, and only copied into the live one on success — so a rejected board type leaves neither EEPROM nor the running configuration touched. (Without the local copy, a rejected POST would leave the in-memory GPIO config wiped forhw->setup(&sys, gpioConfig)at the end of the handler, even with EEPROM intact.)Three related issues along the same path
clear()discarded the HAN pin.clear()deliberately preservesboardTypeandvendorConfigured, but then calledclearMeter(), which resetsrxPin,txPinandrxPinPullup— the three fieldsapplyBoardConfig()sets, dictated by that same board type. Board profiles are only re-applied on boot forboardType < 20, so generic boards lost their HAN pin on every factory reset (button, web and MQTT) and whenever "Clear all other configuration" was used on the vendor page.clear()now carries those three pins across.Fixed centrally rather than by widening the
< 20guard insetup()— forcing profiles on boot for generic boards would stomp user GPIO customisations, which is what that guard exists to protect.getMeterConfig()does its own config-version check and returns cleared values on a virgin EEPROM, so first-boot behaviour is unchanged, and it never calls back intoclear(), so there is no recursion (unlikegetSystemConfig()). Note the setup branch atAmsWebServer.cpp:1139already hand-rolled this same save/restore around its ownclear()call; that is now redundant but left alone.Unsigned compare in the reset button guard.
setup()testedif(gpioConfig.apPin >= 0), always true for auint8_t. With no AP pin configured, boot spent five seconds walking a hold sequence that can never complete (the third check needs aHIGHread on an invalid pin), flashing green and red LEDs on the way. Now tests!= 0xFF, matching the two otherapPincall sites.Vendor page hid the rejection.
handleSubmitnavigated to/or/setupregardless ofres.success. SincegetSysinfo()is only re-polled under specific conditions, thevndcfg === falseredirect inApp.sveltewould not necessarily bring the user back until a reload. It now stays on the page and reports the failure. The string is hardcoded English to match the rest of this route, which has no translations — no Localazy change needed.Verification
All six environments build:
esp8266dev,esp32dev,esp32s2dev,esp32s3dev,esp32c3dev,esp32solodev.ui/distrebuilt (onlyindex.jschanged). esp8266 flash 98.1% → 98.2%, +128 bytes.pio test -e nativewas not run — nothing here touchessrc/decoder/.Left alone, worth a follow-up
AmsConfiguration.cpp:533has the identical unsigned compare insetGpioConfig()—if(config.apPin >= 0) pinMode(...). Harmless (invalid-pinpinModeis a no-op) but wrong for the same reason.VendorRoute.svelte:30readss.boardType, but the sysinfo field iss.board(as used everywhere else in that file), sos.if.ethis alwaysfalseafter a vendor save.vr=trueand a rejected board type still runsconfig->clear()at the end ofhandleSave(), wiping configuration while correctly reporting failure. Restructuring that is more invasive than this fix warrants — theclear()must stay last, since it writesEEPROM_CLEARED_INDICATORand must not be followed bysave()(see f1089fa).requires Node.js version 20.19+ or 22.12+). Built with v22.22.2.🤖 Generated with Claude Code