How to use BAC0 read value in Python?

1.6k Views Asked by At

I was trying to use BAC0 to get values of multiple points in BACnet system, I tried all the Posters and Getting starts, but no one works....

I can get value from BACnet tools which means the connection should be right: enter image description here

Then I move to BAC0, and I want to use this command:

bacnet.read('address object object_instance property')

In my case, BACnet (10.192.62.15/24) and my Raspberry pi (10.192.62.18/24) is connect with a same router, the Device id should be 2039307, objective name is "occupied_cool_setpoint_1" and objective type is "AnalogValue" with objective ID 1. I am little confused with "object and object_instance", what's this in my case?

Another question is about "Device":enter image description here, I have no idea why it always tell me unknow objective...

I also try to use this example:

        ***import BAC0
        myIPAddr = '192.168.1.10/24'
        bacnet = BAC0.connect(ip = myIPAddr)
        bacnet.read('2:5 analogInput 1 presentValue')***

But what is 2:5 here, the ip address should be something like: 192.168.1.1, right?

In my case, when I run "discover": enter image description here And I want to know the points for device ID 2039307, should I use "20393:10.192.62.15/24" instead of "2:5"

Thanks for your patience help!!!!

2

There are 2 best solutions below

0
On

It is surprisingly simple to read data from a BACnet device with Python. In my case I have wireless BACnet thermostat in my home and I have set the static IP address of the device to 192.168.0.150. I have a PC running Linux mint and I'm using Jupyter Lab. Simply import BAC0 library and type the following three lines.

import BAC0
bacnet = BAC0.connect()
bacnet.whois()

In my case, BAC0.connect returns the fist 9 lines and the last line is the IP address and node of the single device on my network. If you don't see any devices listed there is something wrong with your network or device setup.

enter image description here

Then you can use the following command to read an analog value which in my case is the current temperature.

bacnet.read("192.168.0.150 analogInput 0 presentValue")

which at the present time returns a value of 67.3. If you would like to read all the objects available to a particular device you can use the readMultiple command.

bacnet.readMultiple("192.168.0.150 device 100001 all")

In my case this returned the following very large list

[('device', 100001),
 'WiFi BACnet Thermostat',
 'device',
 'operational',
 'Abies Technology, Inc.',
 685,
 '122C',
 '1.52',
 'Aug  6 2021',
 1,
 15,
 [0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  1,
  0,
  1,
  1,
  1,
  1,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  1,
  1,
  0,
  0,
  0,
  0,
  0,
  0],
 [1,
  0,
  1,
  1,
  0,
  1,
  0,
  0,
  1,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  1,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0],
 [('device', 100001),
  ('analogInput', 0),
  ('analogInput', 1),
  ('analogInput', 2),
  ('analogInput', 3),
  ('analogInput', 4),
  ('analogInput', 5),
  ('analogInput', 6),
  ('analogInput', 7),
  ('analogInput', 8),
  ('analogInput', 9),
  ('analogInput', 10),
  ('analogInput', 11),
  ('analogInput', 12),
  ('analogInput', 13),
  ('analogInput', 14),
  ('analogInput', 15),
  ('analogValue', 0),
  ('analogValue', 1),
  ('analogValue', 2),
  ('analogValue', 3),
  ('analogValue', 4),
  ('analogValue', 5),
  ('analogValue', 6),
  ('analogValue', 7),
  ('analogValue', 8),
  ('analogValue', 9),
  ('analogValue', 10),
  ('analogValue', 11),
  ('analogValue', 12),
  ('analogValue', 13),
  ('analogValue', 14),
  ('analogValue', 15),
  ('analogValue', 16),
  ('analogValue', 17),
  ('analogValue', 18),
  ('analogValue', 19),
  ('analogValue', 20),
  ('analogValue', 21),
  ('analogValue', 22),
  ('analogValue', 23),
  ('analogValue', 24),
  ('analogValue', 25),
  ('analogValue', 26),
  ('analogValue', 27),
  ('analogValue', 28),
  ('analogValue', 29),
  ('analogValue', 30),
  ('analogValue', 31),
  ('analogValue', 32),
  ('analogValue', 33),
  ('analogValue', 34),
  ('analogValue', 35),
  ('analogValue', 36),
  ('analogValue', 37),
  ('analogValue', 38),
  ('analogValue', 39),
  ('analogValue', 40),
  ('analogValue', 41),
  ('analogValue', 42),
  ('analogValue', 43),
  ('analogValue', 44),
  ('analogValue', 45),
  ('analogValue', 46),
  ('analogValue', 47),
  ('analogValue', 48),
  ('analogValue', 49),
  ('analogValue', 50),
  ('binaryInput', 0),
  ('binaryInput', 1),
  ('binaryInput', 2),
  ('binaryInput', 3),
  ('binaryInput', 4),
  ('binaryInput', 5),
  ('binaryInput', 6),
  ('binaryInput', 7),
  ('binaryInput', 8),
  ('binaryInput', 9),
  ('binaryInput', 10),
  ('binaryInput', 11),
  ('binaryInput', 12),
  ('binaryInput', 13),
  ('binaryInput', 14),
  ('binaryInput', 15),
  ('binaryInput', 16),
  ('binaryInput', 17),
  ('binaryInput', 18),
  ('binaryInput', 19),
  ('binaryInput', 20),
  ('binaryInput', 21),
  ('binaryInput', 22),
  ('binaryInput', 23),
  ('binaryInput', 24),
  ('binaryInput', 25),
  ('binaryInput', 26),
  ('binaryValue', 0),
  ('binaryValue', 1),
  ('binaryValue', 2),
  ('binaryValue', 3),
  ('binaryValue', 4),
  ('binaryValue', 5),
  ('binaryValue', 6),
  ('binaryValue', 7),
  ('binaryValue', 8),
  ('binaryValue', 9),
  ('binaryValue', 10),
  ('binaryValue', 11),
  ('binaryValue', 12),
  ('binaryValue', 13),
  ('binaryValue', 14),
  ('binaryValue', 15),
  ('binaryValue', 16),
  ('multiStateValue', 0),
  ('multiStateValue', 1),
  ('multiStateValue', 2),
  ('multiStateValue', 3),
  ('multiStateValue', 4),
  ('multiStateValue', 5),
  ('multiStateValue', 6),
  ('multiStateValue', 7)],
 1476,
 'noSegmentation',
 6000,
 3,
 [],
 0,
 'Network Mode: Infrastructure Mode\r\nIP: 192.168.0.150\r\nMAC: c893-465a-a28c']

It is a great help to download a BACnet explorer tool like Yabe (Yet another bacnet explorer) although I have not been able to get it working with Linux mint though it works on Windows just fine.

0
On

I do not know neither 'BAC0' nor 'Python', but I will try to give you a possible head-start.

BACnet defines an 'Object Identifier' - that is composed of two parts, a left-hand/leading/high-order part that is the "object" type, and the right-hand/trailing/low-order part that is the "object instance #"; so I'm guessing "object" is really (the name of) the object-type.

I'm guessing "2:5" is the DNET (Destination Network #) & DADR (Destination Address) - 2 & 5, whereby a (child) device needs it's own (additional) address as it is routed-to/gatewayed-to/accessed via a BACnet router/gateway device. Whereas, if your targeting either a standalone device or a (parent) router/gateway device (& not one of its children/child devices), then I'm guessing you might have to specify the target IP(v4) address only/instead of this DNET:DADR/"2:5" combo/value.

If you need to specify/target a remote child device, then I'm guessing that (in the case of 'BAC0') you might have to use both addresses, e.g. possibly something like this '2:[email protected]'.