On the Python BACnet stack bacpypes there is simple examples on how to make a BACnet server, like this mini_device.py on the git repo.
The BACpypes applications require a .ini file like a config file which looks like that states the address of the NIC card you want to use:
[BACpypes]
objectName: OpenDsm
address: 192.168.0.109/24
objectIdentifier: 500001
maxApduLengthAccepted: 1024
segmentationSupported: segmentedBoth
vendorIdentifier: 15
Trying to turn this into a docker container if I put this mini_device.py in a dir with the BACpypes.ini, requirements.txt for bacypes, and a Dockerfile that looks like this:
# Use an official Python runtime as a parent image with Python 3.10
FROM python:3.10-alpine
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt
# Make port 47808 available to the world outside this container
EXPOSE 47808/udp
# Define environment variable
ENV PYTHONUNBUFFERED=1
# Run your Python script when the container launches
CMD ["python", "app.py"]
A run in terminal $ docker build -t bacnet-server-test .
It builds just fine but when running it with $ docker run -p 47808:47808/udp bacnet-server-test I get an OSError: [Errno 99] Address not available error I think because the BACpypes.ini file is stating an incorrect address to use.
Would anyone have any advice to research on this? Am sort of a newbie in Docker thanks for any tips. Ideally if its possible it would be nice for the Python script to just bind the address to like an eth0 adapter or something in Linux...?
Full traceback:
Traceback (most recent call last):
File "/app/app.py", line 136, in <module>
main()
File "/app/app.py", line 96, in main
test_application = SampleApplication(this_device, args.ini.address)
File "/usr/local/lib/python3.10/site-packages/bacpypes/app.py", line 535, in __init__
self.mux = UDPMultiplexer(self.localAddress)
File "/usr/local/lib/python3.10/site-packages/bacpypes/bvllservice.py", line 96, in __init__
self.directPort = UDPDirector(self.addrTuple)
File "/usr/local/lib/python3.10/site-packages/bacpypes/udp.py", line 155, in __init__
self.bind(address)
File "/usr/local/lib/python3.10/asyncore.py", line 333, in bind
return self.socket.bind(addr)
OSError: [Errno 99] Address not available
I think this is working...add in these packages:
And add in these functions
update_ini_addressandget_ip_addressand modifications to themainas shown below with keeping the rest ofmini_device.pythe same:The
Dockerfileno changes are needed. This is working for me on running this on a Rasp PiAnd the Docker container running
mini_device.pyfinds the host OS IP address where it appears to work fine. From a separate Windows computer on my LAN test bench themini_device.pyBACnet is responding to the BACnetwho-isfrom a BACnet scan tool...and the points ofmini_device.pyworks as expected...