zigpy-znp

0.14.3 · active · verified Thu Apr 16

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `zigpy` controller using `zigpy-znp` as the radio backend. It sets up a basic configuration, attempts to start the controller, and optionally forms a new Zigbee network. Remember to replace `/dev/ttyUSB0` with your actual serial port and ensure you have the necessary permissions.

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.")

view raw JSON →