BACnet/MSTP Example
The BACnet/MSTP Device Service example demonstrates onboarding the BACnet Sim device simulation that is provided with Edge Xpert.
Preconfiguration
Since the BACnet Device Service can run both BACnet/IP and BACnet/MSTP, it must be configured for the correct mode prior to it starting.
To configure the BACnet Device Service to use BACnet/MSTP and the simulated device, you must first create a local docker-compose.yml file. This can be achieved by copying the following content and saving it to your working directory.
version: '3.7'
services:
device-bacnet-mstp:
environment:
BACNET_SERIAL_INTERFACE: /dev/virtualport
volumes:
- /dev/virtualport:/dev/virtualport
bacnet-sim:
environment:
RUN_MODE: "MSTP"
version: '3.7'
services:
device-bacnet-mstp:
user: root:root
security_opt:
- label:disable
environment:
BACNET_SERIAL_INTERFACE: /dev/virtualport
volumes:
- /dev/virtualport:/dev/virtualport
bacnet-sim:
environment:
RUN_MODE: "MSTP"
ports:
- "55000:55000"
- Set RUN_MODE to
MSTP
to run the BACnet simulated device with BACnet/MSTP. Refer to BACnet Sim for further details.
You can configure any specific options for running the Device Service in the environment
section of the device-bacnet-mstp
entry of your local docker-compose.yml file. A listing of available environment variables can be found here.
Start the BACnet/MSTP Device Service and Simulator
To start the BACnet/MSTP Device Service with the simulator, enter the following command:
edgexpert up bacnet-sim
socat
command to transfer data to the simulator.
Note
Socat is a flexible, multi-purpose relay tool. Its purpose is to establish a relationship between two data sources, where each data source can be a file, a Unix socket, UDP, TCP, or standard input. Install socat
by entering the following commands in the terminal: sudo apt udpate
and sudo apt install socat
.
sudo socat pty,link=/dev/virtualport,raw,echo=0,mode=666 tcp:$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' bacnet-sim):55000
sudo socat pty,link=/dev/virtualport,raw,echo=0,mode=666 tcp:localhost:55000
As demonstrated below, Edge Xpert will override the default configuration with a local docker-compose.yml file:
$ edgexpert up device-bacnet-mstp
Overriding configuration with local docker-compose.yml
Creating network "edgexpert_edgex-network" with driver "bridge"
...
Creating device-bacnet-mstp ... done
Note
In order for your local changes to be used, you must start Edge Xpert from the directory in which your local docker-compose.yml is saved.
Device Onboarding
Once the BACnet/MSTP Device Service has been started, BACnet devices can be onboarded to Edge Xpert using either the Edge Xpert Manager UI or through Edge Xpert REST API commands. Instructions on how to use both methods are described below.
Device Onboarding with the Edge Xpert Manager UI
Note
Please refer to the Edge Xpert Manager UI Device Management capability for full details.
-
Ensure the Edge Xpert Manager UI is started, for example:
edgexpert up xpert-manager
-
Open a browser and go to
localhost:9090
. The default username and password isadmin
. -
Using the device profile upload capability, upload the provided BACnet example device profile at /usr/share/edgexpert/examples/device-services/bacnet/bacnet-sim-profile.yml
-
Onboard the BACnet device using the device onboarding capability. The following values can be used to provision the example BACnet simulated device:
Field Example Value Description Required Name bacnet-mstp-sim
The unique name used to identify the device Required Description Simulated BACnet device
Additional information about the device Optional Label BACnet
Any additional information to help identify the device Optional Protocol BACnet-MSTP
The name of the protocol Required Device Instance 123
The unique device identifier across the BACnet network Required Device Profile bacnet-sim-profile
The name of the device profile uploaded above Required Device Service device-bacnet-mstp
The name of the appropriate device service Required Auto Events Interval: 5s
OnChange:false
ResourceName:analog_input_0-present-value
Automated events to retrieve the data at specific frequencies
Note: If OnChange is set to true, values will only be pushed if a change in value has occurred during the specified interval. If set to false, values will be sent on the specified interval regardless of if there has been a change.Optional
Device Onboarding with the Edge Xpert REST API
Info
If Edge Xpert is running in secure mode, you will need to replace localhost in the URL with the IP address for the service. See CLI Service Ports for details.
-
Upload the provided BACnet example device profile:
curl http://localhost:59881/api/v2/deviceprofile/uploadfile -F "file=@/usr/share/edgexpert/examples/device-services/bacnet/bacnet-sim-profile.yml"
-
Onboard the device using similar values as explained above:
curl http://localhost:59881/api/v2/device -H "Content-Type:application/json" -X POST \ -d '[ { "apiVersion": "v2", "device": { "name" :"bacnet-mstp-sim", "description":"Simulated BACnet device", "labels":[ "BACnet" ], "serviceName": "device-bacnet-mstp", "profileName": "bacnet-sim-profile", "protocolName": "BACnet-MSTP", "protocols":{ "BACnet-MSTP":{ "DeviceInstance": "123" } }, "adminState":"UNLOCKED", "operatingState":"UP", "autoEvents": [ { "interval": "5s", "onChange": false, "sourceName": "analog_input_0-present-value" } ] } } ]'
Device Data Flow
Once the device is onboarded to Edge Xpert, data flow between the Device Service and the connected device can be verified in a number of ways.
The Edge Xpert Manager UI supports Read and Write functionality for each device. Readings can also be viewed and queried within the Edge Xpert Manager UI Data Center.
Alternatively, you can read and write data with cURL commands or through REST API applications, such as Postman.
Info
If Edge Xpert is running in secure mode, you will need to replace localhost in the URL with the IP address for the service. See CLI Service Ports for details.
Both the GET and PUT requests can be made to the following address:
http://localhost:59882/api/v2/device/name/{deviceName}/{commandName}
Using the example above, a GET request to this device service could be:
curl http://localhost:59882/api/v2/device/name/bacnet-mstp-sim/analog_input_0-present-value
For more information on the GET and PUT commands, see the Core Command Microservice.
Any data collected by the Device Service can then be processed like all other Edge Xpert sensor data. The data readings can be exported for data processing in a number of other applications and services. See the Supporting Services and Application Services documentation for more details.