Skip to main content

Configure the MQTT Driver

The MQTT driver connects Machines Simulator to an MQTT broker.

Machines Simulator publishes its digital and analog input values to the broker and receives digital and analog output values from MQTT topics.

This example uses:

  • the public HiveMQ test broker
  • MQTTX as an MQTT client for monitoring and publishing messages
warning

The public HiveMQ broker is intended for testing only. Do not use it for production systems or confidential information.

Communication structure

The default MQTT topics are:

Machines Simulator signalDirectionDefault topic
Digital inputMachines Simulator to brokersimulation/io/in/digital/{index}
Analog inputMachines Simulator to brokersimulation/io/in/analog/{index}
Digital outputBroker to Machines Simulatorsimulation/io/out/digital/{index}
Analog outputBroker to Machines Simulatorsimulation/io/out/analog/{index}

The signal index starts at 0.

For example, if 32 digital signals are configured, the valid indexes range from 0 to 31.

note

The in and out sections of the topic refer to the Machines Simulator I/O direction.

Machines Simulator publishes its inputs and receives its outputs.

Configure the MQTT driver

  1. Open the machine you want to use.
  2. Open the I/O Drivers menu.
  3. Select MQTTDriver.
  4. Click Configure.
User Configuration

The MQTT Client Driver configuration window appears.

User Configuration

Configure the broker connection

The Machines Simulator MQTT Client Driver window, allows you to enter the connection settings. For this example, use the following values:

SettingValue
IP/Host Brokerbroker.hivemq.com
Port1883 (default)
Digital I/O numberNumber of digital signals required
Analog I/O numberNumber of analog signals required

IP/Host Broker: The IP address or host name of the MQTT broker.

note

broker.hivemq.com is a free public MQTT broker provided by HiveMQ.

The driver supports a maximum of:

  • 1024 digital I/O signals
  • 1024 analog I/O signals

Configure the topic bases

You can use the default topic bases or replace them with your own topic structure. The default values are:

SettingDefault value
Digital input topic basesimulation/io/in/digital/
Digital output topic basesimulation/io/out/digital/
Analog input topic basesimulation/io/in/analog/
Analog output topic basesimulation/io/out/analog/

The driver automatically adds the signal index to the end of each topic.

Digital input example

Digital input 5 is published using:

Topic: simulation/io/in/digital/5
Payload: 1

The digital payload can be:

  • 1 for ON
  • 0 for OFF

Analog input example

Analog input 2 is published using:

Topic: simulation/io/in/analog/2
Payload: 25.7

Analog signals use numeric values.

After completing the configuration, click OK.

Assign the I/O signals

Assign the MQTT signals to the corresponding Machines Simulator signals.

You can assign them in either of the following ways:

  • drag & drop each MQTT signal onto the corresponding Machines Simulator I/O
  • select Driver > Automatic Assignment when the signals are sequential
User Configuration

When the assignment is complete, select:

Exit > Start Driver and Exit

User Configuration

Machines Simulator is now ready to connect to the MQTT broker.

Configure MQTTX

MQTTX is used as Server in this example to monitor the input messages published by Machines Simulator and to send output values back to the simulation.

Create the connection

  1. Open MQTTX.
  2. Create a new connection.
  3. Configure the following values:
SettingValue
NameAny descriptive connection name
Hostmqtt://broker.hivemq.com
Port1883
UsernameLeave blank
PasswordLeave blank
  1. Click Connect.
User Configuration

Subscribe to Machines Simulator inputs

Machines Simulator publishes digital and analog input values through separate topic branches.

Subscribe to digital inputs

  1. Click New Subscription.
  2. Enter the following topic:
simulation/io/in/digital/#
  1. Leave the remaining settings at their default values.
  2. Click Confirm.

The # wildcard subscribes to all digital input indexes below the topic base.

User Configuration

Subscribe to analog inputs

Create another subscription using:

simulation/io/in/analog/#

Click Confirm.

The # wildcard subscribes to all analog input indexes below the topic base.

User Configuration

MQTTX is now subscribed to all digital and analog input messages published by Machines Simulator.

Test digital inputs

Activate or deactivate a digital input in Machines Simulator.

MQTTX receives a message similar to:

Topic: simulation/io/in/digital/0
Payload: 1

When the input is deactivated, the driver publishes:

Topic: simulation/io/in/digital/0
Payload: 0
User Configuration

Test digital outputs

To control a digital output from MQTTX, publish a message to its output topic.

For example, to activate digital output 2, use:

Topic: simulation/io/out/digital/2
Payload: 1

Click Send.

The corresponding output is activated in Machines Simulator.

To deactivate it, publish:

Topic: simulation/io/out/digital/2
Payload: 0

The driver also accepts boolean values:

  • TRUE for ON
  • FALSE for OFF
User Configuration
User Configuration

Test analog inputs

When an analog input changes in Machines Simulator, the driver publishes its numeric value.

For example:

Topic: simulation/io/in/analog/0
Payload: 2.45

The value can be monitored from the analog input subscription in MQTTX.

User Configuration

Test analog outputs

To change an analog output, publish a numeric value to the corresponding output topic.

For example, to set analog output 1 to 5.89, use:

Topic: simulation/io/out/analog/1
Payload: 5.89

Click Send.

The new value appears in the corresponding Machines Simulator analog output.

User Configuration