Skip to main content

chumicro-wifi

Wifi that auto-reconnects so your app code doesn't have to.

One WiFi service across CircuitPython (Adafruit boards) and MicroPython on both ESP32 and Pi Pico W. Owns the radio (no CIRCUITPY_WIFI_* settings, no firmware-level auto-reconnect competing with you), surfaces state transitions as events you can wire into the rest of your app via chumicro-runner, and reads its config section via chumicro-config. CircuitPython's substrate-level connect() is blocking. See Platform support for what that means in practice.


Part of the ChuMicro family: small, focused Python libraries for microcontrollers and laptops. Browse all libraries.

Install

# CircuitPython (after `circup bundle-add ChuMicro/ChuMicro-Bundle`)
circup install chumicro_wifi

# MicroPython
mpremote mip install github:ChuMicro/ChuMicro-Bundle/chumicro_wifi

# CPython
pip install chumicro-wifi

For bundle setup, pre-compiled .mpy bundles, the experimental channel, and details on PyPI naming, see the chumicro INSTALL guide.

Quick example

User-app pattern (the 4-line bring-up):

from chumicro_config import load_runtime_config
from chumicro_runner import Runner
from chumicro_wifi import WifiService

config = load_runtime_config()
runner = Runner()
wifi = WifiService.from_config(config)
runner.add(wifi)

State + IP introspection any time:

wifi.state          # "disconnected" | "connecting" | "connected" | "reconnecting" | "failed"
wifi.connected
wifi.ip
wifi.last_error
wifi.on_state_change(lambda old, new: print(f"{old} -> {new}"))

What's included

Symbol What it does
WifiConfig Typed connection settings (ssid, password, hostname, timeouts, reconnect tuning). from_config(config) reads the flat wifi.* keys; try_from_config(config) returns None when the section isn't deployed.
WifiService State machine + reconnect supervisor; implements Runner.add()-compatible check/handle. from_config(config, radio=None, ...) builds it straight from the flat wifi.* keys; extra keywords pass through to the constructor. Auto-detects the runtime adapter at construction time (the CpythonWifiAdapter host stand-in on CPython, CpWifiAdapter on CircuitPython, substrate-aware MpWifiAdapter on MicroPython, handling ESP-IDF + CYW43 transparently).
WifiState String-sentinel state names: DISCONNECTED, CONNECTING, CONNECTED, RECONNECTING, FAILED.
chumicro_wifi.testing.FakeWifi Drop-in WifiService wrapping a FakeWifiAdapter with set_connect_outcome, drop_link, calls hooks for downstream library tests.

Where this fits

Depends on chumicro-config for its config section and registers with chumicro-runner for its tick contract. Provides the radio the networking layers sit on top of: chumicro-sockets on CircuitPython, with the HTTP / MQTT / WebSocket / NTP libraries downstream of that.

Platform support

Works on CPython, MicroPython, and CircuitPython. Ships three runtime adapters: CircuitPython wifi.radio (_adapters/cp.py), MicroPython network.WLAN covering both ESP-IDF (ESP32 family) and CYW43 (Pi Pico W) stacks (_adapters/mp.py), and a CPython host stand-in that reports success immediately (_adapters/cpython.py); chumicro_wifi.testing.FakeWifiAdapter covers host-side tests. The right adapter is selected at runtime via sys.implementation.name; the MP adapter then auto-detects ESP-IDF vs CYW43 by matching sys.implementation._machine against a positive whitelist of known CYW43 boards.

CircuitPython connect is blocking (read this if you're shipping to CP)

CircuitPython's substrate-level wifi.radio.connect() is blocking. There is no non-blocking variant exposed by the firmware. While WifiService is CONNECTING or RECONNECTING on a CircuitPython board, handle() stalls for up to connect_timeout_ms (default 15 000 ms). Other services in the same Runner (your LED heartbeat, an HTTP request, an MQTT keep-alive) pause for that window. Once the state reaches CONNECTED, the loop runs at full speed again and stays there until the link drops.

MicroPython's wlan.connect() is genuinely non-blocking on both ESP32 and Pi Pico W substrates: association happens in the background and handle() returns immediately. If non-blocking connect is load-bearing for your app, prefer MicroPython on RP2040 / RP2350 or ESP32-family boards.

Examples

Example What it shows
connect_to_ap.py Connect to a real AP, print state transitions, observe IP, reading wifi.ssid / wifi.password from runtime_config.msgpack.

Wiring wifi credentials

The library never reads TOML itself: it takes a WifiConfig and connects. WifiService.from_config(config) is the construction path the standard pipeline uses, reading credentials from your project's runtime config under the wifi.* keys (wifi.ssid, wifi.password) through the same WifiConfig.from_config(config) loader that also works standalone. To get those credentials onto the device, deploy them as part of a workspace-based deploy or a raw single-file deploy. The bundled connect_to_ap.py example and the on-device acceptance test both read the credentials this way and skip silently when none are configured.

Contributing

Issues, bug reports, and pull requests are welcome, and so is "I ran it on this board and here's what happened", some of the most useful feedback a hardware project can get. Development happens in the ChuMicro repository, whose contributing guide covers setup and the test workflow.

Docs

📖 Stable docs · Experimental docs

Find this library

License

MIT

Metadata

Release files for chumicro-wifi 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chumicro-wifi 0.11.0
File Size Uploaded
chumicro_wifi-0.11.0.tar.gz 36.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chumicro-wifi 0.11.0
File Interpreter ABI Platform
chumicro_wifi-0.11.0-py3-none-any.whl Python 3 none any Details

Total release size: 53.2 kB

Release files / chumicro_wifi-0.11.0.tar.gz

Download URL chumicro_wifi-0.11.0.tar.gz
Size 36.9 kB
Tags Source
SHA-256 checksum
How to use checksums
59b78e3e5079d551e2d73a5917090485629c558a550b19e1a5190542c0b93413
BLAKE2b-256 checksum
How to use checksums
c9671b90c1bf20ccc5d7e8c72ea035ab5f5fc635bd58f4671619ae46be5dd16c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 17, 2026.

Transparency log

Release files / chumicro_wifi-0.11.0-py3-none-any.whl

Download URL chumicro_wifi-0.11.0-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f3438e5eeeaaae5536564ef99324fae9a98934e943aeaba88afecdfe86c877e
BLAKE2b-256 checksum
How to use checksums
063bcd4e69ae81e92b78c20bd11d55b0881f99b87b82d3399eb31f85455253fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 17, 2026.

Transparency log

Release history Release notifications | RSS feed

0.11.2

2 release files

0.11.1

2 release files

This release

0.11.0 This release

2 release files

0.8.2

2 release files

0.8.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page