Skip to content

MQTT Interface

The MQTT Interface is used to communicate drag&bot with the MQTT broker to exchange JSON messages.

General Notes

drag&bot MQTT component includes a MQTT client using QoS level 2 (Quality of service) and supporting MQTT versions 3.1, 3.1.1, and 5.0.

  • JSON messages are used to communicate the data. They are sent as strings.

  • When the hyphen is entered "-" in the UserName and/or Password fields then the MQTT client will try to communicate to the broker without any kind of authentication (open broker).

  • It's highly advisable to use some kind of authentication in the MQTT broker, this can be a userName/Password access or an ACL (Access control list).

Drag&bot MQTT Client

Important

  • Client ID should be unique.
  • drag&bot acts as a bridge to map the ROS topics data to the MQTT topics and vice versa.
  • If you would like to allow other clients to control/get the status of the drag&bot programs on your IPC, then you need to activate the flag Allow line controller in the component manger.

Mapping

You can configure the mapping functionality in the component manager using the fields ROS to MQTT Topics and MQTT To ROS Topics.

  • When the hyphen is entered "-" in the Topics names field, then this field will be ignored and no topics will be created.
  • Any space in the Topics names will be ignored.
  • You don't need to start with / the topic names in the component topic list.

ROS to MQTT Topics

This field is used to map ROS topics to MQTT topics. For multiple topics, write a list of comma separated pairs:

ROS_topic_name : MQTT_topic_name , ROS_topic_name_1 : MQTT_topic_name_1 , etc.

In the example the ROS_topic_name is mapped to MQTT_topic_name.

MQTT To ROS Topics

This field is used to map MQTT topics to ROS topics. For multiple topics, write a list of comma separated pairs:

MQTT_topic_name : ROS_topic_name , MQTT_topic_name_1 : ROS_topic_name_1 , ...etc.

In the example the MQTT_topic_name is mapped to ROS_topic_name.

Function Blocks

Send Message

This function block is used to send JSON string message to MQTT topics (mapped from ROS to MQTT) using its equivalent ROS topic.

Field name Data type Description
Inputs ROS Topic Name String The ROS topic name that is mapped to the required MQTT topic.
JSON Message String The JSON message to be published.
Outputs - - -

Await Message

This function block waits until a message is received from specific ROS topic (mapped from MQTT to ROS) and returns the received JSON as string output

Field name Data type Description
Inputs ROS Topic Name String The ROS topic name that is mapped from the required MQTT topic.
Outputs Received JSON String The received JSON message from the MQTT Topic

Start Program

This function block starts a drag&bot program at another MQTT client. To use this FNB, the flag Allow line controller must be activated at the another MQTT client.

Important

To start the program remotely, you need to deploy it to the robot system, see section Install Programs for installing programs on the Robot System.

Field name Data type Description
Inputs Client ID String The MQTT client ID of the IPC that contains the program to start.
Program Name String The program name to be started
Timeout Float Timeout in seconds. 0 = wait for ever
Outputs Success Boolean Command executed successfully

Stop Program

This function block stops a drag&bot program at another MQTT client. To use this FNB, the flag Allow line controller must be activated at the another MQTT client.

Field name Data type Description
Inputs Client ID String The MQTT client ID of the IPC that contains the program to stop.
Timeout Float Timeout in seconds. 0 = wait for ever
Outputs Success Boolean Command executed successfully

Get Program Status

This function block get the drag&bot program status from another MQTT client. To use this FNB, the flag Allow line controller must be activated at the another MQTT client.

Field name Data type Description
Inputs Client ID String The MQTT client ID of the IPC that contains the program to stop.
Timeout Float Timeout in seconds. 0 = wait for ever
Outputs Running Boolean The program is running at the MQTT client
Stopped by User Boolean The program is stopped manually by a user (using MQTT Stop Program function block)
Finished Correctly Boolean The program execution is finished without an error.
Stopped with Error Boolean The program is stopped due to an error

Broker

These steps describe the installation of the Mosquitto broker. Alternatively you can set your own broker.

Installation through standard sources

The following terminal commands install a broker in your main Ubuntu operating system:

sudo apt-get update sudo apt install mosquitto -y

After the Installation, the mosquitto broker will be immediately launched and also started automatically at the system startup.

The broker IP will be the PC IP where it is installed on. The port number is configured in the mosquitto configuration file (default : 1883).

Configuration

  1. Create a file that contains the user name and the password, call it for example pass under the path /etc/mosquitto/ using the command sudo nano /etc/mosquitto/pass. The file should contain the username and password as below. After that save and close the file.

    01

  2. Run the code mosquitto_passwd -U /etc/mosquitto/pass to encrypt the password.

  3. Open the mosquitto configuration file mosquitto.conf under the path /etc/mosquitto/ using the command sudo nano /etc/mosquitto/mosquitto.conf and insert these lines :

listener 1883

allow_anonymous false

password_file /etc/mosquitto/pass

This will configure the mosquitto to accept the connection from a client with a userName and password authentication on port nomber 1883.

Finally restart mosquitto using the command sudo systemctl restart mosquitto