Connecting a BVS0060 Vision Sensor to mySCADA via MQTT using Node.js
1. Introduction & Requirements
In this tutorial, we’ll walk through an example of integrating a Balluff BVS0060 vision sensor with mySCADA using the MQTT protocol and a Node.js bridge. This approach enables real-time inspection data from your vision sensor to be visualized and processed directly in the SCADA environment.
What You’ll Need
- BVS0060 vision sensor (Balluff), configured to publish MQTT messages
- MQTT broker (e.g., Mosquitto or public broker for testing)
- Access to your mySCADA system (license is necessary for scripting)
- Basic understanding of MQTT and JavaScript
2. Sensor Setup
The BVS0060 vision sensor includes a built-in MQTT interface that enables machine-to-machine communication. It can be used for applications such as:
- Acquisition of parameters and product data
- Condition Monitoring
- Track and Trace integration
- Sending inspection results to the cloud or SCADA
The sensor acts as an MQTT client and sends (PUBLISHes) messages to a broker either cyclically or upon value changes. Other clients, such as Node.js applications or SCADA systems, can SUBSCRIBE to these topics to consume the data.
MQTT Transmission Modes
Three types of MQTT connections can be configured via the sensor’s System Settings:
- Unencrypted MQTT: Plain TCP connection without encryption.
- Encrypted MQTT (without CA file): Encrypted connection using a server certificate, but without verifying its authenticity.
- Encrypted MQTT (with CA file): Full TLS encryption with certificate validation using a CA file. This is the recommended and most secure option.

Address, port, and authentication parameters for the broker must be configured in the sensor's System Settings.
Example Configuration
- Broker Address:
mqtt://192.168.1.101 - Topic:
balluff/D800006154060385/diagnostics - QoS:
1 - Payload: JSON format
{<br /> "timestamp": "2021-03-24T10:44:36.130",<br /> "type": "diagnostics",<br /> "data": {<br /> "totalOperatingHours": {<br /> "value": 0,<br /> "unit": "h"<br /> },<br /> "currentOperatingHours": {<br /> "value": 0,<br /> "unit": "h"<br /> },<br /> "bootCycles": 3,<br /> "currentInternalTemperature": {<br /> "value": 45,<br /> "unit": "°C"<br /> },<br /> "sensorSupplyVoltage": {<br /> "value": 23.8700008392334,<br /> "unit": "V"<br /> },<br /> "vibrationLevel": {<br /> "value": 0.06835520267486572,<br /> "unit": "mm/s"<br /> },<br /> "inclinationDeviationValue": {<br /> "value": 95,<br /> "unit": "°"<br /> },<br /> "humidity": {<br /> "value": 37,<br /> "unit": "%"<br /> },<br /> "health": "NORMAL_0"<br /> }<br />}
Topic Structure
The sensor publishes data to a topic hierarchy using its serial number as part of the topic name. For example:
balluff/D800005521200115/inspection/resultballuff/D800005521200115/diagnosticsballuff/D800005521200115/identification
You can also use MQTT wildcards to subscribe to a range of topics:
balluff/+/diagnostics/temperature– all sensors, diagnostics temperatureballuff/#– all messages from any sensor+/+/inspection/#– all inspection results from all BVS sensors
Note: ReplaceSERIALNUMBERwith your sensor's actual ID (e.g.D800006154060385) in all topic paths.
3. MQTT to mySCADA with Node.js
This example demonstrates a basic MQTT client written in Node.js, which subscribes to selected topics from a BVS0060 sensor and stores incoming JSON messages. On request, the latest message can be returned to mySCADA for display purposes.
Installing Dependencies
Only the mqtt package is required. Install it using:
npm install mqtt
Sample Script
This Node.js script connects to the MQTT broker at 192.168.10.202 and listens to relevant topics for the sensor with serial D800000000000067.
const mqtt = require('mqtt');
const myscada = require('./myscada');
myscada.init();
const camSerialNr = 'D800000000000067';
const client = mqtt.connect('mqtt://192.168.10.202:1883');
// Variables to store latest data
let identification = {};
let diagnosticsData = {};
let visionStatus = {};
let visionResultsData = {};
let resultsID = {};
client.on('connect', () => {
console.log('Connected to MQTT broker');
// Subscribe to topics
const topics = [
'balluff/' + camSerialNr + '/identification',
'balluff/' + camSerialNr + '/diagnostics',
'balluff/' + camSerialNr + '/vision/status',
'balluff/' + camSerialNr + '/vision/inspection/results',
'balluff/' + camSerialNr + '/vision/inspection/id'
];
topics.forEach(topic => {
client.subscribe(topic, { qos: 0 }, (err, granted) => {
if (err) {
console.error('Subscription error:', err);
} else {
console.log('Subscribed to', granted[0].topic);
}
});
});
});
// Handle incoming messages
client.on('message', (topic, message) => {
const payload = message.toString();
if (topic.endsWith('/identification')) {
identification = payload;
} else if (topic.endsWith('/diagnostics')) {
diagnosticsData = payload;
} else if (topic.endsWith('/vision/status')) {
visionStatus = payload;
} else if (topic.endsWith('/vision/inspection/results')) {
visionResultsData = payload;
} else if (topic.endsWith('/vision/inspection/id')) {
resultsID = payload;
}
console.log(`[MQTT] ${topic}: ${payload}`);
});
mySCADA Communication
mySCADA queries the data through myscada.dataFromViewScripts(). The script returns the relevant MQTT message depending on the button clicked in the UI:
myscada.dataFromViewScripts = function (data, callback) {
if (data.id === "getDataBVS" && data.buttons === 10) {
callback(identification);
} else if (data.id === "getDataBVS" && data.buttons === 11) {
callback(diagnosticsData);
} else if (data.id === "getDataBVS" && data.buttons === 12) {
callback(visionStatus);
} else if (data.id === "getDataBVS" && data.buttons === 13) {
callback(visionResultsData);
} else if (data.id === "getDataBVS" && data.buttons === 14) {
callback(resultsID);
} else {
callback('Unknown command');
}
};
Purpose
This script is designed for quick prototyping and display of live sensor data in mySCADA views. It is not intended for persistent storage or production use.
You can now bind SCADA buttons to send the correct id and buttons values to the Node.js backend and receive updated data for display.
4. Result
Once the data is successfully received from the BVS0060 sensor via MQTT, we can visualize it in the mySCADA interface. One of the most important MQTT topics for this integration is:
balluff/<serial_number>/vision/inspection/results
This topic typically returns a JSON payload with the latest result of a vision inspection. A typical message might look like this:
{
"timestamp": "2025-06-03T12:00:00Z",
"result": "OK",
"object_id": 5
}
Understanding the Fields
timestamp– time of the inspection resultresult– pass/fail status ("OK", "NOK", etc.)object_id– ID or index of the detected object
Displaying Results in mySCADA
The script described in the previous section makes this data available via:
myscada.dataFromViewScripts
To show inspection results in mySCADA:
- Create a new button or data element in the view.
- Configure the element to call the Node.js script with:
id = "getDataBVS"buttons = 13
- Bind the response (the JSON object) to text fields, indicators, or graphical elements.
- Use scripting logic to change colors, show/hide objects, or trigger alarms based on values like
result = "NOK".
Example Usage
In the SCADA screen, a user might press a "Refresh Results" button. The button sends the query with button ID 13. The Node.js script responds with the latest MQTT payload, and mySCADA shows:
- Result: OK
- Object ID: 5
- Timestamp: 12:00:00