CSWorks 2.0 talks BACnet

Author: Sergey Sorokin

Published: 2011-05-31 22:02:00

Last update: 2013-09-18 16:10:50

Tags: hmi

Slug: CSWorks-20-talks-BACnet

Starting from version 2.0, CSWorks installation package includes BACnet IP data source provider. That means: now you can build web-based solutions that can communicate with BACnet devices - controllers, modules, thermostats - any kind of hardware that supports BACnet. Here is a quick demonstration.


We will need:
- room thermostat that supports BACnet MSTP;
- BACnet IP to MSTP adapter;
- local network;
- desktop computer (server);
- notebook computer (client).

We have to use BACnet IP to MSTP adapter, because CSWorks supports only IP version of the BACnet protocol, and our thermostat provides only BACnet MSTP (good old RS-485) connectivity. Make sure that:
- both computers and BACnet adapter are connected to your local network;
- thermostat is connected to the adapter via RS-485.

BACnet thermostat in the local network diagram


The following software will be used:
- CSWorks 2.0 on the server; full CSWorks version is required, CSWorks Light will not let clients from other computers access the application;
- Microsoft VisualStudio 2010 on the server;
- web browser on the notebook.

Build demo application

On the server computer, open VisualStudio project at C:\Program Files\CSWorks\Demo\Src\BacnetThermostatIntegrationDemo\ and have a look at MainPage.xaml. BACnet connection points are defined in the very beginning:

<!-- AnalogValue(0): mode (Heat, Cool, Idle, Afterhours, Unoccupied Idle, Unoccupied Heat, Unoccupied Cool) -->
<data:DoubleDataItem x:Key="mode" Id="..." DataSource="RoomThermostat01" TemplateName="analogValue" Parameters="tagIndex=0;"/>
<!-- AnalogValue(6): heating setpoint -->
<data:DoubleDataItem x:Key="heatingSP" Id="..." DataSource="RoomThermostat01" TemplateName="analogValue" Parameters="tagIndex=6;"/>
<!-- AnalogValue(7): cooling setpoint -->
<data:DoubleDataItem x:Key="coolingSP" Id="..." DataSource="RoomThermostat01" TemplateName="analogValue" Parameters="tagIndex=7;"/>
<!-- AnalogValue(20): room temperature -->
<data:DoubleDataItem x:Key="roomTemp" Id="..." DataSource="RoomThermostat01" TemplateName="analogValue" Parameters="tagIndex=20;"/>
<!-- AnalogValue(87): fan speed (off, 1, 2, 3, auto, on) -->
<data:DoubleDataItem x:Key="fanSpeed" Id="..." DataSource="RoomThermostat01" TemplateName="analogValue" Parameters="tagIndex=87;"/>

and used later in the UI definition part:

<TextBlock Text="{Binding Value, Source={StaticResource roomTemp}, ..." .../>
<TextBlock Text="{Binding Value, Source={StaticResource mode}, ..." .../>
<TextBlock Text="{Binding Value, Source={StaticResource heatingSP}, ..." .../>
<TextBlock Text="{Binding Value, Source={StaticResource coolingSP}, ..." .../>
<TextBlock Text="{Binding Value, Source={StaticResource fanSpeed}, ..." .../>

Please note that these BACnet connection points are specific to the particular thermostat used in this demo, your connections points will be different - see BACnet integration guide for your thermostat. Build Release|x86 (for 32-bit installations) or Release|x64 (for 64-bit installations) configuration. Build script will place the compiled application file (CSWorks.Client.BacnetThermostatIntegrationDemo.xap) and hosting HTML file (BacnetThermostatIntegrationDemo.html) to the correspondent locations under C:\Program Files\CSWorks\Demo\Web\. Your client demo application is ready.

Add LiveData source

CSWorks LiveData Service must be aware of the new data source - BACnet device. Our client application will connect to a data source called "RoomThermostat01" (see MainPage.xaml above), so we have to add a new data source with this name. Add the following piece to the LiveData Service configuration file (see C:\Program Files\CSWorks\Framework\Server\CSWorks.Server.LiveDataService.exe.config):

  <bacnetIpLiveDataSources type="CSWorks.Server.DataSource.Bacnet.BacnetIpLiveDataSource, CSWorks.Server.BacnetIpProvider">
    <bacnetIpLiveDataSource name="RoomThermostat01" sampleBufferLength="16" deviceId="99102" ipPort="47808" updateRate="250">
        <template name="analogValue" type="Single" readPath="AnalogValue(($tagIndex)).PresentValue" canWrite="true" />

This demo works only with AV (analog value) BACnet connection points, so there is only one template is defined for this data source. Please make sure that deviceId attribute corresponds to the device identifier of the thermostat, otherwise CSWorks will not be able to locate it in the BACnet network. When done, restart CSWorks LiveData Service.

Configure LiveData web service

LiveData web service must be aware of the "RoomThermostat01" data source as well. Add an antry for "RoomThermostat01" to the LiveData Web Service configuration file (C:\Program Files\CSWorks\Demo\Web\LiveDataWebService\web.config):

    <liveDataPartition name="partition1" primaryLiveDataServer="liveDataServer_1_primary" secondaryLiveDataServer="">
        <dataSource name="RoomThermostat01"/>

Run the application

On the client notebook, open a browser and navigate to the CSWorks application page:


After a few seconds of initialization, you will see the demo reading values from the thermostat (click on the image to enlarge it):

BACnet integration with thermostat

Congratulations! Your thermostat is web-enabled now.