Created
October 30, 2024 16:36
-
-
Save thejhh/a63120437b97b7fa5373c4eb7df0337c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import logging | |
from zigpy_znp.zigbee.application import ControllerApplication | |
import zigpy_znp.config as znp_config | |
async def connect_zigbee(): | |
# Set up logging to see detailed output (optional) | |
logging.basicConfig(level=logging.DEBUG) | |
# Create the configuration dictionary | |
config = { | |
znp_config.CONF_DEVICE: { | |
znp_config.CONF_DEVICE_PATH: 'COM3', # Adjust for your actual port | |
znp_config.CONF_DEVICE_BAUDRATE: 115200, # Adjust for your device | |
znp_config.CONF_DEVICE_FLOW_CONTROL: None, | |
}, | |
znp_config.CONF_ZNP_CONFIG: { | |
znp_config.CONF_SKIP_BOOTLOADER: True, | |
znp_config.CONF_SREQ_TIMEOUT: 2, | |
znp_config.CONF_ARSP_TIMEOUT: 5, | |
znp_config.CONF_CONNECT_DTR_STATES: [False, False, False], | |
znp_config.CONF_CONNECT_RTS_STATES: [False, False, False], | |
} | |
} | |
# Create the ControllerApplication with the configuration | |
app = ControllerApplication(config) | |
# Connect to the device | |
await app.connect() | |
# Start the network (auto-form network if necessary) | |
await app.startup(auto_form=True) | |
print("Connected to Zigbee network!") | |
# Keep the application running to handle incoming events | |
# For example, wait indefinitely or perform other tasks | |
try: | |
while True: | |
await asyncio.sleep(1) | |
except KeyboardInterrupt: | |
print("Shutting down Zigbee network...") | |
finally: | |
# Disconnect cleanly | |
await app.shutdown() | |
print("Disconnected from Zigbee network.") | |
# Run the connect_zigbee function | |
asyncio.run(connect_zigbee()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment