0% found this document useful (0 votes)
103 views24 pages

Application Using The OPC UA Server As Interface To A Website en

This document describes using an OPC UA server interface to connect a website to machine data. It provides an overview of the solution, describing the core functionality of using an OPC UA client on an external computer to access data from the OPC UA server and display it on a website. It also covers the hardware and software components used, basics of OPC UA and how it works, and steps for installing and commissioning the OPC UA server and external computer.

Uploaded by

Stek Labs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views24 pages

Application Using The OPC UA Server As Interface To A Website en

This document describes using an OPC UA server interface to connect a website to machine data. It provides an overview of the solution, describing the core functionality of using an OPC UA client on an external computer to access data from the OPC UA server and display it on a website. It also covers the hardware and software components used, basics of OPC UA and how it works, and steps for installing and commissioning the OPC UA server and external computer.

Uploaded by

Stek Labs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Application description  12/2016

Using the OPC UA server as


interface to a website
SINUMERIK 828D / 840D sl, SW 4.7 SP2 / OPC UA

https://support.industry.siemens.com/cs/ww/en/view/109742294
Warranty and liability

Warranty and liability

Note The application examples are not binding and do not claim to be complete
regarding the circuits shown, equipment and any other eventuality. The
application examples do not represent customer-specific solutions. They are only
intended to provide support for typical applications. You are responsible for
ensuring that the described products are used correctly. These application
examples do not relieve you of the responsibility to use safe practices in
application, installation, operation, and maintenance. When using these
application examples, you recognize that we cannot be made liable for any
damage/claims beyond the liability clause described. We reserve the right to
make changes to these application examples at any time without prior notice.
If there are any deviations between the recommendations provided in these
application examples and other Siemens publications – e.g. catalogs – the
contents of the other documents have priority.

We do not accept any liability for the information contained in this document.

Any claims against us – based on whatever legal reason – resulting from the use of
the examples, information, programs, engineering and performance data, etc.
described in this application example, shall be excluded. Such an exclusion shall
not apply in the case of mandatory liability, e.g. under the German Product Liability
Act ("Produkthaftungsgesetz"), in case of intent, gross negligence or injury of life,
 Siemens AG 2016 All rights reserved

body or health, guarantee for the quality of a product, fraudulent concealment of a


deficiency or breach of a condition which goes to the root of the contract
("wesentliche Vertragspflichten"). The damages for a breach of a substantial
contractual obligation are, however, limited to the foreseeable damage, typical for
the type of contract, except in the event of intent or gross negligence or injury to
life, body, or health. The above provisions do not imply a change in the burden of
proof to your detriment.

Any form of duplication or distribution of these application examples or excerpts


thereof is prohibited without the express consent of Siemens Industry Sector.

Security Siemens provides products and solutions with industrial security functions that
informa- support the secure operation of plants, solutions, machines, equipment, and/or
tion networks. They are important components in a holistic industrial security
concept. With this in mind, Siemens' products and solutions undergo continuous
development. Siemens recommends strongly that you regularly check for
product updates.
For the secure operation of Siemens products and solutions, it is necessary to
take suitable preventive action (e.g. cell protection concept) and integrate each
component into a holistic, state-of-the-art industrial security concept. Third-party
products that may be in use should also be considered. For more information
about industrial security, visit http://www.siemens.com/industrialsecurity.
To stay informed about product updates as they occur, sign up for a product-
specific newsletter. For more information, visit
http://support.automation.siemens.com.

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 2
Table of contents

Table of contents
Warranty and liability ................................................................................................... 2
1 Task ..................................................................................................................... 4
1.1 Overview............................................................................................... 4
1.2 Preconditions ........................................................................................ 4
2 Solution............................................................................................................... 5
2.1 Overview............................................................................................... 5
2.2 Description of the core functionality ..................................................... 6
2.3 Hardware and software components ................................................... 8
2.3.1 Validity .................................................................................................. 8
2.3.2 Components used ................................................................................ 8
3 Basics ............................................................................................................... 10
4 Principle of operation ...................................................................................... 11
4.1 General overview ............................................................................... 11
4.2 Functionality OPC UA Client .............................................................. 12
4.2.1 Program details for MachineConnection ............................................ 12
4.2.2 Program details for JDBC_PSQL ....................................................... 12
4.2.3 Configuring information ...................................................................... 13
4.3 Functionality of the web site ............................................................... 13
5 Installing and commissioning ........................................................................ 14
 Siemens AG 2016 All rights reserved

5.1 Commissioning the OPC UA server ................................................... 14


5.2 Commissioning the external computer ............................................... 16
5.2.1 Creating the OPC UA client................................................................ 16
5.2.2 Commissioning the external computer using the appliance
provided .............................................................................................. 17
5.2.3 Commissioning the external computer without the preconfigured
Appliance ............................................................................................ 18
5.3 Adapting the website template ........................................................... 19
6 Additional notes ............................................................................................... 22
7 Related literature ............................................................................................. 23
8 Contact.............................................................................................................. 24
9 History............................................................................................................... 24

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 3
1 Task
1.1 Overview

1 Task
1.1 Overview
Introduction
The objective of this application is to display SINUMERIK data at a web user
interface. Access should be from a PC as well as from a tablet. The implemented
OPC UA server of SINUMERIK serves as interface.

1.2 Preconditions
 SINUMERIK 840D sl or SINUMERIK 828D
– SW > 4.7 SP 2
– Option, Access MyMachine /OPC UA
 External computer (in this example, Ubuntu 16.04 LTS server)
– With web server (in this example, Apache web server)
– With database system (in this example, PostgreSQL)
 Siemens AG 2016 All rights reserved

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 4
2 Solution
2.1 Overview

2 Solution
2.1 Overview
Schematic
The following schematic diagram shows the most important components of the
solution:

Fig. 2-1 Infrastructure used when employing the OPC UA server as interface to a website
 Siemens AG 2016 All rights reserved

SINUMERIK controls are connected to an external computer via the company


network interface X130. The SINUMERIK OPC UA server must be activated at this
interface. This application description does not go into any more detail as to how
this OPC UA server is commissioned.
The OPC UA client is started when the external computer boots. This forms an
interface between the SINUMERIK control systems and a database. From the
database, the OPC UA client reads with which machines it should communicate -
and which data is to be transferred.
This data is subsequently written to the database. The data can be read from the
web server, and used for display on the web site.

Advantages
The following advantages are obtained from the solution described here:
 Machine parameters can be displayed at a web site
 Several machines can be displayed on one page
 An integrated job list is available for each machine.

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 5
2 Solution
2.2 Description of the core functionality

Limitations
This application does not contain a description of:
 Commissioning the OPC UA server of SINUMERIK
It is assumed that readers have basic knowledge of these topics.

Knowledge required
Readers should have basic knowledge about these areas:
 Adapting the OPC UA client: Java
 Adapting the web site:
– Java script
– HTML
– CSS
– PHP
– Apache
– SQL
 Network configuration
 Siemens AG 2016 All rights reserved

2.2 Description of the core functionality


Overview and description of the user interface

Figure 2-2 Start screen of the web template

The machine image data are displayed on the start page of the web site template.
The background color indicates whether a connection to the specified machine

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 6
2 Solution
2.2 Description of the core functionality

exists.
A green screen indicates that an error-free connection exists. A red screen signals
that a fault exists - or that there is no connection. Such a container should be
assigned to each connected machine. The machine name is in the header. A
navigation bar is created in the footer.

Figure 2-3 Interrogating the status of the machine door


 Siemens AG 2016 All rights reserved

Screens/displays can be changed using PLC inputs. Such an application is, for
example, querying the status of the machine door (open = 1.0/ closed = 1.1).

Figure 2-4 Directly writing SINUMERIK variables

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 7
2 Solution
2.3 Hardware and software components

Using the screen form "Write Variables" you can directly write data to SINUMERIK.
As a consequence, it is possible to write data to fixed addresses, as well as to first
select the address to be written to on the website.

Figure 2-5 Form for pending jobs


 Siemens AG 2016 All rights reserved

The still pending jobs are shown in the "Jobs" screen form. The oldest (still not
executed) job can be transferred to the machine using a defined trigger. However,
each of these pages only serves as a template, and can be adapted to each
machine when the system is commissioned.

2.3 Hardware and software components


2.3.1 Validity

This application is valid for SINUMERIK 828D and 840D sl from software
version 4.7 SP 2.

2.3.2 Components used

The application was created using the following components.

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 8
2 Solution
2.3 Hardware and software components

Components
Table 2-1
Component Qty. Article number Note
SINUMERIK 828D 1 6FC5370-7AA30-0AA0 Alternatively, a SINUMERIK
840D sl can be used.

Option, Access 1 6FC5800-0AP67-0YB0


MyMachine /OPC
UA
Virtual machine 1 Ubuntu 16.04.1 LTS with 2GB
running on a PC in RAM and 8 GB HDD
the network

Sample files and projects


The list below contains all the files and projects used in this example.

Table 2-2
Component Note
workspace_OPCUAClient.zip Java Projekt of the OpcDbClients
for the IDE eclipse
 Siemens AG 2016 All rights reserved

AppNoteOPCUAClient.pdf This document.

WebsiteTemplate.zip Template for the website:

OpcUaDb.ova Import file for a preconfigured virtual


machine

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 9
3 Basics
2.3 Hardware and software components

3 Basics
An OPC UA server is connected with a SINUMERIK. Independent of the
SINUMERIK user concept, users can be created this server.
The necessary read and write authorizations must be issued to the OPC UA client
user. See the SINUMERIK documentation for OPC UA.
For security reasons, we recommend that the administrator user names are
changed - and that a standard password is not used, as access is possible via the
network.
A SINUMERIK variable is accessed via the OPC UA server using node points. The
addresses of the node points correspond to the OPI notation of SINUMERIK. This
means, accessing R parameter 0 is realized via address
/Channel/Parameter/R[u1,0].
 Siemens AG 2016 All rights reserved

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 10
4 Principle of operation
4.1 General overview

4 Principle of operation
4.1 General overview
Fig. 4-1 Principle of operation of a OPC UA server as interface to a web site

OPC UA OPC UA
Database Website
server client

In the js/init.js JavaScript file, a data set is created for each control to be
monitored. As a minimum, each machine must be assigned a unique name and the
associated IP address - as well as two bit addresses for the job list.
This means that a trigger is used to transfer the job - and another to acknowledge
the successful production. These data sets are transferred in the machines table
of the database. In addition, a table is created for each machine that defines which
data is to be cyclically read from the SINUMERIK.
This table starts with recreate_ followed by the machine name. A data set is
inserted in this for each datum, which specifies the address for the excess and the
associated data type. Further, a table is created for the machine jobs (assuming
 Siemens AG 2016 All rights reserved

that this is still not available - or the job the structure has changed). The OPC UA
client evaluates the machines table, and attempts to establish a connection with
each machine.
The user name and the password for the OPC UA server login are defined in the
source code of the Java application. Once the OPC UA client has established a
connection to a machine, then the data from the machine - defined in the
create_table - are cyclically read out, and the values of this data transferred to
table read_.
A table such as this is assigned to every machine. Using a PHP script, this table
can be read out and therefore displayed on the website.

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 11
4 Principle of operation
4.2 Functionality OPC UA Client

4.2 Functionality OPC UA Client

Fig. 4-2 Functional principle of the OPC UA client

The OPC UA client was developed with Java in the Eclipse programming
environment. Class OpcDbClient manages the connections to the machine.
Database access is realized using class JDBC_PSQL. Class MachineConnection
manages the tasks for an individual machine.

4.2.1 Program details for MachineConnection


 Siemens AG 2016 All rights reserved

In this particular class, create_table is read out, and table read_is created. The
actual SINUMERIK data are archived in this table for a period of two days,
assuming that the structure does not change. With this class, a check is made as
to whether a new entry for writing exists in the write_table. This entry is transferred
to SINUMERIK if this is the case. Further, the objects of this class are responsible
for handling the job.

4.2.2 Program details for JDBC_PSQL

If, for an application, another database is to be used, then another interface must
be used. In addition, all SQL commands should be checked as to whether these
are supported by the reference database, and the desired performance is reached.

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 12
4 Principle of operation
4.3 Functionality of the web site

4.2.3 Configuring information

The OPC UA server login that is used is defined in the OpcDbClient Class. This
must be adapted.

Fig. 4-3 Defining the server login

4.3 Functionality of the web site


Users can adapt the web site to address their individual requirements. When
calling the page, using JavaScript, an initialization process is initiated, which
analyzes the HTML file.
 Siemens AG 2016 All rights reserved

A Container Element with the unique name as ID should be created in the HTML
for each machine. The data of this machine is displayed in this. When analyzing
the HTML, all elements whose ID are executed according to the following
schematic, are checked.

NameDerMaschine_node address
If, for these elements, the access attribute has the value TRUE, then these node
addresses are transferred into the create_ table.
The web site data are refreshed every 250ms using AJAX. In this case, the
read_table is read out using a PHP script, and the data values are transferred into
the innerText part of the element mentioned above. Based on these values, it is
then also possible to change web site screens.
If an HTML element has the id NameDerMaschine_jobform, then it is assumed that
it involves a FORM element. All Input elements are analyzed, and with the name, a
task table is created in the database. If a name starts with a slash, then this is
identified as OPI address - and is transferred by the OPC UA client into the
machine, assuming that JobTrigger has the value "true".

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 13
5 Installing and commissioning
5.1 Commissioning the OPC UA server

5 Installing and commissioning


This chapter describes the steps that are necessary to commission the example
using the code that has been downloaded and the hardware list.

5.1 Commissioning the OPC UA server


The first step is to commission the OPC UA server of SINUMERIK. Further, an
additional user should be created with the administrator user. This is possible using
the AddUser method.

Fig. 5-1 Tree-like structure of the OPC UA server


 Siemens AG 2016 All rights reserved

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 14
5 Installing and commissioning
5.1 Commissioning the OPC UA server

Fig. 5-2Calling the AddUser function

The user that has been created requires rights in order to be able to access
SINUMERIK data.
The GiveUserAccess method can be used for the call. The following rights are
necessary in order that the website template functions as required:

 StateRead
 StateWrite
 GudWrite
 Siemens AG 2016 All rights reserved

 PlcRead
 PlcWrite

Fig. 5-3 Calling the AddUserAccess function

The password of the user that has been created should be changed after the
necessary rights have been assigned. As default, the password corresponds to the
user name.
A password can be changed using the ChangeMyPassword method. To do this,
the user must be logged on to the server.

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 15
5 Installing and commissioning
5.2 Commissioning the external computer

Fig. 5-4 Calling the ChangeMyPassword function

5.2 Commissioning the external computer


5.2.1 Creating the OPC UA client

Table 5-1 Sequence when creating the OPC UA clients


 Siemens AG 2016 All rights reserved

No. Action
1. Installing the Eclipse programming environment.
2. Defining the workspace and unzipping the Java project.
3. Adapting variables OPCUSER and OPCPASSWORD to the specified OPC UA
server configuration. This is realized in Class
/examples/opcDbClient/OpcDbClient.java
4. Export the configuration as runnable Jar file.
File > Export… > Java > Runnable JAR file

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 16
5 Installing and commissioning
5.2 Commissioning the external computer

5.2.2 Commissioning the external computer using the appliance provided

Table 5-2 Sequence when commissioning the external computer


No.
1. Installing the VirtualBox software (www.virtualbox.org ) on a computer in the
network.
2. Importing file OpcUaDb.ova supplied using the Appliance dialog.
 Siemens AG 2016 All rights reserved

3. Select the machine that has been created after the import. The network
configuration is subsequently adapted via the network.
The host machine is connected with a SINUMERIK using a network bridge to the
network adapter.

4. Start of the machine


5. Then logon with user name manufact and password SUNRISE.

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 17
5 Installing and commissioning
5.2 Commissioning the external computer

No.
6. Command:
sudo nano /etc/network/interfaces
Change the IP address of the network interface to a free address in the network
being used.
Save the file and restart the machine.
Standard IP: 192.168.1.100/24
7. Transfer the runnable Jar file of the OPC UA client to directory/usr/local/bin/.
8. Adapt the website template to the user requirements.

5.2.3 Commissioning the external computer without the preconfigured


Appliance

Table 5-3
No. Action
1. Install a Ubuntu x64 server 16.04.01 LTS on the existing computer in the
network. This is realized by following the instructions displayed on the screen.
2. A connection must be established to the Internet in order that the following
packagesapache2, openssh-server, postgresql, php-pgsql and libapache2-
mod-php. can be installed.
 Siemens AG 2016 All rights reserved

3. Create database manufact and create the database user java, password java,
and website, password web.
If other users or passwords are to be used, then these must also be changed in
the appropriate programs.
User java is used in Class JDBC_PSQL - and user website is used in the PHP
scripts.
4. Install a Java runtime environment. To do this, the software for the operating
system being used must be downloaded from www.Oracle.com. Unzip the. The
content of folder jre1.8.0_* is shifted to directory /opt/Java/.
The following commands are now entered:
sudo update-alternatives --install "/usr/bin/java" "java"
"/opt/Oracle_Java/bin/java" 1
sudo update-alternatives --set "java" "/opt/Oracle_Java/bin/java"
5. Transfer the runnable Jar file of the OPC UA client to directory/usr/local/bin/.
6. By inserting line java –jar /usr/local/bin/OpcDbClient.jar & in file /etc/rc.local,
the client already starts in the background, while the computer being used is
booted.
7. Define the required IP address in the following file/etc/network/infaces.
8. If access to the website is to be restricted using .htaccess, then file
/etc/apache2/.htpasswd must be created, and a valid user name and password
entered. If .htaccess is not to be used, then this file must be removed from the
template.
9. Transfer the template of the website to directory /var/www/html/ - and adapt
this to the individual user requirements.

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 18
5 Installing and commissioning
5.3 Adapting the website template

5.3 Adapting the website template

Fig. 5-5 Tree-like structure of the website template


 Siemens AG 2016 All rights reserved

The website template should be adapted to the required configuration. A variable


machConfiginit.js is declared in file init.js in which the configuration of each
machine to be displayed is defined.
A name and an ip must be assigned for each machine. Further, it is intended that a
"Heartbeat signal" signal is sent to each machine, which it can then evaluate.
Further, the template has a function so that each machine can display whether the
machine door is open or closed, for example.
The appropriate PLC addresses must be specified to do this. If the machine is
equipped with a sensor in the workpiece clamping unit, which allows clamping to
be evaluated, then this can also be displayed.

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 19
5 Installing and commissioning
5.3 Adapting the website template

Fig. 5-6 Machine configuration

Variables jobTrigger and jobFinished must be specified if the joblist function is to


be used. Once the machine has been basically configured, file index.html must be
 Siemens AG 2016 All rights reserved

adapted.
In order that the data can be read from the machine, only an HTML element has to
be created, which has the following attributes:
 The element ID must start with the machine name. This must be followed
by an underscore and then by the OPI notation of the variable.
 Attribute access must have the value true.
 Attribute datatype should be specified corresponding to the database and
the particular variable type.
Such an HTML element, which complies with the requirements, is shown in the
following diagram.

Fig. 5-7Diagram showing an HTML that is used

If operators should be prevented from writing the website data of the SINUMERIK,
then the third content page and the third navigation element should be removed.
For the case that other data are specified than should be written, then this must be
specified in the appropriate form. The form can be copied and adapted as often as
required. It must be ensured that the name of the form element, corresponds to the
machine name, and the name of the input element is the same as the OPI notation
of the machine variable.

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 20
5 Installing and commissioning
5.3 Adapting the website template

If the job list is not to be used, then it is important that the fourth content page and
the fourth navigation element are removed. Otherwise, the job form must be
adapted.
All input elements, whose name is started with a slash, are transferred to the
machine as soon as Jobtrigger has the value true. After the transfer from the
OPC UA client, JobTrigger is set to the false. This allows an evaluation in the PLC
as to when and where new job data has been received.

Adding an additional machine to the website


An additional object must be inserted into the machConfig Java script array if
more than one machine is to be simultaneously displayed on the website.
The container element of the first machine must then be copied to file index.html
and inserted a second time. All references to the name of the machine and to the
name of the second machine must be changed.
As a minimum, this involves the following objects:
 The <div> element with class="box"
 The <h1> element within the box.
 All elements whose ID starts with the machine name.
 All <form> elements, whose name has the machine name.
 Siemens AG 2016 All rights reserved

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 21
6 Additional notes
5.3 Adapting the website template

6 Additional notes
The function of a marker (bit memory) is available when using this template. This
means that the website notes which navigation element of each machine was
opened at the last call, and reactivates this when the website is called.
To operate a terminal element with the touch function, a "swipe gesture" is
implemented, which allows you to navigate between the pages. By clicking on a
data set of the job list, this is marked, and a prompt is displayed that allows this
data set to be deleted. The OPC UA client writes its output messages to
file/tmp/OpcDbClientOut.tmp . The error messages can be found in
file/tmp/OpcDbClientError.tmp.
 Siemens AG 2016 All rights reserved

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 22
7 Related literature
5.3 Adapting the website template

7 Related literature
Table 7-1
Topic
\1\ Siemens Industry Online Support
https://support.industry.siemens.com
\2\ https://support.industry.siemens.com/cs/ww/en/view/109742294
https://support.industry.siemens.com/cs/ww/en/view/109742497

\3\
 Siemens AG 2016 All rights reserved

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 23
8 Contact

8 Contact
Siemens AG
Industry Sector
DF MC MTS PPM
Frauenauracher Strasse 80
91056 Erlangen
Germany
mailto: [email protected]

9 History
Table 9-1
Version Date Revision
V1.0 12/2016 First edition
 Siemens AG 2016 All rights reserved

Using of OPC UA as an interface


Entry ID: 109742294, V1.0, 12/2016 24

You might also like