Connecting Prosys OPC UA Forge to Various MQTT Brokers

While Forge’s functions and capabilities expand, so does the demand for augmented connectivity. The offering of different MQTT brokers is growing fast, and we want to enable you to connect to the broker of your choice as quickly as possible. This blog post will guide you through the steps to connect Prosys OPC UA Forge with prominent platforms such as Azure IoT Hub and Amazon IoT Core. In the future, this blog post will be updated with more MQTT brokers. The MQTT brokers we have tested are: If you don’t see your broker on the lists above and would like us to test it, contact us by email or via our contact form to let us know about the broker, and we’ll add it to our list.

Guides

You can find our finished guides below. Click on the tab you are interested in to read the guide for that specific MQTT broker.

Forge Publisher – Azure IoT Hub

During this tutorial, we will be using the following products:

  • Azure IoT Hub
  • Visual Studio Code with Azure IoT Hub extension

Connecting to Azure IoT Hub

  1. Create a new device in the IoT Hub.
  2. The connection information to the IoT Hub is as follows:
    • Connection address: mqtts://”Hostname”:8883
    • Client Id: “DeviceId”
    • Username: “Hostname”/”DeviceId”/?api-version=2021-04-12
    • Password: “SAS Token”
    • Queue: devices/”DeviceId”/messages/events/
    • Metadata Queue: devices/”DeviceId”/messages/events/metadata/
    • The hostname is the name of your IoT Hub, and it can be seen on the front page of the IoT Hub.
    • DeviceId is the name of the device you created.
  3. Generate the SAS Token with Visual Studio Code.
Generating password (SAS Token) for Azure IoT Hub in Visual Studio Code
  1. Open Prosys OPC UA Forge and add the OPC UA Publisher Module.
  2. In the OPC UA Publisher -tab, you will need to add at least a Connection, Writer Group, and either Variable or Event Data Set.
  3. Add a Connection to Azure using the connection information you previously collected.
Azure connection information in Forge
  1. Create a Writer Group and choose a Variable or Event Data Set that the Writer Group Publishes. Remember to add the correct MQTT Topic Settings to the Writer Group.
MQTT Topic settings for Azure IoT Hub
  1. The Publisher should now be enabled, and the IoT Hub should receive data. You can check the sent messages from Visual Studio Code.
Subscribing to Azure IoT Hub Publisher in Visual Studio Code

Forge Publisher – Amazon IoT Core – Forge Subscriber

During this tutorial, we will be using the following products:

  • Amazon IoT Core

Connecting to Amazon IoT Core

  1. Create a new single Thing in IoT Core/Manage/All devices/Things/Create Things.
  2. Enter a name for the Thing and set it to have no shadow.
  3. Auto-generate a new certificate and download all certificate files when prompted.
Certificate generation and downloading in AWS IoT Core
  1. Create a new policy, IoT Core/Manage/Security/Policies.
  2. Give the policy a name and fill in the policy document information as shown in the image below.
Policy document creation information in AWS IoT Core
  1. To attach the created policy, go to IoT Core/Manage/Things/”name of the created Thing”/Certificates and choose the certificate you wish to add the policy to.
Security Policies in Amazon IoT Core
  1. You can find the connection Endpoint from IoT Core/Test/MQTT test client/Connection details/Endpoint.
  2. Open Prosys OPC UA Forge and add the Publisher and Subscriber Modules.
  3. In the OPC UA Publisher -tab you will need to add at least a Connection, Writer Group, and either Variable or Event Data Set.
  4. Add a new Connection using the connection Endpoint from IoT Core and the certificates downloaded.
Forge connection screen for AWS IoT Core
  1. Create a Writer Group and choose a Variable or Event Data Set that the Writer Group Publishes.
  2. Now, you should see some data in the IoT Core/Test/MQTT test client.
  3. Use Subscriber wildcard * for the topic filter.
  4. Lastly, create an MQTT subscriber. In Forge/Data Sources/OPC UA Subscribers, add a new Subscriber using the same certificate files and Endpoint address as for the publisher.

Forge Publisher – Eclipse Mosquitto – Forge Subscriber

During this tutorial, we will be using the following products:

Connecting to Eclipse Mosquitto

  1. Pull and run the eclipse-mosquitto image in Docker Desktop.
Docker Desktop Pull and Run eclipse-mosquitto image
  1. Set the correct host port for the MQTT broker. In this case, we use the default port, 1883. Other settings are not necessary.
  2. Run the Docker container.
Docker Desktop new container
  1. Open the configuration file from Files/mosquitto/config/mosquitto.conf and edit it with the following information:
    • listener 1883
    • allow_anonymous true

    These commands allow external connections to port 1883.

Docker Desktop edit mosquitto.conf file
  1. Save and restart the container.
Docker Desktop save and restart container
  1. Open Prosys OPC UA Forge and add the OPC UA Publisher Module.
  2. In the OPC UA Publisher tab, you will need to add at least a Connection, Writer Group, and either Variable or Event Data Set.
  3. Add a Connection to the Eclipse Mosquitto using the address mqtt://localhost:1883.
Connecting Forge to localhosted Eclipse MQTT Broker
  1. Create a Writer Group and choose a Variable or Event Data Set that the Writer Group Publishes.
  2. Now, let’s also add the Publisher.
  3. Use Subscriber wildcard * for the topic filter.
  4. Lastly, create an MQTT subscriber. In Forge/Data Sources/OPC UA Subscribers, add a new Subscriber using the same connection address as for the publisher.

Forge Publisher – HiveMQ – Forge Subscriber

During this tutorial, we will be using the following products:

Connecting to HiveMQ

  1. Pull and run the hivemq4 image in Docker Desktop.
HiveMQ docker desktop pull and run
  1. Set the correct host port for the MQTT broker. In this case, we use the default port, 1883. If you are using the default ports for some other applications, change the ports.
  2. Run the Docker container.
HiveMQ docker desktop settings
  1. Open Prosys OPC UA Forge and add the OPC UA Publisher Module.
  2. In the OPC UA Publisher tab, you will need to add at least a Connection, Writer Group, and either Variable or Event Data Set.
  3. Add a Connection to the HiveMQ using the address mqtt://localhost:1883. The connection Name does not matter and to demonstrate that, I am using the same connection from the previous part of this tutorial.
Connecting Forge to localhosted Eclipse MQTT Broker
  1. Create a Writer Group and choose a Variable or Event Data Set that the Writer Group Publishes.
  2. Now, let’s also add the Publisher.
  3. Use Subscriber wildcard * for the topic filter.
  4. Lastly, create an MQTT subscriber. In Forge/Data Sources/OPC UA Subscribers, add a new Subscriber using the same connection address as for the publisher.

Forge Publisher – Azure Event Grid – Forge Subscriber

During this tutorial, we will be using the following products:

Generating Certificates with OpenSSL

If you have installed Git to your device, you already have OpenSSL on your computer. On Windows computers, it is normally located in: C:\Program Files\Git\usr\bin\openssl.exe
  1. Open the .exe file
  2. Generate a Certificate Authority (CA) Certificate and Key with command: openssl req -new -x509 -days -extensions v3_ca -keyout ca.key -out ca.crt
  1. Generate a client Key for the Publisher with command: openssl genrsa -out client-pub.key 2048
  1. Generate a Certificate Signing Request (CSR) with command: openssl req -out client-pub.csr -key client-pub.key -new
  1. Send the CSR to the CA to sign it with command: openssl x509 -req -in client-pub.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client-pub.crt -days <duration>
  1. Now lets generate another Keypair for the Subscriber. Generate a client Key with command: openssl genrsa -out client-sub.key 2048
  1. Generate a CSR with command: openssl req -out client-sub.csr -key client-sub.key -new
  1. Send the CSR to the CA to sign it with command: openssl x509 -req -in client-sub.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client-sub.crt -days <duration>

Configuring the Azure Event Grid

  1. Create a new Azure Event Grid Namespace. This may take several minutes.
Azure search for event grid
  1. Enable the MQTT broker that is disabled by default. This may also take several minutes.
  1. Next create two new clients, Subscriber and Publisher.
  2. Select the Thumbprint Match as the Validation Scheme. Then thumbprint can be check from the Certificates we created earlier.
  1. Create a topic space. You can use any name and template for it. In this demo we are using example template called contosotopic/topic1
  1. Create two Permission Bindings. One for the Publisher and one for the Subscriber.

Connecting Forge to the Azure Event Grid

  1. Open Prosys OPC UA Forge and add the OPC UA Publisher and Subscriber Modules.
  2. In the OPC UA Publisher tab, you will need to add at least a Connection, Writer Group, and either Variable or Event Data Set.
  3. Add a Connection to the Azure Event Grid using the address mqtts://<MQTT hostname>:8883. Choose the Publisher Certificate and Key that we created earlier. The Username must be the same as the clients name in the Azure Event Grid.
  1. Lastly, create an MQTT subscriber. In Forge/Data Sources/OPC UA Subscribers, add a new Subscriber using the same connection address as for the publisher. This time use the client-sub Keypair.

Next Steps

To learn more about Forge and its capabilities, request a detailed introduction by emailing sales@prosysopc.com or using our contact form. We’d be delighted to provide tailored information about Forge that aligns with your interests and requirements.

If you want to test Forge yourself, we can provide you with an evaluation license to get you started. You can request an evaluation license by emailing our sales team or filling out the request form.

A generic vector graphic of an author avatar

Elias Nykänen

Software Engineer

Email: elias.nykanen@prosysopc.com

Related Posts

Interested in this topic?

Get updated about new posts through our newsletter!
Scroll to Top