From 00dda11564b5f35fc77346189dc9b9a7a9c39528 Mon Sep 17 00:00:00 2001 From: Adam Shiervani Date: Fri, 4 Dec 2026 10:20:44 +0100 Subject: [PATCH 1/2] Keep the route to the internet after a Wi-Fi band change or hotspot mode A stop of the Wi-Fi radio removes the station from lwIP, which clears lwIP's default interface. ESP-IDF does not set a default interface chosen by hand again when the station starts, so the Mini reached only its own subnet until the next restart. The station is now made the default interface at each connect. --- components/jetkvm_c5_wifi/jetkvm_c5_wifi.c | 9 +++ .../tests/wifi_radio_restart.test.mjs | 77 +++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 tools/integration/tests/wifi_radio_restart.test.mjs diff --git a/components/jetkvm_c5_wifi/jetkvm_c5_wifi.c b/components/jetkvm_c5_wifi/jetkvm_c5_wifi.c index d50b4abc..796dc414 100644 --- a/components/jetkvm_c5_wifi/jetkvm_c5_wifi.c +++ b/components/jetkvm_c5_wifi/jetkvm_c5_wifi.c @@ -1333,6 +1333,15 @@ static void c5_wifi_event_handler(void *argument, esp_event_base_t event_base, } if (event_id == WIFI_EVENT_STA_CONNECTED) { __atomic_store_n(&s_station_associated, true, __ATOMIC_RELEASE); + /* A radio stop (a band switch, hotspot mode) removes the station + * from lwIP, which clears lwIP's default interface, and IDF does + * not set a default chosen by hand again at the next start. + * Without one, lwIP has no route off the local network. */ + const esp_err_t default_error = esp_netif_set_default_netif(s_station); + if (default_error != ESP_OK) { + ESP_LOGE(TAG, "Wi-Fi station is not the default interface: %s", + esp_err_to_name(default_error)); + } /* The station interface starts with lwIP's own choice for IPv6; * the ipv6_mode setting decides from here on. */ jetkvm_network_settings_link_up(); diff --git a/tools/integration/tests/wifi_radio_restart.test.mjs b/tools/integration/tests/wifi_radio_restart.test.mjs new file mode 100644 index 00000000..b2b8c3e9 --- /dev/null +++ b/tools/integration/tests/wifi_radio_restart.test.mjs @@ -0,0 +1,77 @@ +import assert from 'node:assert/strict'; +import path from 'node:path'; +import { test } from 'node:test'; +import { fileURLToPath } from 'node:url'; +import { benchFile, readBench } from '../../combined_load/runner/build.mjs'; +import { connect, until } from '../lib/mini.mjs'; + +const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..', '..'); +const bench = readBench(benchFile(root, process.env.INTEGRATION_BENCH ?? '')); +const skip = bench.JETKVM_SKU === 'jetkvm-mini-wireless' ? false : 'the Mini has no Wi-Fi'; +const PRODUCTION = 'https://api.jetkvm.com'; +const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); + +// The Mini leaves its network for the band change: the page's session ends. +// The Wi-Fi settings once the change is done and the Mini is back online. +async function backOnline(mini, seconds) { + await sleep(5000); + return until(async () => { + await mini.open(); + return mini.rpc('getWifiSettings'); + }, settings => !settings.applying && settings.connected, seconds); +} + +// Right after a join the Mini's other TLS clients connect again and can hold +// the TLS memory that a check needs. A Mini without a route to the server +// does not get one in the wait. +async function reachesProduction(mini, when) { + try { + await until(() => mini.rpc('getUpdateStatus', {}, 30_000), status => Boolean(status.remote?.systemVersion), 30); + } catch (error) { + assert.fail(`the Mini does not reach ${PRODUCTION} ${when}: ${error.message}`); + } +} + +// A stop of the Wi-Fi radio takes the station out of lwIP, and with it lwIP's +// default interface. The Mini then still reaches its own subnet but no +// address beyond it, so the update server is the one on the internet. Each +// band change stops the radio, also a change to the band that the Mini is on, +// which keeps the bench's network. +test('the Mini reaches the update server on the internet after a Wi-Fi band change restarts its radio', { timeout: 300_000, skip }, async t => { + const online = await fetch(`${PRODUCTION}/releases?deviceId=jetkvm-integration&sku=${bench.JETKVM_SKU}`, + { signal: AbortSignal.timeout(30_000) }).then(response => response.ok, () => false); + if (!online) { + t.skip(`needs the internet: this machine does not reach ${PRODUCTION}`); + return; + } + const mini = await connect(); + // The band as found, once the test may change it. + let original = null; + t.after(async () => { + try { + const settings = original && await backOnline(mini, 240); + if (settings && settings.band !== original) { + await mini.rpc('setWifiBand', { band: original }); + await backOnline(mini, 240); + } + } finally { + await mini.close(); + } + }); + await mini.rpc('setUpdateApiUrl', { url: PRODUCTION }); + await mini.rpc('setDevChannelState', { enabled: false }); + const before = await mini.rpc('getWifiSettings'); + assert.ok(before.connected && before.channel > 0, `the Mini is on a Wi-Fi network: ${JSON.stringify(before)}`); + await reachesProduction(mini, 'before the band change'); + + const band = before.band === 'auto' ? (before.channel > 14 ? '5ghz' : '2.4ghz') : 'auto'; + original = before.band; + const changedAt = Date.now(); + await mini.rpc('setWifiBand', { band }); + const after = await backOnline(mini, 240); + t.diagnostic(`band ${before.band} to ${band} on channel ${before.channel}; back on ${after.ssid}, channel ${after.channel}, ` + + `after ${Math.round((Date.now() - changedAt) / 1000)} s`); + assert.equal(after.apply_failed, false, 'the band change succeeded'); + assert.equal(after.band, band); + await reachesProduction(mini, 'after the band change'); +}); From 3fe66c90faabaffe5f2d3573f35294683a30b90e Mon Sep 17 00:00:00 2001 From: Adam Shiervani Date: Fri, 4 Dec 2026 10:29:20 +0100 Subject: [PATCH 2/2] Remove two comments that narrate the radio restart test --- tools/integration/tests/wifi_radio_restart.test.mjs | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/integration/tests/wifi_radio_restart.test.mjs b/tools/integration/tests/wifi_radio_restart.test.mjs index b2b8c3e9..53bffea3 100644 --- a/tools/integration/tests/wifi_radio_restart.test.mjs +++ b/tools/integration/tests/wifi_radio_restart.test.mjs @@ -12,7 +12,6 @@ const PRODUCTION = 'https://api.jetkvm.com'; const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); // The Mini leaves its network for the band change: the page's session ends. -// The Wi-Fi settings once the change is done and the Mini is back online. async function backOnline(mini, seconds) { await sleep(5000); return until(async () => { @@ -45,7 +44,6 @@ test('the Mini reaches the update server on the internet after a Wi-Fi band chan return; } const mini = await connect(); - // The band as found, once the test may change it. let original = null; t.after(async () => { try {