Network

Needs a radio: Pico W, ESP32, ESP8266, or an nRF board for BLE. The Pico W emulator models the CYW43 path; full AP scans still want real hardware.

Network

Wi-Fi

import network, time

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect('ssid', 'password')
for _ in range(40):
    if wlan.isconnected():
        break
    time.sleep(0.25)
print(wlan.ifconfig())

Sockets

import socket

addr = socket.getaddrinfo('example.com', 80)[0][-1]
s = socket.socket()
s.connect(addr)
s.send(b'GET / HTTP/1.0
Host: example.com

')
print(s.read(200))
s.close()

HTTP

urequests / requests from micropython-lib wraps the same sockets. Install with mip when you have a network.

import requests
print(requests.get('http://httpbin.org/ip').json())

MQTT

Use umqtt.simple or mqtt_as from micropython-lib / awesome-micropython. Typical pattern: connect Wi-Fi, then connect a broker, then publish readings.

# pip-style: mpremote mip install umqtt.simple
from umqtt.simple import MQTTClient

c = MQTTClient('pico', 'broker.local')
c.connect()
c.publish(b'sensor/temp', b'21.5')
c.disconnect()

WebREPL

Wireless REPL on ports that include it. Enable once over USB:

import webrepl_setup  # follow the prompts, then reboot

Then open the WebREPL client and connect to the board’s IP. Treat it as a LAN tool, not something to expose to the internet.

Bluetooth

On ESP32 and nRF, bluetooth.BLE is the low-level API. aioble is the asyncio wrapper most new code should use. See the official bluetooth and aioble docs.