SMARTUNIFIER Configuration

Information Models

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

Information Model - Equipment (File Reader)

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

Equipment Information Model

Screenshot of the Equipment Information Model in SMARTUNIFIER

Structure of the Information Model for the File Consumer Channel:

  • Event:

    The event specified in the Information Model for the File Reader will serve as a trigger in the Mapping. When a file in the target directory is detected by SMARTUNIFIER the associated rule will be executed.

  • Variables:

    Variables defined within the Event represent the key-value pairs in the XML-file.

ID

Node Type

Data Type

FileEvent

Event

FileEventType

FileEvent/OrderNr

Variable

String

FileEvent/ProductNr

Variable

String

FileEvent/Date

Variable

String

FileEvent/Quality

Variable

String

FileEvent/Quantity

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.xml-database-2-mqtt” is used.

Information Model - Database (SQL)

Create an Information Model that represents the structure of the database query:

Database Information Model

Screenshot of the Database Information Model in SMARTUNIFIER

Structure of the Information Model for the SQL Database Channel:

  • Command:

    We need a structure that allows us to receive a reply, and commands provide this capability. The Parameter variable, OrderNumber, is used in the database select query as a parameter. The Reply variable, Customer, will store the outcome of the corresponding database query.

Database - Variables

ID

Node Type

Data Type

DatabaseSelect

Command

Command_DatabaseSelect

DatabaseSelect/Parameters/OrderNumber

Variable

String

DatabaseSelect/Reply/Customer

Variable

String

Information Model - Host (MQTT)

Create an Information Model that represents the data structure of the MQTT payload.

Host Information Model

Screenshot of the Host Information Model in SMARTUNIFIER

Structure of the Information Model for the MQTT payload:

  • Event:

    In this demo we want to send JSON data to the MQTT broker. The structure of the payload is defined in the Event by adding Variables of simple (e.g. OrderNumber) or complex (e.g. TimestampType) data type.

Host - Variables

ID

Node Type

Data Type

MQTTEvent

Event

MQTTEventType

MQTTEvent/OrderNr

Variable

String

MQTTEvent/ProductNr

Variable

String

MQTTEvent/Customer

Variable

String

MQTTEvent/Quantity

Variable

int

MQTTEvent/Quality

Variable

String

MQTTEvent/Timestamp

Variable

TimestampType

MQTTEvent/Timestamp/Time

Variable

String

MQTTEvent/Timestamp/Date

Variable

String

Communication Channels

Communication Channels are described in the chapter Communication Channels.

Communication Channel - Equipment (File Reader)

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

1. Create File Reader (XML) Channel:

  • Enter the group name: demo.xml-database-2-mqtt

  • Enter a name: e.g. Equipment

  • Select the Equipment Information Model created previously

  • Select File Reader (XML) as the Channel Type

2. Configuration of the File Reader (XML) Channel:

a. Select the root node and specify paths to following folders:

  • In

  • Process

  • Out

  • Error

Configuration the File Reader (XML) Channel

Screenshot of the configuration of the File Reader in SMARTUNIFIER

b. Enable the Event FileEvent to tell SMARTUNIFIER that this event is going to be used for reading in the file. We can further explicitly define which files in the directory should be processed by configuring the File Name Filter.

Configuration of the File Reader (XML) Channel

Screenshot of the configuration of the File Reader in SMARTUNIFIER

3. Apply your changes and save the Channel.

Communication Channel - SQL Database

To create the SQL Database Communication Channel we need to proceed with the steps outlined below:

1. Create the SQL Database Channel:

  • Enter the group name: demo.xml-database-2-mqtt

  • Enter a name: e.g. Database

  • Select the Database Information Model created previously

  • Select Sql Database as Channel Type

2. Configuration of the SQL Database Channel:

a. Select the root node and configure the database connection:

  • Select the database type SQLServer

  • Set the JDBC Url according to the selected database - jdbc:sqlserver://192.168.0.111:1433;databaseName=unifier;trustServerCertificate=true

  • Enter the Username and the Password or select it from the Credential Manager

Configuration the SQL Database Channel

Screenshot of the configuration of the SQL Database in SMARTUNIFIER

b. Select the Command node and enter the SELECT query - select CUSTOMER_NAME from DEMO_INTEGRATION_UC3_SCHEMA.CUSTOMER where ORDER_NUMBER = ${ORDER_NUMBER}

Configuration the SQL Database Channel

Screenshot of the configuration of the SQL Database in SMARTUNIFIER

c. Select the OrderNumber Variable and enter the associated database column name.

Configuration the SQL Database Channel

Screenshot of the configuration of the SQL Database in SMARTUNIFIER

d. Select the Customer Variable and enter the associated database column name.

Configuration the SQL Database Channel

Screenshot of the configuration of the SQL Database in SMARTUNIFIER

3. Apply your changes and save the Channel.

Communication Channel - MQTT

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

1. Create the MQTT Channel:

  • Enter the group name: demo.xml-database-2-mqtt

  • Enter a name: e.g. Host

  • Select the Host Information Model created previously

  • Select MQTT (JSON) as Channel Type

2. Configuration of the MQTT Channel:

a. Select the root node and enter the Host (ip address) and the port of the MQTT Broker (We can leave the other configurations at their default value for this demo).

Configuration the MQTT Channel

Screenshot of the configuration of the MQTT Channel in SMARTUNIFIER

b. Select the Event node to enable the Producers and enter a name for the Topic.

Configuration the MQTT Channel

Screenshot of the configuration of the MQTT Channel in SMARTUNIFIER

3. Apply your changes and save the Channel.

Mappings

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.xml-database-2-mqtt

  • Enter a name: e.g. Advanced Mapping

  • Add the Information Models form earlier:

  • demo.xml-database-2-mqtt.Equipment

  • demo.xml-database-2-mqtt.Database

  • demo.xml-database-2-mqtt.Host

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.

2. Create a Rule that executes the SELECT query and sends the result with the other equipment data out via MQTT.

a. Enter a Rule Name.

b. Drag and drop the FileEvent Node from the Equipment Information Model into the trigger field.

c. Drag and drop the DatabaseSelect Command from the Database Information Model into the actions panel.

d. Assign to each target element the appropriate source element (via drag and drop):

  • database/DatabaseSelect/Parameters/OrderNumber := equipment/FileEvent/OrderNumber

  • host/MQTTEvent/OrderNumber := equipment/FileEvent/OrderNumber

  • host/MQTTEvent/Customer := reply.Customer (enable code for assigning the reply of the request)

  • host/MQTTEvent/Timestamp/Date := java.time.format.DateTimeFormatter.ofPattern("dd.MM.yyyy").format(java.time.OffsetDateTime.parse(event.Date.value.toString)) (enable code to format the date)

  • host/MQTTEvent/Timestamp/Time := java.time.format.DateTimeFormatter.ofPattern("HH:mm:ss").format(java.time.OffsetDateTime.parse(event.Date.value.toString)) (enable code to format the time)

  • host/MQTTEvent/Quantity := toInt(event.Quantity) (enable code to do a type conversion)

Definition of the Rule

Screenshot of the Rule editor in SMARTUNIFIER

We can also use the code editor and paste the following code snippet:

equipment.FileEvent mapTo { event =>
  database.DatabaseSelect.execute(command => {
    Try {
      command.OrderNumber := event.orderNumber
      CommunicationLogger.log(event, command)
      }
  }, reply => {
    host.MQTTEvent.send(event1 => {

      Try {
        event1.Timestamp.time := java.time.format.DateTimeFormatter.ofPattern("HH:mm:ss").format(java.time.OffsetDateTime.parse(event.date.value.toString))
        event1.Timestamp.date := java.time.format.DateTimeFormatter.ofPattern("dd.MM.yyyy").format(java.time.OffsetDateTime.parse(event.date.value.toString))

        event1.OrderNumber := event.orderNumber
        event1.ProductNumber := event.productNumber
        event1.Customer := reply.Customer
        event1.Quantity := event.quantity.toInt
        event1.Quality := event.quality

        CommunicationLogger.log(reply, event1)
      }
    }
    )
  }
  )
}

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.xml-database-2-mqtt and a name: e.g. SU DeviceType.

2. Select the Mapping created previously.

3. Assign the Channels (Equipment, Database, and Host) 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.

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

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 equipment with the customer information via MQTT, move the XML-file into the specified In Folder (Step 2.1 Communication Channel - Equipment - Configuration).