Read a BACnet value by polling
In this example you will learn how to communicate with a BACnet device and read data on it by polling the device.
Configure the BACnet module connection using
module.bacnetanddevice.bacnet.Read a BACnet object periodically using the
SINGLE_POLLINGmode inowner.bacnet.Display the polled 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-polling .
Learning goals
How to setup a connection to a BACnet device using
module.bacnetanddevice.bacnet.How to read data using
SINGLE_POLLINGandowner.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.
{
"readStrategy": {
"strategy": "SINGLE_POLLING",
"frequency": {
"value": 5,
"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
}