Tutorial: Wi-Fi 6 iTWT, NimBLE Coded PHY, ESP-NOW & IEEE 802.15.4
All 30 PylotOS boards share a 2.4 GHz RF front-end managed by ESP-IDF's hardware/software coexistence arbiter (esp_coex). On ESP32-C6 boards (m5stack_nanoc6, waveshare_esp32c6_lcd_147, seeed_xiao_esp32c6, waveshare_esp32c6_zero, generic_esp32c6), three distinct 2.4 GHz radios coexist: Wi-Fi 6 (802.11ax), NimBLE BLE 5.3, and IEEE 802.15.4 (Thread / Zigbee / Matter).
1. hal.net — Coexistence Priority & Wi-Fi 6 Target Wake Time (iTWT)
hal.net is owned by the OS (HAL_OWNER_OS), ensuring Core 0 :80/:443 Web UI, :8266 JSON-RPC/MCP, and Asymmetric OTA remain uninterrupted while allowing apps to tune power/latency balance:
import hal
# Prioritize throughput ("wifi"), low-jitter GATT ("ble"), or balanced time-slicing ("balance"):
hal.net.coex("balance")
# On ESP32-C6 connected to a Wi-Fi 6 AP, negotiate Individual Target Wake Time (iTWT):
hal.net.twt(True, wake_interval_ms=2000, min_wake_ms=12)
print(hal.net.status())
2. hal.ble — NimBLE 5.0 / 5.3 Long-Range Coded PHY
On ESP32-S3, ESP32-C3, and ESP32-C6, enable LE Coded PHY (S=8, 125 kbps forward error correction) for up to 4× outdoor BLE range:
import hal
hal.ble.coded_phy(True, s8_long_range=True)
print(hal.ble.status()) # {'stack': 'nimble', 'enabled': True, 'coded_phy': True}
3. hal.espnow — Routerless Zero-Copy Peer Mesh
ESP-NOW transmits up to 250 B connectionless 2.4 GHz action frames directly between MAC addresses (broadcast ff:ff:ff:ff:ff:ff or AES-128-CCM LMK-encrypted unicast peers):
import hal
from pylotos import wireless
BROADCAST = b"\xff\xff\xff\xff\xff\xff"
hal.espnow.open()
hal.espnow.add_peer(BROADCAST, channel=0)
hal.espnow.send(BROADCAST, b"swarm-heartbeat")
buf = bytearray(250)
meta = {}
n = await wireless.recv_espnow_into(buf, meta=meta, timeout_ms=500)
if n > 0:
print("From:", meta.get("src"), "RSSI:", meta.get("rssi"), "Payload:", bytes(buf[:n]))
4. hal.ieee802154 — Raw 802.15.4, Thread & Zigbee on ESP32-C6
Build ESP32-C6 firmware with --wireless-profile 802154 (or thread / zigbee) to activate the native IEEE 802.15.4 transceiver on channels 11..26:
import hal
hal.ieee802154.open(channel=15, pan_id=0x1234, short_addr=0x0001)
hal.ieee802154.send(frame_bytes)
Preview both 2.4 GHz apps locally:
pylotos-sim examples/espnow_swarm_radar.py --board m5stack_nanoc6 --port 8080
pylotos-sim examples/c6_wifi6_twt_and_802154.py --board waveshare_esp32c6_lcd_147 --port 8080