For the complete documentation index, see llms.txt. This page is also available as Markdown.

Microsoft SQL Server Integration

How to integrate Microsoft SQL Server with Connectware, including writing shop floor data into a production events table and polling query results back into MQTT topics.

This guide describes how to integrate Microsoft SQL Server with Connectware. You configure a service commissioning file that writes shop floor data into a SQL Server table and polls query results back into an MQTT topic. A complete example file is available at the end of this guide.

Objectives

  • Establishing a connection between Connectware and Microsoft SQL Server.

  • Writing shop floor data from an ISA-95-style topic hierarchy into a production events table.

  • Polling recent rows from the database into an MQTT topic on a fixed interval.

Prerequisites

To follow this guide, you will need the following:

Connectware and Microsoft SQL Server Integration

Connectware communicates with Microsoft SQL Server through the MSSQL connector. The connector works by defining SQL queries or query templates on endpoints:

  • Write endpoints define a query template, typically an INSERT statement. The template contains placeholders in the form @identifier, which the connector replaces with the values from the JSON payload of each incoming MQTT message (see Placeholder Syntax).

  • Subscribe endpoints define a query and a polling interval. The connector executes the query on a regular basis and publishes the result rows as a JSON array to the MQTT broker.

The MQTT topics in this guide follow an ISA-95-style equipment hierarchy (<enterprise>/<site>/<area>/<line>/<cell>). The mapping subscribes with named wildcards across all levels, so any machine in the hierarchy is picked up without changing the integration, and the topic levels become column values in the database.

The connector encrypts the connection to the database server by default (the useEncryption connection property), so it also works with Azure SQL Database, which only accepts encrypted connections.

Production Events Table

The integration writes into a single table that stores one row per shop floor event. Create it in your target database:

The event_time column defaults to the insert time in UTC, so the messages do not need to carry a timestamp. If you want to store machine timestamps instead, add a column for them and extend the INSERT statement with another placeholder.

Microsoft SQL Server Connection Properties

We add the connection values as parameters to the service commissioning file, so you can set them when you install the service.

Do not worry about copying the service commissioning file snippets together into one, the complete example file is available at the end of this guide.

  • mssqlHost and mssqlPort: The hostname and port of your SQL Server instance. The default port is 1433.

  • mssqlUsername and mssqlPassword: The SQL login that Connectware uses to connect.

  • mssqlDatabase: The database that contains the production_events table.

  • pollingInterval: The interval in milliseconds between polling queries.

  • topicRoot: The root of the MQTT topic hierarchy. Defaults to enterprise.

Microsoft SQL Server Connection

To connect to the database, we set up a Cybus::Connection resource that uses the MSSQL connector. All endpoints in this guide share this connection.

For all available connection properties, including the TDS protocol version, timeouts, and the reconnection strategy, see MSSQL Connection Properties.

Writing Production Events

The write endpoint defines the INSERT statement as a query template. Each placeholder, for example @site, is replaced with the value of the matching key in the JSON payload of the incoming message.

The mapping feeds the endpoint from the topic hierarchy. It uses named wildcards, so the topic levels are available in the $context.vars object of the transform rule. The rule builds one flat object whose keys match the query placeholders, combining the topic levels with the event_type and value fields of the machine payload.

Any message published to a matching topic, for example enterprise/hamburg/assembly/line-1/press-01/production-events, now inserts one row into the table. The machine payload only needs the event fields, the topic provides the rest:

All placeholders defined in the query must exist in the resulting message payload. If one is missing, the connector logs an error and ignores the message (see Writing Data).

Polling Recent Production Events

For the opposite direction, a subscribe endpoint executes a query on a fixed interval and publishes the result rows to the MQTT broker. This example reads the production events of the last five minutes, so downstream consumers such as dashboards or MES systems receive a regularly updated snapshot.

Choose the polling interval carefully. A low value can overload the database. Instead of a fixed interval, you can also poll on a schedule with the cronExpression property (see MSSQL Endpoint Properties).

Every query execution publishes a message with a timestamp property and a value property that contains the result rows. If the query returns no rows, value is an empty array ([]).

Verifying the Integration

  1. Install the service and set the parameters with the values of your SQL Server instance.

  2. Check that the connection is in the Connected state on the service details page in the Admin UI. If the credentials or the database name are wrong, the connection does not reach the connected state.

  3. Publish a test message with the machine payload shown in this guide to enterprise/hamburg/assembly/line-1/press-01/production-events, for example with an MQTT client or the Admin UI.

  4. Check that the row arrived in the database, for example with SELECT TOP 10 * FROM production_events ORDER BY id DESC. The result of every write is also published to the /res topic of the write endpoint, with value set to true on success.

  5. Use the Data Explorer to inspect the polled result rows on the enterprise/production-events/recent topic.

Service Commissioning File Example

Last updated

Was this helpful?