Wi-Fi
For networking to work on a device, it needs Wi-Fi. Kog handles this two ways: credentials baked in at flash time (the usual case: networking works with no Wi-Fi setup in your app), or connecting from code at runtime.
On the desktop simulator and web playground there's no radio, so WiFi is
always-connected emulation: fetch/WebSocket work and WiFi.status()
reports connected. You only think about Wi-Fi for real devices.
This playground runs the emulation, so WiFi.status() reports connected with a
synthetic IP (on a device it would reflect the real association):
The easy path: provision at flash time
Put your network in kog.config:
export default defineConfig({
network: {
wifi: {
ssid: 'my-network',
password: '${WIFI_PASSWORD}', // resolved from your environment
autoConnect: true, // start joining at boot, before your app runs
},
},
});
Then bake the credentials onto the board with the CLI:
WIFI_PASSWORD='hunter2' kog wifi
kog wifi writes the credentials to the kog_net namespace in the device's
nvs partition at flash time, not into your app bundle. With
autoConnect: true, the device starts joining the network at boot, before your
app runs. The join finishes in the background, so await WiFi.ready() before a
startup request that must not fail.
kog wifi --print-csv prints the Wi-Fi NVS entries without touching anything.
(The blob kog wifi flashes also sets dev_mode=1, and it replaces the board's
whole nvs partition.) kog wifi --ssid X --pass Y provisions without editing
the config.
Keep secrets out of git
Your Wi-Fi password is a secret; never commit it. Kog supports:
- Environment references:
password: '${WIFI_PASSWORD}'(orprocess.env.WIFI_PASSWORDin a TS/JS config) is resolved from your environment at provision time. The CLI doesn't read.envfiles itself: export the value in your shell, or load your gitignored.envinto the environment first. - A literal password in your config draws a warning every time you run
kog wifi.
New projects already .gitignore .env and *.local.
Connecting from code
Call WiFi.connect() at runtime for a setup screen, a network picker, or to
switch networks:
// Join the credentials you provisioned with `kog wifi`:
await WiFi.connect();
// Or join a specific network:
const conn = await WiFi.connect('guest-network', 'password');
console.log('got IP', conn.ip);
Pass { save: true } to persist the credentials, so the device auto-joins them
on the next boot (off by default, so a retry loop can't wear out the flash). On
a device the credentials are currently saved when the join starts, not after it
succeeds, so only save credentials you trust:
await WiFi.connect(ssid, password, { save: true });
Status and events
const status = WiFi.status(); // { state, ssid?, ip?, rssi?, mac? }
if (WiFi.isConnected) { /* ... */ }
await WiFi.ready(); // resolves when connected (doesn't reject on a failed join yet)
const off = WiFi.on('disconnect', (s) => showBanner('Wi-Fi lost'));
WiFi.scan() returns nearby networks on a device (a fixed synthetic list on the
sim/playground). A join failure rejects with a KogNetError with code
NET_WIFI. A wrong password isn't reported separately yet.
Provisioning from the browser flasher
The docs "Run on device" panel can flash a board over Web Serial, but it does
not provision Wi-Fi. To bake credentials from the browser, use
Kog Studio's Wi-Fi setup (also over USB), or use the CLI
(kog wifi).
See the API reference for the full WiFi surface,
and kog wifi for all the command's flags.