Bacnet with Raspberry PLC

Implementing BACnet Communication with Raspberry PLCs Using Python and BAC0 Library
8 de julio de 2024 por
Bacnet with Raspberry PLC
Boot & Work Corp. S.L., Martí Schnabel

What is BACnet?

BACnet, short for Building Automation and Control Networks, distinguishes itself from conventional architectures by its decentralized structure. Unlike systems reliant on central servers, BACnet functions on a peer-to-peer model, where each device, whether a sensor or controller, communicates directly with others. This decentralized arrangement enhances system resilience by eliminating single points of failure and fostering flexibility in network design and operation. BACnet's protocol is designed to be platform-independent and transport-agnostic, accommodating diverse networking technologies such as Ethernet, Wi-Fi, and serial connections.


Throughout this blog post, we'll guide you through the process of implementing BACnet communication using Raspberry PLCs and Python's BAC0 library. Before delving into the technical details, we'll outline the prerequisites for testing BACnet communication. Once the requirements are in place, we'll provide step-by-step instructions for installing the BAC0 library and exploring basic BAC0 functions, laying the groundwork for your BACnet implementation journey.

Requirements

To test BACnet communication, you'll need either of the following device setups:

  • 2 Raspberry PLCs
  • 1 Raspberry PLC and your PC.

The communication between devices will be established using an Ethernet cable, and ensure that your PLC is powered within the range of 12-24V.


BACnet implementation

Our Raspberry PLCs support the Bacnet communication protocol and in this post is shown how to implement it using BAC0 library from Python. You can find the BAC0 documentation in this link.

1. First, install it on your Raspberry PLC:

pip install BAC0

Basic BAC0 functions

1. To implement the first simple program to communicate between two devices use the lite() function:

import BAC0
bacnet = BAC0.lite(ip='xxx.xxx.xxx.xxx/mask', port=47808)

The lite() function will allow you to interact with some devices without using the web interface or the live trending features which is a good option for small devices as a Raspberry Pi.

In the function, two parameters are instantiated:

  • IP and mask: Write the IP address and mask of your device. You can use the command ip a.
  • Port: Select the port you want to use. By default, the Bacnet communications will use 47808 port.

To look for the available devices, use the whois() function:

​devices = bacnet.whois()
print("Devices found: ", devices)

To read from a device, use the read() function:

bacnet.read('address object object_instance property')

The request contains:

  • The address of the device from which we want to read.
  • The object type (analogValue).
  • The instance number (the object “address” or “register", for instance, "1").
  • The property from the object we want to read (typically the "presentValue").

To write to a device, use the write() function:

bacnet.write('address object object_instance property value - priority')

The request contains:

  • The address of the device from which we want to read.
  • The object type (analogValue).
  • The instance number (the object “address” or “register", for instance, "1").
  • The property from the object we want to read (typically the "presentValue").
  • The value you want to write.
  • The priority (From 1 to 16).

Buscar en nuestro blog

Bacnet with Raspberry PLC
Boot & Work Corp. S.L., Martí Schnabel 8 de julio de 2024
Compartir

¿Estás buscando tu Controlador Lógico Programable ideal?

Echa un vistazo a esta comparativa de producto de varios controladores industriales basados en Arduino.

Comparamos entradas, salidas, comunicaciones y otras especificaciones con las de los equipos de otras marcas destacadas.


Comparación de PLCs industriales >>>