zigpy-znp
zigpy-znp is a Python library that provides a radio implementation for the `zigpy` ecosystem, enabling communication with Texas Instruments (TI) ZNP (Zigbee Network Processor) based radios. It allows `zigpy` applications to control Zigbee networks using devices like TI CC2531, CC2652R/P, CC1352P, etc., acting as the coordinator or router. The current version is 0.14.3, and it receives updates as needed to support `zigpy` advancements, new ZNP firmware features, and bug fixes.
Common errors
-
SerialException: [Errno 13] Permission denied: '/dev/ttyUSB0'
cause The user running the Python script does not have sufficient permissions to access the specified serial device.fixAdd the user to the `dialout` group (Linux) using `sudo usermod -a -G dialout $USER` and then log out and back in, or reboot. Alternatively, adjust device permissions or udev rules. -
FileNotFoundError: [Errno 2] No such file or directory: 'COM3'
cause The specified serial port path does not exist or is incorrect for your system.fixVerify the serial port name. On Linux, check `/dev/tty*` (e.g., `/dev/ttyACM0`, `/dev/ttyUSB0`). On Windows, check Device Manager for the correct `COM` port (e.g., `COM3`, `COM4`). -
ValueError: Unknown radio type: 'znp'
cause The `zigpy` application cannot find the `zigpy-znp` radio backend. This usually means `zigpy-znp` is not installed or `zigpy` hasn't correctly discovered its entry points.fixEnsure `zigpy-znp` is correctly installed (`pip install zigpy-znp`). If running in a virtual environment, activate it before installation. Restart the application or environment if necessary.
Warnings
- gotcha On Linux, users often encounter 'Permission denied' errors when accessing serial ports (`/dev/ttyACM0` or `/dev/ttyUSB0`).
- gotcha Incompatible ZNP firmware versions on your TI radio can lead to connection issues, instability, or missing features.
- gotcha Only one application can access a serial port at a time. Trying to run multiple instances of `zigpy` or other serial tools simultaneously will cause errors.
- breaking Changes in the core `zigpy` library's API or configuration scheme can affect `zigpy-znp` users, as `zigpy-znp` is a radio backend for `zigpy`.
Install
-
pip install zigpy-znp
Imports
- ZnpApplication
from zigpy_znp.zigbee.application import ZnpApplication
Quickstart
import asyncio
import os
from zigpy.application import Controller
from zigpy.config import CONF_DATABASE_PATH, CONF_DEVICE, CONF_RADIO_TYPE
async def main():
# Replace with your actual serial port for the ZNP radio
# On Linux: '/dev/ttyACM0' or '/dev/ttyUSB0'
# On Windows: 'COM3'
serial_port = os.environ.get("ZNP_SERIAL_PORT", "/dev/ttyUSB0")
# Define the zigpy configuration
config = {
CONF_DEVICE: {
CONF_RADIO_TYPE: "znp", # This activates zigpy-znp
"port": serial_port,
},
CONF_DATABASE_PATH: "zigpy_znp.db", # Database for network state
}
print(f"Starting zigpy controller with ZNP radio on {serial_port}...")
controller = Controller(config)
try:
# auto_form=True creates a new network if none exists. Set to False if you expect to join an existing network.
await controller.startup(auto_form=True)
print("Controller started successfully. Network formed/joined.")
# At this point, you can interact with the Zigbee network, e.g., discover devices
print("Controller running for 10 seconds. Press Ctrl+C to stop sooner.")
await asyncio.sleep(10) # Keep running for 10 seconds
print("Shutting down controller.")
except Exception as e:
print(f"Error starting controller: {e}")
finally:
await controller.shutdown()
print("Controller shut down.")
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("Exiting.")