Middleware communication via Python API

I’d like to connect a middleware to the simulation. Further, the data transported by the middleware should update my robots joint values. Therefore, I tested the communication with MQTT middleware:

  • Publishing data from the OnSimulationUpdate() hook works quite fine and I can receive the message outside VC
  • Receiving data in VC is the problem at the moment. Either I don’t receive the message or VC is crashing in that moment I’m sending a message from a console outside to VC

However, I ask myself if the handling of threads in stackless python cause the problem. Do you have any suggestion how and in which hook (OnRun, OnSimUpdate, OnSignal …) I should set up such an event based communication.


This thread might be a little too old but I’ll show how I got visual components to work with a MQTT broker (mosquitto) to exchange information with a webbrowser over websockets. The mosquitto broker is run as a desktop application in my case (available from https://mosquitto.org/download/).


The webbrowser client is implemented as below:

    <link href="css/button-style.css" rel="stylesheet">

    <script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js" type="text/javascript">
    <script type = "text/javascript" language = "javascript">

        var host="";
        var port=8001;

        var client = new Paho.MQTT.Client(host,port,"webbrowser");

        client.onMessageArrived = onMessageArrived;

        var options = {
            timeout: 3,
            onSuccess: onConnect,


        function onMessageArrived(message) {

        function onConnect() {
            // Once a connection has been made, make a subscription.
            console.log("Connected ");

         //Subscribing to Topics

        function myFunction(){

                message = new Paho.MQTT.Message(event.target.id );
                message.destinationName = "/factory/robot/command";


Pick From Conveyor A
Place in Machining Center
Place on Conveyor B
Pick from Machining Center



The CSS file for the HTML is avoided for the sake of simplicity

The Robot Client in VC is implemented as below:

from vcScript import *
import paho.mqtt.client as mqtt

def executeFunction(fnName):
  global robotExecutor
  comp = getComponent()
  robotExecutor = comp.findBehavioursByType('rRobotExecutor')[0]
  robotProgram = robotExecutor.Program
  routine = robotProgram.findRoutine(fnName)

  if routine is not None:

def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))

def on_message(client, userdata, msg):
  print "Some message received", msg.payload.decode()
  comp = getComponent()

def OnStart():
  global client
  client = mqtt.Client(client_id = "VC_robot", clean_session = False)
  client.on_connect = on_connect
  client.on_message = on_message

def OnRun():
  global client
  while True:


1 Like

I’m very interested in this feature.Can you provide the demo source file

Hello, can you demonstrate the effect you have achieved? I want to learn this easy-to-use function