Using atvise connect to Read from an MQTT Broker

Created by Jose Fabian Solano, Modified on Mon, 15 Jul at 9:39 PM by Jose Fabian Solano

The first crucial step is to set up an MQTT communication channel within our atvise connect. In this initial setup, it's necessary to provide the IP address of the MQTT broker we want to connect to, specify the port that the broker uses for MQTT connections, and determine if any authentication is required to establish a secure and authorized connection. This configuration ensures that atvise connect can establish and maintain effective and reliable communication with the MQTT broker, facilitating consistent and accurate data reading.


Next, we'll specify the MQTT protocol version that atvise uses. Atvise supports versions 3.1 and 3.1.1; if you're connecting to a Mosquitto broker, it supports version 3.1.1. Additionally, choose the quality of service (QoS) level supported by the connection. Lastly, it's important to check the "Use String type for data" option because atvise ultimately receives JSON data, which it interprets as text.


Since we're establishing a connection from Atvise Connect, we need to create our variables here to publish them via the OPC UA protocol to Atvise Builder. To do this, navigate to the "Add Variables" icon located at the top.



Here we are going to create a variable; you can choose any name you prefer, for example, "JSON". We will use the following syntax: "TOPIC_NAME{{String}}". In this structure, the first part represents the topic name we are connecting to in order to extract the JSON data. The curly braces indicate that the data is in JSON format, and we specify the variable type as String to interpret the data as readable text. After saving this configuration, we will verify if we can view the data in the variables section, accessible through the data visualization icon.



With this setup complete, we send the data to atvise Builder by creating an OPC UA communication channel.


After adding our JSON variable and verifying that it receives the JSON correctly, the next step is to parse this information into a new variable so that we can use it within an object. To achieve this, we need to create a script to parse and extract the desired information from the JSON. Navigate to the "Library" section where you'll find an option called "Script Menu." Here, we will create a script specifically for parsing purposes.



Within the script, we're going to create the following code to extract the "value" property from the JSON:


// Assigning the value from the created node.

var temp = Ua.findNode("AGENT.OBJECTS.JSON.JSON");


// Parsing the received information. temp.result.value allows me to appreciate the content of this. variable / objectAtvise / objectValueJson.

var parseo = JSON.parse(temp.result.value);


// Logging the parsed value to the console.

console.log(parseo.value);


// Finding the node "AGENT.OBJECTS.JSON.Resultado" and assigning the parsed value to it.

var resultado = Ua.findNode("AGENT.OBJECTS.JSON.Resultado");

resultado.result.assign({value: parseo.value});


This code will extract the "value" property from the JSON and create a new variable named "resultado" to store and display the data.




Created by JF


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article