Getting started
I know nothing about Python
First, welcome to the Python community. If you’re new to Python programming, it can be hard to know where to start.
I highly recommend to start with a complete distribution. That will help you a lot as the majority of important modules will be installed for you.
If you are using Windows, it will simplify your life as some modules need a C compiler and it can be hard sometimes to compile a module by yourself.
Some examples of complete distributions are Anaconda or Enthought Canopy. As I use Anaconda, I’ll focus on this one but you’re free to choose the one you prefer.
If you are using a Raspberry Pi, have a look at miniconda or berryconda. For berryconda, once it’s done, run conda install pandas to install pandas without compiling.
Installing a complete distribution
Begin by downloading Anaconda. Install it. Once it’s done, you’ll get access to a variety of tools like :
Spyder (and IDE to write the code)
Anaconda Prompt (a console configured for Python)
Jupyter Notebook (Python in your browser)
pip (a script allowing you to install modules)
conda (a package manager used by Anaconda)
Start using pip
Open a terminal (e.g., Anaconda Prompt on Windows)
pip install BAC0
This simple line will look in Pypi (The Python Package Index), download and install everything you need to start using BAC0
Check that BAC0 works
In the terminal again, start the asyncio REPL and create a session
python -m asyncio
This will open a python terminal. In the terminal type
>>> import BAC0
>>> async with BAC0.start() as bacnet:
... # connected, ready to use
... pass
This will show you the installed version. You’re good to go.
You can also assign directly and manage cleanup yourself
>>> import BAC0, asyncio
>>> async def demo():
... bacnet = BAC0.start() # or BAC0.connect(), BAC0.lite()
... try:
... # use bacnet
... await bacnet._discover(global_broadcast=True)
... finally:
... await bacnet._disconnect() # or: await bacnet.disconnect()
...
>>> asyncio.run(demo())
Note: the context manager waits for full initialization before entering. Without it, most operations work immediately, but a few conveniences may need a brief moment to become ready.
Where to download the source code
https://github.com/ChristianTremblay/BAC0/
There you’ll be able to open issues if you find bugs.
Dependencies
BAC0 is based on BACpypes3 for BACnet/IP communication.
Optional: * Pandas for convenient history handling * rich for nicer console output * python-dotenv to load a .env
You’re ready to begin using BAC0!