SMARTUNIFIER Configuration

Information Models

Information Models, and how to create them, are described in the chapter Information Models.

Information Model - CSV File (File Tailer)

Create an Information Model that represents the CSVs file’s structure:

File Tailer CSV Information Model

Screenshot of the FileTailer Information Model in SMARTUNIFIER

Structure of the Information Model for the File Tailer Channel

  • Event:

    The event specified in the Information Model for the File Tailer will serve as a trigger in the Mapping. When a new line in the CSV file is detected by SMARTUNIFIER the associated rule will be executed.

  • Variables:

    Variables defined within the Event represent the values in the same order as defined in the CSV-file.

CsvDataModel - Variables

ID

Node Type

Data Type

CsvData

Event

CsvDataType

CsvData/Timestamp

Variable

String

CsvData/Temperature

Variable

String

CsvData/Pressure

Variable

String

Note

The group function allows you to combine logical entities into paths. You can use existing naming conventions and styles for naming equipment to organize the configuration components. This simplifies the structuring and management of configurations.

Hint

We recommend using a consistent “Group” name throughout the demo. For instance, to identify the artifacts created for this scenario, the group name “demo.csv-rest” is used.

Information Model - REST Server

There must be a second Information Model, for the REST-Server.

Create an Information Model that represents the structure of the data on the REST server.

REST Server Information Model

Screenshot of the REST server Information Model in SMARTUNIFIER

Structure of the Information Model for the REST server:

Variables

The variable Data which is defined as a custom data type represents a data object on the Rest server. By invoking Data, we can conveniently access all associated variables at once, rather than retrieving each individually.

The individual variables nested within Data specifically represent the actual values.

RestDataModel - Variables

ID

Definition Type

Data Type

Data

Variable

DataStructure

Data/Timestamp

Variable

LocalDateTime

Data/Temperature

Variable

Double

Data/Pressure

Variable

Double

Communication Channels

Communication Channels are described in the chapter Communication Channels.

Communication Channel - File Tailer (CSV)

To create the File Tailer Communication Channel we need to proceed with the steps outlined below:

1. Create File Tailer (CSV) Channel:

  • Enter the group name: demo.csv-rest

  • Enter a name: e.g. FileTailer

  • Select the FileTailer Information Model created previously

  • Select File Tailer (CSV) as the Channel Type

2. Configuration of the File Tailer (CSV) Channel:

a. Select the root node to configure:

File Tailer to String:

  • Enter the path to the location of the CSV-file

  • We can leave the other configurations on default

File Tailer to String configuration

CSV String to Model:

  • Enter the seperator that is used within the CSV-file

  • Check Ignore first line if the file contains a header

CSV String to Model configuration

b. Select the CsvData - Event and enable the event:

  • File Tailer to String - Click on Enable Event

  • CSV String to Model - Click on Enable Event

File Tailer Event configuration

3. Apply your changes and save the Channel.

Communication Channel - REST Server

To create the REST Server Communication Channel we need to proceed with the steps outlined below:

1. Create the REST Server Channel:

  • Enter the group name: demo.csv-rest

  • Enter a name: e.g. RestServer

  • Select the RestServer Information Model created previously

  • Select Rest Server as Channel Type

2. Configuration of the Rest Server Channel:

  • Enter the Path prefix e.g. demo

  • Enter the IP e.g. 127.0.0.1

  • Enter the Port e.g. 7777

Rest Server configuration

3. Apply your changes and save the Channel.

Mapping

Mapping are described in the chapter Mappings.

To create the Mapping we need to proceed with the steps outlined below:

1. Create the Mapping:

  • Enter the group name: demo.csv-rest

  • Enter a name: e.g. CsvDataToRest

  • Add the Information Models form earlier:

  • demo.csv-rest.FileTailer

  • demo.csv-rest.RestServer

Hint

You can enter for each Information Model a short name which is used within the Rule to access all elements of the specific Information Model e.g. csv and rest.

2. Create a Single Rule that defines the Mapping between the File Tailer and the Rest Server Information Model.

a. Enter a Rule Name e.g. CsvToRest.

b. Drag and drop the CsvData Event from the File Tailer Information Model into the trigger field.

c. Drag and drop the Data variable from the Rest Server Information Model into the actions panel. Make sure to choose the Complex assignment type.

d. Assign to each target element the appropriate source element:

Because we have different data types for the source and the target Information Model we have to use the following code constructs:

  • To convert the String variables Temperature and Pressure to double, we can use toDouble(definition: TVariableDefinition[T]):

    • rest/Data/Temperature := toDouble(event.Temperature)

    • rest/Data/Pressure := toDouble(event.Pressure)

  • To convert the String variable Timestamp to a LocalDateTime, we can use:

    • rest/Data/Timestamp := java.time.Instant.ofEpochSecond(event.Timestamp.value.toLong).atZone(java.time.ZoneOffset.UTC).toLocalDateTime

Hint

To enter code in the Source field click the Source Code icon.

Definition of the Rule

Screenshot of the Rule editor in SMARTUNIFIER

3. Compile the Rule and save the Mapping

Device Type

Device Types are described in the chapter Device Types.

To create the Device Type we need to proceed with the steps outlined below:

1. Enter the group name used for this demo: demo.csv-rest and a name: e.g. SU DeviceType.

2. Select the Mapping created previously.

3. Assign the Channels (File Tailer and Rest Server) to their respective Information Models.

Device Type

Screenshot of the Device Type view in SMARTUNIFIER

4. Save the Device Type.

Instance

Instances are described in the chapter Communication Instances.

1. Here we just need to select the Device Type created previously.

Hint

We could modify the configuration of the different Channels at this level, but we have already done so at the Channel level previously.

2. Save the Instance.

Deployment

Deployments are described in the chapter Deployment.

To deploy our Communication Instance we need to proceed with the steps outlined below:

1. Select the Local Deployment

2. Select the Instance, the Endpoint default:Default and Info for the level of detail of the log (We can leave the other configuration at their default value for this demo).

3. Save the Deployment.

4. Now Deploy and Start the Instance.

Deployment

Screenshot of a deployed Instance in SMARTUNIFIER

Execution

In order to send the data from the CSV file to the REST server, just add a new line of data.

To access the data open any Browser and enter http://127.0.0.1:7777/demo/Variable/Data as an URL to receive the values in JSON format.