David
David

Reputation: 1

How to create a BACnet Analog Value witch BAC0 in Python?

To start off I have to say that I am an absolute beginner when it comes to Python and the BAC0 library.

I want to create a Bacnet Analog Value with my python script that is supposed to be sent to another (physical) Bacnet-device. For now I have only "created" a Bacnet-device with the bacnet = BAC0.lite() command. It's not much but it works.

I spend a lot of time browsing the documentation but I can not find the right way to let my script send an Analog Value.

Can anyone help?

Background: I have a device that is able to send an analog value (0 ... 10 V) to an MQTT-broker very easiliy. Now I want to let a Raspi recieve that analog value and "transform" it into a Bacnet Analog Value. This Bacnet Analog Value will be sent to a DDC in order to controll the power of a pump. To do this I need the correct command / code that "creates" the Bacnet Analog Value in the python script.

Upvotes: 0

Views: 1012

Answers (1)

Christian Tremblay
Christian Tremblay

Reputation: 839

Here is an example :

#!/usr/bin/python

import weakref
import BAC0
from bacpypes.basetypes import EngineeringUnits, DateTime
from bacpypes.primitivedata import CharacterString, Date, Time

from BAC0.core.devices.local.models import (
    analog_input,
    datetime_value,
    character_string,
)
from BAC0.core.devices.local.object import ObjectFactory
from BAC0.core.devices.local.models import make_state_text

def start_device():
    print("Starting BACnet device")
    new_device = BAC0.lite(deviceId=10032)
    time.sleep(1)

    # Analog Values
    _new_objects = analog_input(
        instance=1,
        name="Current_Temp",
        description="Current Temperature in degC",
        presentValue=0,
        properties={"units": "degreesCelsius"},
    )
    _new_objects = analog_input(
        instance=2,
        name="Current_Pressure",
        description="Current Pressure in kPa",
        presentValue=0,
        properties={"units": "kilopascals"},
    )

    # Character Strings
    # _new_objects = character_string(
    #    instance=1,
    #    name="Location",
    #    description="City code for data",
    #    presentValue="on-24",
    #    is_commandable=True,
    # )

    _new_objects.add_objects_to_application(new_device)
return new_device

Upvotes: 1

Related Questions