Repository navigation
Conversation
|
Rebased onto #1041's current head. #1041 gained commit dd4c881 (a Disable ends a pending pick before the module confirms) after this PR was opened. The two commits here are unchanged apart from the rebase. The hardware run above already used both together, and host tests pass on the rebased branch. Written with Claude Opus 5.5 in Claude Code. |
|
@JC-000 Nice one! Thanks for this fix. It will take me a few days to review. |
|
@JC-000 Thank you for this PR, and for keeping the persistence part small and well covered by host tests. Result: changes requested. Reviewed head What I reviewed
Changes requested (this PR's own commits)
Please check
Suggestions
Not testedCold boot of the exact PR application on the C64 Ultimate, the Ultimate 64 Elite II, RF capture, Wake on WiFi with the new netif hooks, and recovery-button Autoconnect with a stored Disabled setting. One earlier persistence attempt left the C64 Ultimate off after the outlet was restored; a second outlet cycle started it. I did not find the cause and do not attribute it to this PR. |
| if (netstack->enabled_in_config()) { | ||
| wifi_enable(); | ||
| } else { | ||
| wifi_disable(); |
There was a problem hiding this comment.
@JC-000 Thank you for this PR. My review is in two parts: inline comments on the lines concerned, and one summary comment. Everything from #1041's commits that is in this PR applies here as well; those comments are on #1041 and I have not repeated them. Required change for #1042:
At boot the Ultimate pushes its stored setting to the control module (wifi_enable() or wifi_disable()). This is what repairs a module whose NVS disagrees with the setting (module swap, failed NVS write). The result is ignored. If wifi_disable() cannot be sent or the module rejects the enqueue, there is no confirmation deadline on U64 == 2, because RadioOff and its retry are U64 != 2 only. Initialisation continues, wifi_is_connected reports the module as connected and the Connected event is accepted. The application shows WiFi Enabled = Disabled while the radio stays associated, with no retry and no message.
Host reproduction (U64=2, stored Disabled, the module answers the disable with an error, link up, then a Connected event): fails with "failed stored-Disabled push must be retried" and "stored Disabled must not accept connected module after failed push". It needs a failed command plus a setting/module mismatch. A normal boot is not affected.
Change: check the return value. On failure retry a bounded number of times, and otherwise leave a visible failure state. Do not treat a Connected event as success while a Disable push is unconfirmed.
| switch(cmd->command) { | ||
| case CMD_WIFI_DISABLE: | ||
| // The setting is kept first: it is what the next boot goes by, whatever the radio does now | ||
| power_set_wifi_enabled(0); |
There was a problem hiding this comment.
Required change (also the Enable branch further down).
The result of power_set_wifi_enabled() is ignored. write_u8 logs a failure, but the code continues: the radio goes off, EVENT_DISABLED is sent, and the stored value stays Enabled. After the next mains-out the radio starts at boot (wifi_start_at_boot) until the Ultimate pushes its setting. The window is short because the Ultimate pushes its setting when it detects the module, but see my comment on wifi.cc line 313: that push can fail as well. Neither the power_state host test stub nor module_persist_test.cpp has a failing-write case, so this path is not tested.
Change: keep the result. On failure retry from the connector (for example at its next wake) and log it once. Add a host test with a failing write that asserts the radio state and the retry.
… mains-out On U64 == 2 the menu's Enable and Disable were actions with no stored state, and the module's off state lived in RAM only, so a Disabled unit started its radio at every mains-in. WiFi Enabled is now the same stored setting as on the Ultimate 64 (the one switch, NetworkLWIP_WiFi::set_enabled), which replaces the two actions. u64ctrl keeps a copy in its NVS and reads it before it starts the radio; the Ultimate passes its setting when it finds the module, and that wins. Recovery's Autoconnect still starts the radio and leaves the copy alone. u64ctrl's identity is bumped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Record the netif's input and output slots when the radio first starts (a Disabled boot has no netif yet, so a later Enable and a machine-off wrote NULL into the netif); a Disable during a recovery only stores the copy; tests for wifi_init's use of wifi_start_at_boot, the netif slots, the recovery case and the stored copy's defaults in power_state.c. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd confirm a radio off On U64 == 2 the module was told the stored setting at its detection, with the answer ignored, and nothing waited for the radio off: after a rejected or lost Disable the module's Connected was taken, and the row showed Disabled while the radio stayed associated. A change of the setting between that read and the request could also leave the radio opposite to the setting. The Elite II and C64 Ultimate now take the path of the U64 and U2+L (GideonZ#1041): the WiFi task applies the setting when it has found the module and on every change (EVENT_RADIO_SETTING), drops the module's link events until EVENT_DISABLED confirms a radio off, asks again at the deadlines, holds the link down when the asks run out, and asks again for a radio on that failed. The push at detection and CFG_WIFI_ENA/DIS are gone. The control module is never held off. u64ctrl answers a Disable during a recovery with ESP_ERR_INVALID_STATE (the radio stays on for the download, the setting is stored); the Ultimate then waits for nothing, says nothing, and the link follows the module, also when the refusal comes at a later ask. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
u64ctrl ignored the result of power_set_wifi_enabled(): with a failed NVS write the radio went off and EVENT_DISABLED was sent while the stored value stayed Enabled, so the radio came up again at the next boot (and the same for an Enable). The value whose write failed is now kept (store_pending) and written again while the connector idles: at once, then every 2 s, up to 5 writes in all, with one warning. The idle waits that have no bound (Connected, Disabled, a user Disconnect) are bounded while a write is due. A newer Enable or Disable replaces the pending value. A comment in enable_wifi_if_needed says why a recovery's Autoconnect leaves the radio on with Disabled stored. Host tests: a failing write in power_state_test.c (the NVS stub can fail nvs_set_u8) and in module_persist_test.cpp. u64ctrl's identity notes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… C64 Ultimate Wake on Wi-Fi listens on the station interface, which a radio that is off does not have. With a Disable that now survives a power cycle, a user with Wake on Wi-Fi on and WiFi Disabled had a wake that never came, and nothing said so. Setting Wake On Wi-Fi while WiFi is Disabled, and disabling WiFi while Wake On Wi-Fi is on, now post "Wake on Wi-Fi needs WiFi enabled". Neither is refused: the setting is kept and works once WiFi is enabled again. The settings are documented outside this repository, so there is no doc line here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…start The control module's Enable and enable_wifi_if_needed() sent EVENT_DISCONNECTED and then cleared disabled_g. The dispatcher answers the Ultimate's connection query on its own task, at a higher priority (wifi_send_connected_event): a query that landed in between sent EVENT_DISABLED after the start's EVENT_DISCONNECTED, and the Ultimate ended in Disabled with the radio on and the setting Enabled. The WiFi task asks for the connection state a few ms after its boot Enable, so the window was reachable. The flag is now cleared first. raw_u64 and raw_c3 clear it first already, and answer the query from their connector, in order with the Enable. Host test: an Enable and an Autoconnect from a stored Disabled send no EVENT_DISCONNECTED while disabled_g is set (red 17 models the old order). u64ctrl's identity notes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…asked again Only the boot's refusal (a recovery runs) had a host test: the handling of a refused Disable from the menu or the REST API, and of a refusal at a later ask, could be removed with every case still passing. Two U64 == 2 cases now cover them: a runtime Disable refused waits for nothing, says nothing and keeps the link; a radio off queued and then refused when asked again ends the wait after one deadline, without a message, and the link follows the module. legacy/fix23 and fix24 model the two without their refusal handling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er a failed Enable Every failing-write case failed once, so the retry at the top of the connector's next pass always stored the value, and the 2 s bounded waits (Connected and Disabled) could be removed with the suite still passing. The new case lets the write fail twice and three times, in Disabled and in Connected, and requires the copy to be stored after the bounded waits (red 16b and 16c model each wait without its bound). The pending-write case also runs the other way round: a stored Disable, an Enable whose write fails, then a Disable, which wins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… settings The notice "Wake on Wi-Fi needs WiFi enabled" came from the change hook of "WiFi Enabled" only, which a reset or load of the settings does not run: a loaded Disabled with Wake on Wi-Fi on stopped the wake without a word. The effectuate that applies such a change now tells it too, when the WiFi task had applied Enabled and no change waits for it, so neither at boot nor a second time for a change whose hook told already. Host test (U64 == 2), and legacy/fix25 models the effectuate without it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the setting is stored The help under Power Settings now says that Wake On Wi-Fi needs WiFi Enabled. setWakeOnWifi posted that notice before it wrote the setting to the control module, so a failed write showed it and then "Wake on Wi-Fi not stored."; the notice now follows a write that worked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t be read power_set_wifi_enabled() returned early when power_get_wifi_enabled() read the value it was to write. A read error gives the default, Enabled, so an Enable then wrote nothing over a stored Disabled, and the radio stayed off at the next boot. write_u8() compares with what is stored itself and writes only a change, so the early return goes, and with it the log line of a change and the "not read" line that every push printed on a module that never stored the setting. The NVS stub can fail a read; power_state_test.c covers the case. u64ctrl's identity notes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Patterns of both no longer matched the code once the Elite II / C64 Ultimate took the radio requests into the WiFi task: fix7's boot-push lines (and its wifi_disable() line, which hit only the U64 restart path) matched nothing, so its model still told the module the setting at detection; fix1's radio-off test at the start, its boot radio on, and its RadioOff and RadioOn of the menu matched nothing either. Both now take the boot's radio off and radio on out, and fix1 stops and starts the application for Disable and Enable again. Both still fail, as required. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for the review. This PR is rebased onto #1041's new head, The commit messages were cleaned, so the PR is force-pushed. The two commits you reviewed are now At
Every legacy model fails, as it must. In the test column, run and model mean the same as in my reply on #1041, with RED taken against Changes requested1. The stored-Disabled push at boot (
Tests (all are models):
2. A failed NVS write (
Tests:
Please check3. The window at module detection. It is closed by the same task path. Test, models fix10 and fix7: 4. Wake on Wi-Fi with Disabled stored ( We tell the user rather than refuse: the setting is kept and works once WiFi is enabled again. "Wake on Wi-Fi needs WiFi enabled" is shown in three cases:
The help under Power Settings now reads "It needs WiFi Enabled (WiFi settings)." ( Tests:
Suggestions
Also changedu64ctrl clears its Disabled flag before the event of a radio start ( Test, model LEGACY_17: Hardware (C64 Ultimate)Setup. The image carried this PR as it stood before #1041's last two changes (frames off after the give-up, and the actions that ask while a radio off waits). The rest of the tree is the same as Method. "Silent" is measured with a Wi-Fi sniffer on the AP's channel (seconds in which the device's MAC sent or received anything) and a ping of the WiFi address.
Mains-out: 3/3. Not run on hardware. The third notice case (a load of a stored Disabled with Wake on Wi-Fi on) stays host-tested ( Observation, not a change. With Enabled stored, the control module stays associated while the machine is off, which is what Wake on Wi-Fi needs. With Disabled stored, it sent nothing while off. Module version. The u64ctrl version is now above every work-in-progress build, including the one from this PR's first version on your C64 Ultimate, so the updater installs it. The Written with Claude Opus 5.5 in Claude Code. |
Conflicts: took master's deletion of the nine legacy/*.sed models GideonZ#1042 had modified; software/wifi/tests/Makefile keeps master's structure (no legacy/red targets) plus GideonZ#1042's additions (FUNCS_MODEM entries, WIFI_STORE_ extraction, wifi_init check). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chrisgleissner
left a comment
There was a problem hiding this comment.
@JC-000 thanks for this. I checked the behaviour against the source: an old config has no CFG_WIFI_ENABLE, so it loads as Enabled and an upgrade does not turn WiFi off. Only u64ctrl changes, so the U64, U2+ and U2+L are unaffected. The host tests extract the production functions, and they fail when I make boot ignore the stored copy or make set_enabled skip the save.
Requesting changes on three points:
- Hardware at head. The hardware run in the description is a work-in-progress build and the Elite II was not tested. Please run the head on the Elite II and the C64 Ultimate: set Disable, power cycle, confirm the radio stays off from power-on; set Enable, power cycle, confirm it comes up without user action.
- Scope. The Wake on Wi-Fi notices and help text (commits 3d07467, 4587750, 22b783f, in
u64_config.cc,u64_config.handwifi.h) are not needed for #589. Please move them to their own PR. - Module restart while Disabled. On the Elite II, in the remaining
#if U64 != 2block ofwifi.cc, a module that restarts on its own is not re-synchronised, so with a stale copy the radio can come back on while the setting is Disabled until the next boot. Please fix it or list it with the other caveats.
They are not needed for GideonZ#589. They go to their own PR. This reverts 3d07467, 4587750 and 22b783f. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…tarts, and act on it A control module that restarted on its own (a crash, a watchdog, a brownout) read its own copy of WiFi Enabled and, if that was stale Enabled, started the radio while the Ultimate's setting was Disabled. Nothing told the Ultimate, so the radio stayed on until the next boot: the EVENT_RESTARTED handling in wifi.cc was U64 != 2 only. The control module now sends EVENT_RESTARTED before any link event when it starts its radio after a restart of its own, and the Ultimate handles it on every product: while Disabled it asks for the radio off again and drops the link events until that is confirmed. The connector now starts once the UART is on its pins, so that the event is not lost. The module's identity is 1.35, above every open work-in-progress change. Host tests: Persist.a_restart_of_its_own_with_the_radio_started_tells_the_ultimate and a_restart_of_its_own_with_the_radio_off_tells_nothing (module); the two EVENT_RESTARTED cases of switch_task_test.cpp now run for U64=2 as well. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…WiFi task is in After an Enable the task's state stays Disabled until the module's radio events arrive. A restart event that came in that gap was answered with a radio off, although the setting said Enabled. The handler now asks for the radio off only while the setting is Disabled. Host test WifiSwitchTask.module_restarted_while_an_enable_is_on_its_way fails without the change (a radio off follows the Enable) and passes with it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Thanks for the review. Where each point stands: 1. Hardware at head. Run on a C64 Ultimate. I have no Elite II, so it was not tested there. The C64 Ultimate's own software "Power Cycle" only switches the main regulators; the control module stays powered and
The silent measure only counts because the same sniffer saw the unit's traffic in the Enabled legs (positive control). The build was flashed through the updater with the configuration reset; it was built from the PR branch as it was before the 2. Scope. The three Wake on Wi-Fi commits are reverted on this branch in one new commit (no history rewrite). They will 3. Module restart while Disabled. Fixed in code, but only host-tested: a mains-out never makes the module restart on its own, and I did not
Your 5 November comments.
Written with Claude Opus and Claude Sonnet in Claude Code. |
|
Thanks, scope is now clean and the restart handling is in. Remaining before approval: (1) the hardware rows ran the build before the last commit, which changes the EVENT_RESTARTED handler; please repeat the Disable and Enable mains-out legs on the head. (2) The Elite II has no hardware result; if nobody has one, please say so in the description. (3) The restart path has no hardware row, only host tests; please list that with the other caveats. This is a larger change than the other WiFi fixes, so it should go after #1041 and the small items. |
|
Thanks. I added the missing caveats to the description: there is no Elite II result (I only have a C64 Ultimate and an Elite I), and the restart path has host tests only. I will repeat the Disable and Enable mains-out legs on the head and post the rows here. Understood on ordering: this goes after #1041 and the small items. Written with Claude Opus and Claude Sonnet in Claude Code. |
|
I repeated the C64 Ultimate Disable and Enable mains-out legs on the current head (b93a12d), built with #835 and a bench-only updater that forces the module flash.
The rows are added to the hardware table in the description. Written with Claude Opus and Claude Sonnet in Claude Code. |
Makes "Disable" stick on the Elite II / C64 Ultimate. A WiFi Disable now survives a power cycle, so a disabled unit no longer starts its radio at mains-in. Fixes #589.
This PR was stacked on #1041, which is merged. The diff is the commits on top of it (
6cfdc7b36..b93a12d34).Summary
NetworkLWIP_WiFi::set_enabled()from WiFi: Disable turns the radio off, plus the connect and AP-list fixes from #1031 #1041. It sets the item, its change hook turns the radio on or off, and it saves only when the value changed.The default is Enabled, so nothing changes for a unit that never used Disable. No new RPC. The Wake on Wi-Fi notices that were part of the first version of this PR will be in their own PR.
Why
#589 reports that Disable is not persisted on the C64 Ultimate, and the maintainer agreed it is a bug. The off state lived only in the module's RAM, and the Ultimate had nothing stored. So after a mains cycle the module associated on its own while the Ultimate was still starting.
#1041 gave the U64 and U2+L one switch with a stored setting. The Elite II / C64 Ultimate module already had the radio switch, but not the storage. This change gives it the same setting, kept where it is needed before the Ultimate runs. The plan was discussed on #589.
Alternatives considered
{enabled, stored, write_failed}), so that the Ultimate could detect a mismatch. Not needed: the Ultimate applies its value once it has found the module and waits for the confirmation, and the commands are idempotent. A query would add an RPC number and a handler in the module for no decision that the confirmed request does not already make.set_enabled()covers every call, so the actions,cfg_enable/cfg_disable, and their item numbers CFG_WIFI_ENA / CFG_WIFI_DIS are removed.Technical details, per commit
No line endings were changed:
git diff --statequalsgit diff --ignore-cr-at-eol --statfor every commit.network_esp32.cc/.h,wifi.cc). The Elite II row becomes the U64's:CFG_WIFI_ENABLE, "WiFi Enabled", Enabled by default. Its change hook andset_enabled()are no longer U64 != 2 only.u64ctrl/main).power_get_wifi_enabled()/power_set_wifi_enabled()keep the setting under the NVS key "wifion", next to the Wake on Wi-Fi key.wifi_start_at_boot()replaces theesp_wifi_start()inwifi_init(). With the copy at Disabled, it leaves the radio stopped and setsdisabled_g.connector_boot_state()starts the connector inDisabledin that case, otherwise inLastAP.CMD_WIFI_DISABLEstores 0 first. When the radio is off already, it confirms (EVENT_DISABLED) without stopping it again.CMD_WIFI_ENABLEstores 1, then starts the radio if Disabled.enable_wifi_if_needed(), the Autoconnect path that recovery uses, does not touch the copy.store_pending) and written again: at once and then every 2 s while Disabled or idle without a timeout, otherwise at the reconnect pace; up to 5 writes, with one warning. The idle waits are bounded while a write is due. A newer request replaces the pending value. A comment inenable_wifi_if_neededsays why a recovery's Autoconnect leaves the radio on with Disabled stored.U64Config::setWakeOnWifi.setup_modem()maps the reset reason (panic, watchdog, brownout) toself_restart_g.connector_boot_state()sends EVENT_RESTARTED before any link event when it starts the radio after such a restart. After a power-up, or with the radio left off, it sends nothing. The connector now starts once the UART is on its pins, so that the event is not lost.wifi.cc). The EVENT_RESTARTED case is no longer U64 != 2 only. While Disabled it asks for the radio off again and drops the link events until that is confirmed, as at boot.module_persist_test.cpp, and the two EVENT_RESTARTED cases ofswitch_task_test.cppnow also run for U64 == 2.WifiSwitchTask.module_restarted_while_an_enable_is_on_its_wayfails without the change and passes with it.Identity. u64ctrl's IDENT_STRING and IDENT_MINOR are bumped together, with a changelog line. The number is a placeholder for the maintainer. raw_u64 and raw_c3 are not touched beyond #1041.
Tests
Host tests
At this head (
b93a12d34), every host test directory passes, run one by one on macOS and in an Ubuntu 24.04 container. Each suite has failing-before models (-red).module_persist_test.cpppersist_task_test.cpp,disabled_task_test.cpplegacy/fix7persist_task_test.cpp,switch_task_test.cppmodule_persist_test.cpp;switch_task_test.cppwifi_init()starts the radio only throughwifi_start_at_boot().Counts:
Every model fails as required: 69 task-side and 50 module-side runs.
As in #1041, the
-redtargets run against a sed model of the code before the change, not against master, because the suites cut functions out of files that only exist in the new form.Firmware builds
These all built with no errors at 98c347c: u64ii (with the u64ctrl blob), u64, raw_c3, and the U2+L and U2+ applications. For the hardware runs below the C64 Ultimate image was built at bf7e862; CI builds every product at the current head.
Hardware
All on a C64 Ultimate on 2026-11-10 and 2026-11-11, times in UTC.
C64 Ultimate only. The Elite II was not tested. A Wi-Fi sniffer on the AP's channel counted the seconds in which the unit sent or received anything, and a ping of its WiFi address and a read of the setting and the WiFi row ran alongside. The C64 Ultimate's own software "Power Cycle" only switches the main regulators and the control module stays powered, so each leg uses a real mains-out: software power-off (
PUT /v1/machine:poweroff), the mains plug out and back in, power on with the toggle. The sniffer's silence only counts because it saw the unit's traffic in the Enabled leg.584250385, no stored copy)bf7e862fdbf7e862fdb93a12d34+ #835b93a12d34+ #835The images were flashed through the updater with the configuration reset (the head image with a bench-only updater that forces the module flash). The module's version on the row read as the new one after the update and as the old one before it.
Host tests only, no hardware row:
54731c25d). A mains-out never makes the module restart on its own, and no crash, watchdog or brownout was induced. Insetup_modem()the new start order (connector after the pin switch) and the mapping of the reset reason to "restarted on its own" have no host test either.b93a12d34). It is in the 2026-11-11 image, but a mains-out does not exercise it.Not tested on hardware: the Elite II.
Caveats
Not tested on hardware
EVENT_RESTARTEDrestart path: host tests only, because a mains-out never restarts the module by itself.setup_modem()and the reset-reason mapping have no host test either.Written with Claude Opus 5.5 in Claude Code.