Project1 Document
Project1 Document
1
Click the Apply button to confirm
PART 4: JAVASCRIPT MANAGER FOR NODE.JS
Initial Setup:
Creat a new project — Example: SCADA\P hongSon
Access to path C:\WinCC\O AnP rojnSCADAnP hongSonnjavascriptcreateaf olderP ublisher
Open Visual Studio Code =¿ open folder Publisher
In the terminal ( Ctrl + Shift + ‘) :
Run “npm init -y” ; a new file package.json will be created
Run “npm install –save-dev C:\Siemens\Automation\WinCC\O An3.20njavascriptnwinccoa−
manager”toinstallrequiredmodulesincludingapathtothe\winccoa − manager”
Create a file “index.js” in folder Publisher, which is also where we will write
our code
Create a Javascript manager:
Add a Javascript manager to the console with the path of index.js and Set
Start mode to manual
Code Analysis: Getting Data from WINCC OA and Publishing to MQTT
Strict Mode and Imports
’use strict’;
const \ WinccoaManager \ = require(’winccoa-manager’);
const winccoa = new WinccoaManager();
MQTT Broker Configuration
const brokerUrl = ’mqtt://192.168.1.9:1883’;
const client = mqtt.connect(brokerUrl);
MQTT Connection Event Handler
client.on(’connect’, function() \
console.log(’Connected to MQTT broker’);
setInterval(getValuesAndPublish, 5000);
\);
Getting values and publishing to MQTT:
Exception Handling of the WinCC OA JavaScript Manager for Node.js
Publishing Data to MQTT
PART 5: MQTT CONFIGURATION
1. Setting Up an MQTT Broker on Windows:
Step 1: Download and Install Mosquitto:
Go to the official Mosquitto website: .
Download the Windows installer and follow the installation prompts.
Step 2: Configure Mosquitto for Anonymous Access:
Locate the mosquitto.conf configuration file, usually in the installation di-
rectory
(e.g., C:\Program Files\mosquitto\mosquitto.conf).
Open mosquitto.conf in a text editor.
Add the following lines to allow anonymous access:
Step 3: Test the Mosquitto Broker:
Open a New Command Prompt:
Run the following command to subscribe to a test topic
mosquitto\s ub − hlocalhost − ttest/topic
2
Publish a Message:
mosquitto\p ub − hlocalhost − ttest/topic − m”HelloM QT T ”
Connecting WinCC OA to the MQTT Broker
Once you have successfully created an MQTT broker, you can proceed to
connect it with the MQTT client in WinCCOA
Step 1: Append the MQTT Client Manager:
Step 2: Create a Data Point for MQTT:
Create datapoint DP\M QT T : \SystemM anagement > Driver > M QT T Client”
Figure: Configuration panel of the MQTT driver
Step 3: Defining the peripheral adress
Click on the \a ddressconf igof adatapointelement, selectthedriverM QT T CLIEN T andclickonConf igu
Figure: Definition of a peripheral address
Figure “MQTT Eplorer” and “Panel simulor Sine Sim”
Question : How can we deploy a webserver ?