var ipBroker = "<?php echo $config->Robots->Robot[0]->ip ?>"; //mqtt websocket enabled broker
var portBroker = <?php echo $config->Robots->Robot[0]->port ?>;
var mqttClient = new Paho.MQTT.Client(ipBroker, portBroker, "clientIdFromArScene" + parseInt(Math.random() * 100, 10));
mqttClient.onConnectionLost = function (responseObject)
{
console.log("connection lost: " + responseObject.errorMessage);
};
mqttClient.onMessageArrived = function (message)
{
switch(message.destinationName)
{
<?php
for($i = 0; $i < $NUM_TOPICS; $i++)
{
echo "case '" . $config->ViewTopics->Topic[$i]->path . "' :\r\n\t\t"
. "switch('" . $config->ViewTopics->Topic[$i]->type . "') \r\n\t\t"
. "{\r\n\t\t case '" . $NAME_TEXT . "' :\r\n\t\tvar entity = document.querySelector('#viewTopic" . $i . "');\r\n\t\t"
. "entity.setAttribute('text', 'color: red; align: center; value: ' + message.payloadString + ';width:3');\r\n\t\tbreak;\r\n\t\t"
. "case '" . $NAME_BALKEN . "' :\r\n\t\tvar barEntity = document.querySelector('#viewTopic" . $i . "');\r\n\t\t"
. "var textEntity = document.querySelector('#textViewTopic" . $i . "');\r\n\t\t"
. "if((message.payloadString * 1) >= " . $config->ViewTopics->Topic[$i]->min . "){\r\n\t\t"
. "barEntity.setAttribute('width', " . ($MAX_WIDTH_BAR / ($config->ViewTopics->Topic[$i]->max - $config->ViewTopics->Topic[$i]->min)) . " * (message.payloadString - " . $config->ViewTopics->Topic[$i]->min . "));\r\n\t\t}"
. "else{\r\n\t\tbarEntity.setAttribute('width', '0.1');\r\n\t\t}\r\n\t\t}\r\n\t\t\tbreak;\r\n\t";
}
?>
}
};
var options =
{
timeout: 3,
onSuccess: function ()
{
console.log("Connectet to MQTT-Broker");
// Subscribing the actual relevant Topics
mqttClient.subscribe('<?php echo $config->ViewTopics->Topic[0]->path ?>', {qos: 0});
mqttClient.subscribe('<?php echo $config->ViewTopics->Topic[1]->path ?>', {qos: 0});
mqttClient.subscribe('<?php echo $config->ViewTopics->Topic[2]->path ?>', {qos: 0});
mqttClient.subscribe('<?php echo $config->ViewTopics->Topic[3]->path ?>', {qos: 0});
},
onFailure: function (message)
{
console.log("Connection to MQTT-Broker failed: " + message.errorMessage);
}
};
function mqttSend(topic, msg)
{
console.log("Message get send: " + msg);
message = new Paho.MQTT.Message(msg);
message.destinationName = topic;
mqttClient.send(message);
}
function init()
{
console.log("Trying to connect to MQTT-Broker");
mqttClient.connect(options);
console.log(parseInt(10) *2);
}