Connecting a BVS0060 Vision Sensor to mySCADA via REST API using Node.js
1. Introduction & Requirements
This tutorial demonstrates how to integrate a Balluff BVS0060 vision sensor with mySCADA using its built-in REST API and a Node.js script. The sensor exposes HTTP endpoints that allow reading status, diagnostics, inspection results, and other information without needing MQTT.
What You’ll Need:
- BVS0060 vision sensor (Balluff), with REST API enabled
- Node.js environment
- Access to your mySCADA system (license is necessary for scripting)
- Basic knowledge of HTTP requests and JavaScript
2. Sensor setup
The BVS0060 sensor provides a local HTTP API accessible via its IP address. This interface allows reading:
- Sensor identification
- Vision status and results
- Diagnostic information (temperature, voltage, vibration, etc.)
- System time and firmware versions
Example REST Endpoints:
/api/balluff/v1/identification/api/balluff/v1/vision/status/api/balluff/v1/vision/inspection/results/api/balluff/v1/diagnostics
Make sure the sensor IP address is reachable from the machine running Node.js. You can test it by opening the endpoint in a browser:
http://192.168.10.2/api/balluff/v1/identification
3. REST to mySCADA with Node.js
In this section, we implement a Node.js bridge between the REST API of the BVS0060 sensor and the mySCADA interface. The script will periodically poll the REST API and store the latest data in memory. On request from mySCADA, specific data can be returned and visualized.
Installing Dependencies
Install the required HTTP client library:
npm install axios
How It Works
- The Node.js script connects to the sensor’s REST API using
axios. - It polls selected endpoints every 5 seconds and stores the data in memory.
- mySCADA sends a query to the script (e.g. on button press).
- The script responds with the latest cached data from memory.
Script: REST Polling Logic
This part handles the communication with the sensor:
const axios = require('axios');
const camIP = 'http://192.168.10.2';
let identification = {};
let diagnostics = {};
let visionStatus = {};
let visionResults = {};
const readData = async (endpoint) => {
try {
const res = await axios.get(camIP + endpoint);
return res.data;
} catch (error) {
console.error(`Error reading ${endpoint}:`, error.message);
return null;
}
};
const pollSensor = async () => {
identification = await readData('/api/balluff/v1/identification');
diagnostics = await readData('/api/balluff/v1/diagnostics');
visionStatus = await readData('/api/balluff/v1/vision/status');
visionResults = await readData('/api/balluff/v1/vision/inspection/results');
};
setInterval(pollSensor, 5000);
Script: Integration with mySCADA
This part allows the SCADA environment to request specific cached data using myscada.dataFromViewScripts:
const myscada = require('./myscada');
myscada.init();
myscada.dataFromViewScripts = function (data, callback) {
if (data.id === "getDataRestAPI" && data.buttons === 0) {
callback(identification);
} else if (data.id === "getDataRestAPI" && data.buttons === 7) {
callback(diagnostics);
} else if (data.id === "getDataRestAPI" && data.buttons === 6) {
callback(visionStatus);
} else if (data.id === "getDataRestAPI" && data.buttons === 8) {
callback(visionResults);
} else {
callback('Unknown command');
}
};
Button Mapping Example
In mySCADA, assign buttons to send the following values to query the script:
- Button 0 → Identification
- Button 6 → Vision Status
- Button 7 → Diagnostics
- Button 8 → Vision Results
Purpose
This setup is lightweight and does not require any broker or subscription. It’s ideal when REST is preferred due to infrastructure or security constraints. All requests remain within the local network and no persistent storage is needed for basic monitoring.
4. Results
The most relevant REST endpoint for visual inspection results is:
/api/balluff/v1/vision/inspection/results
This returns a JSON object with details such as:
{
"timestamp": "2025-06-03T12:00:00Z",
"result": "OK",
"object_id": 5
}
Understanding the Fields:
- timestamp: when the inspection occurred
- result: pass/fail result (e.g. OK/NOK)
- object_id: ID of the recognized object
Displaying in mySCADA:
- Create a button in the SCADA view
- Send a query to Node.js with:
id = "getDataRestAPI"buttons = 8
- Bind the returned JSON to indicators or text labels
- Add logic to highlight or alarm on failure results
