Write a BACnet value¶
Description¶
In this example you will learn how to communicate with a BACnet device and write data. It is recommended to first start by reading the following bacnet polling example, as some of the elements are also explained there.
Prerequisites¶
Modules
Checkout branches
git checkout origin/osp-bacnet-configuration .
git checkout origin/osp-variables-configuration .
git checkout origin/osp-web-configuration .
Note
The complete example can be checkout from any onsphere stack
git checkout origin/example-bacnet-write .
Objectives¶
How to setup a connection to a BACnet device using
module.bacnet
anddevice.bacnet
.How to write data using
output.bacnet
and a callback.ospp.
Bonus :
Display the data in a frontend widget and use another widget to increment a BACnet
ANALOG_VALUE
.
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. Write the data on the BACnet device¶
To write the data on the BACnet device, it is a requirement to be able to understand to concept of outputs and callbacks. The file output.bacnet
represents the target on which you want to write data.
{
"linkedDevice": "root.bacnet",
"objectIndex": 0,
"objectType": "ANALOG_VALUE",
"property": "PRESENT_VALUE"
}
Next, the callback.ospp
in which you will configure the output to trigger.
{
"linkedOutputs": [
{
"outputId": "root.write"
}
]
}
1. Read the data on the BACnet device¶
Once the connection is correctly configured, and the output correctly triggered, 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": "OBJECT_SUBSCRIPTION"
}
4. 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. For this write example there is also a basic input output value widget that triggers the callback. In this use case, it increases or decreases the value by 1.
{
"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
}