Read a BACnet value by polling

Description

In this example you will learn how to communicate with a BACnet device and read data on it by polling the device.

Prerequisites

Modules

Checkout branches

git checkout origin/osp-bacnet-configuration .
git checkout origin/osp-web-configuration .

Note

The complete example can be checkout from any onsphere stack

git checkout origin/example-bacnet-polling .

Objectives

  • How to setup a connection to a BACnet device using module.bacnet and device.bacnet .

  • How to read data using SINGLE_POLLING and owner.bacnet.

Bonus :

  • Display the data in a frontend widget.

Steps

In this example we are using a BACnet stack using https://sourceforge.net/projects/bacnet/files/bacnet-stack/bacnet-stack-1.3.1/. This BACnet stack is running in a container using the following parameters.

bacnet_server:
    image: "nexus.sdnroot.net/bacnet_test_server:1.0"
    command: ["bacserv", "200001"]
    networks:
        - "back"
        - "outside_access"
        - "bridge"

Of course the whole example try to interact using nexus.sdnroot.net/bacnet_test_server:1.0 docker image. This is located in stack.external-services file. Please be careful to check if you can access this container or if your other tests devices are accessible from the OnSphere stack. For any connection problem refer to BACnet.

Note

Depending which BACnet type you are trying to read you may need an other OnSphere type see supported properties.

1. Setup the connection

First you need to configure the connection with a device. This is made in the bacnet.module file and device.bacnet file . This is made in the bacnet.module file and device.bacnet file

{
  "messagingConfiguration": 
  {
    "clientId": "osp-bacnet-1",
    "host": "rabbit"
  },
  "networkConfiguration": {
      "subnetAddress": "172.17.0.0",
      "subnetMask": 16
  },
  "deviceIdentifier": 1234
}
{
    "deviceIdentifier": 200001,
    "moduleId": "modules.bacnet.bacnet-1"
}

2. Read the data on the BACnet device

Once the connection is correctly configured we can now configure the owner.bacnet file. Here we will determine what to read on the device. In this example we are configuring the BACnet module to read periodically the value by using the SINGLE_POLLING parameter. This parameter allow to poll in a dedicated read request and get a dedicated response.

{
    "linkedDevice": "root.bacnet",
    "objectType": "ANALOG_VALUE",
    "objectIndex": 0,
    "property": "PRESENT_VALUE",
    "readStrategy": "SINGLE_POLLING"
}

3. Visualize the data

To visualize the data of your device, a dashboard, including a value subscription widget already linked to the status of your BACnet device and the test value, has been created.

{
    "configuration": [
        {
            "type": "ValueSubscription",
            "id": "mKQio7uo",
            "title": "",
            "valueSubscriptions": {
                "values": [
                    {
                        "id": "root.bacnet",
                        "type": "BOOLEAN",
                        "right": "READ_WRITE"
                    },
                    {
                        "id": "root.state",
                        "right": "READ",
                        "type": "DECIMAL"
                    }
                ]
            }
        },
        {
            "valueSubscriptions": {
                "values": [
                    {
                        "id": "root.callback",
                        "right": "READ_WRITE",
                        "type": "DECIMAL"
                    }
                ]
            },
            "basicWidgetSettings": {
                "showLabel": true,
                "showTooltip": true,
                "showIcon": true,
                "showValue": true
            },
            "id": "ZfYR8aZ_",
            "type": "BasicInputOutputValue",
            "title": ""
        }
    ],
    "layout": {
        "lg": [
            {
                "w": 6,
                "h": 3,
                "x": 0,
                "y": 0,
                "i": "mKQio7uo"
            },
            {
                "w": 4,
                "h": 2,
                "x": 6,
                "y": 0,
                "i": "ZfYR8aZ_"
            }
        ]
    },
    "breakpoints": {
        "lg": 1200,
        "md": 996,
        "sm": 768,
        "xs": 480,
        "xxs": 0
    },
    "cols": {
        "lg": 12,
        "md": 10,
        "sm": 6,
        "xs": 4,
        "xxs": 2
    },
    "rowHeight": 150
}