From f96d239a1d1cb7dd8102effb1134010c2492ac4c Mon Sep 17 00:00:00 2001 From: David Montero Crespo Date: Mon, 10 Aug 2026 21:52:24 +0200 Subject: [PATCH] fix(micropython): route unknown SSIDs to the emulated AP instead of hanging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to the #262 fix. Handing MicroPython the real driver exposed a population the stub had been quietly carrying: sketches that connect to an SSID that simply does not exist in the emulated radio. The AP tables (QEMU esp32_wifi_ap.c and the esp32*js engines — same four networks in both) associate by MAC/channel, so an unknown SSID scans to nothing and `while not isconnected():` spins forever. Most 100-days gallery examples ship their author's home SSID, so "real driver, no shim" would have frozen them on the connect loop. So when a NIC is attached the prelude now injects a thin proxy around the REAL network module: connect() to any SSID outside the emulated set is redirected to Velxio-GUEST (announced on serial, so nobody debugs a connection they didn't make); known SSIDs pass through untouched; every other attribute delegates to the native module. Result: made-up-SSID sketches get genuine DHCP/DNS/TCP through SLIRP instead of the old fake answers, and the reporter's PICSimLabWifi repro is never rewritten. Wrapper semantics (rewrite, passthrough, module-attr delegation, and the `from network import WLAN` form) are exercised against an instrumented fake module; both generated preludes are syntax-checked. --- frontend/src/store/useSimulatorStore.ts | 36 ++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/frontend/src/store/useSimulatorStore.ts b/frontend/src/store/useSimulatorStore.ts index ed091ccf..b84879a2 100644 --- a/frontend/src/store/useSimulatorStore.ts +++ b/frontend/src/store/useSimulatorStore.ts @@ -2015,7 +2015,41 @@ export const useSimulatorStore = create((set, get) => { // useful data instead of "API Error". const now = new Date(); const fakeWeatherCity = 'Simulator City'; - const networkStub = wifiOn ? [] : [ + // With a NIC attached: the REAL driver, behind a thin proxy that + // rewrites unknown SSIDs to the emulated AP. The emulated radio + // (QEMU esp32_wifi_ap.c and the esp32*js engines both) announces + // exactly four networks; a sketch that connects to its author's + // home SSID would scan, find nothing, and busy-wait on + // isconnected() forever — which is what every gallery example + // that ships a made-up SSID would do. Redirecting to + // Velxio-GUEST keeps those sketches on the REAL stack (DHCP on + // 192.168.4.x, DNS, outbound TCP through SLIRP) instead of + // reviving the fake stub for them. Known SSIDs pass through + // untouched, and the rewrite is announced on serial so nobody + // debugs a connection they didn't make. + const networkStub = wifiOn ? [ + 'import network as _vlx_net', + '_VLX_SSIDS = ("Velxio-GUEST", "PICSimLabWifi", "Espressif", "MasseyWifi")', + 'class _VlxWLAN:', + ' def __init__(self, *a, **k):', + ' self._w = _vlx_net.WLAN(*a, **k)', + ' def connect(self, ssid=None, key=None, **kw):', + ' if ssid is not None and ssid not in _VLX_SSIDS:', + ' print("[velxio] SSID %r is not part of the emulated network; connecting to \'Velxio-GUEST\' instead" % ssid)', + ' ssid, key = "Velxio-GUEST", ""', + ' if ssid is None:', + ' return self._w.connect()', + ' return self._w.connect(ssid, key, **kw)', + ' def __getattr__(self, n):', + ' return getattr(self._w, n)', + 'class _VlxNetwork:', + ' STA_IF = _vlx_net.STA_IF', + ' AP_IF = _vlx_net.AP_IF', + ' WLAN = _VlxWLAN', + ' def __getattr__(self, n):', + ' return getattr(_vlx_net, n)', + 'sys.modules["network"] = _VlxNetwork()', + ] : [ 'class _StubWLAN:', ' def __init__(self, *a, **k):', ' self._calls = 0',