Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assistance with BAC0 Experiments and Address in Use Error #518

Open
tgc1979 opened this issue Jan 27, 2025 · 0 comments
Open

Assistance with BAC0 Experiments and Address in Use Error #518

tgc1979 opened this issue Jan 27, 2025 · 0 comments

Comments

@tgc1979
Copy link

tgc1979 commented Jan 27, 2025

Hi,

I’m new to BAC0 and have been experimenting with it in a test environment. Here’s a brief overview of my setup and the issues I’m encountering:

Setup
I created a Linux VM with two network adapters configured as follows:

Adapter 1: 192.168.0.10 (used in tests/manual_test.py)
Adapter 2: 192.168.0.50 (used in tests/manual_test_create_device.py)
Below are code snippets from the test scripts where I made changes:

Below are code snippets from the existing test code in the repo where I made changes:

tests/manual_test_create_device

sync def main():
    # We'll use 3 devices plus our main instance
    devip = "192.168.0.50/24"
    async with BAC0.start(localObjName="bacnet",ip=devip) as bacnet:
        async with BAC0.start(port=47809, localObjName="App1",ip=devip) as device_app:
            async with BAC0.start(port=47810, localObjName="App2",ip=devip) as device30_app:
                async with BAC0.start(port=47811, localObjName="App3",ip=devip) as device300_app:

tests/manual_test

async def main():
    # Configuration
    # # Initialize BACnet
    print(BAC0.infos.__version__)

    async with BAC0.start(ip="192.168.0.10/24") as bacnet:

        await bacnet._discover()
        lst = await bacnet._devices(_return_list=True)
        print(lst)

I am monitoring the traffic using Wireshark. When I start manual_test_create_device.py, I see BACnet communication from adapter 1 to adapter 1 on the specified ports. I believe the purpose of this test is not only to simulate devices but also to interact with them.

However, when I run manual_test.py, I expect to see "Who-Is" requests from adapter 2 to adapter 1, as both adapters are on the same subnet. Unfortunately, this does not happen because I encounter an "Address already in use" error.

Here’s the error traceback:

Exception in callback IPv4DatagramServer.set_broadcast_transport_protocol(<IPv4Address 192.168.0.10>)(<Task cancell...nit__.py:150>>)
handle: <Handle IPv4DatagramServer.set_broadcast_transport_protocol(<IPv4Address 192.168.0.10>)(<Task cancell...nit__.py:150>>)>
Traceback (most recent call last):
  File "/home/vboxuser/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/bacpypes3/ipv4/__init__.py", line 159, in retrying_create_datagram_endpoint
    return await loop.create_datagram_endpoint(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/base_events.py", line 1423, in create_datagram_endpoint
    raise exceptions[0]
  File "/usr/lib/python3.12/asyncio/base_events.py", line 1407, in create_datagram_endpoint
    sock.bind(local_address)
OSError: [Errno 98] Address already in use

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/home/vboxuser/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/bacpypes3/ipv4/__init__.py", line 207, in set_broadcast_transport_protocol
    transport, protocol = task.result()
                          ^^^^^^^^^^^^^
  File "/home/vboxuser/PycharmProjects/PythonProject/.venv/lib/python3.12/site-packages/bacpypes3/ipv4/__init__.py", line 167, in retrying_create_datagram_endpoint
    await asyncio.sleep(BACPYPES_ENDPOINT_RETRY_INTERVAL)
  File "/usr/lib/python3.12/asyncio/tasks.py", line 665, in sleep
    return await future
           ^^^^^^^^^^^^
asyncio.exceptions.CancelledError

My Observations and Questions
Address Already in Use

  • I’m using two different IP addresses (192.168.0.10 and 192.168.0.50) on the same subnet, so I don’t expect a collision. Am I misunderstanding how the adapters or ports are being bound in BAC0?

Discovery Without _discover()

  • In manual_test_create_device.py, the device named "bacnet" is somehow able to discover other devices without explicitly calling _discover().
  • I added breakpoints in the "Who-Is" code but never hit them. How is discovery happening in this scenario?

Additional Information
I am using the latest version of BAC0 from the master branch.
Python version: 3.12
I would greatly appreciate your help in resolving these issues and understanding what might be wrong with my setup or logic.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant