Repository navigation
Replies: 2 comments 1 reply
|
Doing test with your code here, I get a wrong subnet mask when providing only the IP. It defaults to /24 but if like me, you are using something else... it fails to send broadcast messages. I also suggest that you use Also, I really like to use import BAC0
import socket
import asyncio
# Retrieving the IP address from the host PC
hostname = socket.gethostname()
host_ip = socket.gethostbyname(hostname) # Get the corresponding IP address
print(host_ip)
async def start_bacnet_server():
"""
Initialize the BACnet server and periodically update object values.
"""
async with BAC0.start(ip=host_ip, port=47811, deviceId=1112) as device1:
# Start BACnet on a specific IP and port
#device1 = BAC0.start(ip=host_ip, port=47811, deviceId=1112)
print("BACnet started. Discovering devices...")
# Discover devices (this may take some time)
await device1._discover()
# Wait a few seconds to allow device discovery to complete
#await asyncio.sleep(3)
# Get the discovered devices
devices = device1.discoveredDevices
print(f"Discovered devices: {devices}")
print("Pretty")
await device1.devices
if __name__ == "__main__":
asyncio.run(start_bacnet_server()) |
|
This is mostly due to my non-experience with async code. I converted synchronous BAC0 and at the time, I was under the impression that I should try to keep some sync command line that would not require to constantly write "await"... So I created async function using _myfunction and synchronous myfunction that was calling _myfunction as a task. Now that I worked with async a little more, I don't really care writing await... but this initial decision will haunt me for a while... |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I am trying to read from a BACnet network configured on my localhost using the BAC0 library in Python. Below is the code I am using to send a general discovery request. However, every time I run it, no devices are discovered. This is confusing, as I have a BACnet network running and can test it using YABE.
What could be causing this issue, and how can I modify my code to ensure it works for discovering devices on any BACnet network?
Thank you for your help!
All reactions