Read a BACnet value by subscription
In this example you will learn how to communicate with a BACnet device and read data on it by subscription.
Configure the BACnet module connection using
module.bacnetanddevice.bacnet.Subscribe to change notifications using
OBJECT_SUBSCRIPTIONmode inowner.bacnetto receive updates pushed by the device.Use
SINGLE_SUBSCRIPTIONas an alternative to receive updates only whenPRESENT_VALUEor selected properties change.Display the subscribed value on a dashboard using a value subscription widget.
git checkout origin/osp-bacnet-configuration .
git checkout origin/osp-web-configuration .
git checkout origin/osp-variables-configuration .
git checkout origin/example-bacnet-subscription .
Learning goals
How to setup a connection to a BACnet device using
module.bacnetanddevice.bacnet.How to read data using
OBJECT_SUBSCRIPTIONandowner.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.
{
"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 subscribe one the value by using the OBJECT_SUBSCRIPTION parameter. This parameter asks the bacnet device to notify use about any changes on the BACnet object. Using SINGLE_SUBSCRIPTION option instead means that updates only arrive when a change on PRESENT_VALUE or any other selected BACnet properties happens (see supported properties).
{
"readStrategy": {
"strategy": "OBJECT_SUBSCRIPTION",
"subscriptionRefreshFrequency": {
"value": 30,
"unit": "SECONDS"
}
},
"linkedDevice": "root.bacnet",
"object": {
"type": "ANALOG_VALUE",
"instance": 0,
"property": "PRESENT_VALUE"
}
}
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": {
"showTooltip": 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
}