Integrate OPC UA With MongoDB - A Feasibility Study With Codelitt

Humza Akhtar, Alex Butler, and Kaio Magalhães

Open Platform Communications Unified Architecture (OPC UA) is a widely recognized and important communication standard for Industry 4.0 and industrial IoT. It enables interoperability across different machines and equipment, ensuring reliable and secure information sharing within the Operational Technology (OT) layer. By providing a standard framework for communication, OPC UA enhances data integrity, security, and accessibility of data, enabling many use cases for Industry 4.0.

OPC UA focuses on standard data transmission and information modeling. It uses multiple data encoding methods, such as binary or JavaScript Object Notation (JSON), and leverages different levels of security encryption to address security concerns. For information modeling, it adopts an object-oriented approach to abstract and model specific industrial assets such as robots, machines, and processes. Rich data models and object types can be created for a description of machine attributes and composition. Using OPC UA, the traditional context-less time-series machine data is transformed into a semantic-based information model.

MongoDB's document model offers a straightforward and compelling approach for storing OPC UA semantic information models due to its flexibility and compatibility with complex data structures. The document model is a superset of all other types of data models, which makes it very popular in the developer community. OPC UA information models contain detailed relationships and hierarchies, making the dynamic schema of MongoDB a natural fit. Fields in the document are extensible at run time, making dynamic updates and efficient querying a breeze. For example, consider an OPC UA information model representing an industrial robot. This model will encompass information about the robot's status, current task, operational parameters, and maintenance history.

Example OPC UA information model for an Industrial Robot

  • Robot
    • RobotName (Variable)
    • Status (Variable)
    • CurrentTask (Variable)
    • OperationalParameters (Object)
    • MaxSpeed (Variable)
    • PayloadCapacity (Variable)
    • Reach (Variable)
    • MaintenanceHistory (Array of Objects)
    • Timestamp (Variable)
    • Description (Variable)

With MongoDB, this model can be easily represented in a document with nested fields.

{
  "_id": ObjectId("654321ab12345abcd6789"),
  "RobotName": "Robot1",
  "Status": "Running",
  "CurrentTask": "Assembling Component ABC",
  "OperationalParameters": {
    "MaxSpeed": 80, // in cm/s 
   "PayloadCapacity": 150, // in kg
   "Reach": 2.65 // in m 
    },
  "MaintenanceHistory": [
    {
      "Timestamp": "2023-08-25T10:00:00",
      "Description": "Routine checkup"
    },
    {
      "Timestamp": "2023-06-25T14:30:00",
      "Description": "Replaced worn-out gripper"
    }
  ]
}

This MongoDB document easily captures the complexities of the OPC UA information model. Hierarchical attributes in the model are maintained as objects, and arrays can represent historical data and log files. As the robot runs during the production shift, the document can be easily updated with real-time status information. Instead of worrying about creating a complicated Entity Relationship diagram with SQL databases, MongoDB offers a superior alternative to represent digital shadows of industrial equipment.

Now that we have seen how easy it is to model OPC UA data in MongoDB, let's talk about how to connect an OPC UA server to MongoDB. One of our partners, Codelitt, is developing a connector that can ingest time-series OPC UA data into MongoDB in real time. Codelitt is a custom software strategy, engineering, and design company.

The architecture of the end-to-end solution is shown in Figure 1.

Figure 1: High-level architecture and data flow

In Figure 1:

  • Industrial equipment and controllers will transmit data to local servers using the OPC UA protocol.

  • OPC UA servers will listen to these devices and broadcast them to all subscribed clients.

  • Clients will listen to specific events/variables and queue the event to be stored.

  • The message broker will provide the queue system to digest a large amount of data and provide reliability between the event source and the data storage.

  • MongoDB Atlas will provide the final destination of data, and the ability to do analytics using the aggregation framework and visualization using Atlas Charts.

Technical details

It is assumed that the user already has machines that have OPC UA server enabled. For the OPC UA client, depending on the client's preferences, the Codelitt solution can switch between a custom-built OPC UA client based on the Node-OPCUA open source project, AWS IoT SiteWise Edge, or a Confluent-based OPC UA source connector. In the case of a custom-built client, it will connect to the machine's OPC UA server using OPC TCP and extract the necessary data that is then transmitted to a broker. The message broker could be any cloud-provided solution (Azure Event Hub, Amazon Kinesis, etc.) or any form of Kafka implementation from Confluence for example. In the case of Kafka, the MongoDB Kafka connector can be leveraged to push data to the database. Finally, leveraging the aggregation framework, the operating parameters of each device are queried for visualization via MongoDB Atlas Charts.

In summary, the MongoDB document model elegantly mirrors OPC UA information, and there are multiple options available to users who would like to push data from their OPC UA servers to MongoDB.

To learn more about MongoDB’s role in the manufacturing sector, please visit our manufacturing webpage. To learn more about how Codelitt is digitally transforming industries, please visit their website.