Application Using The OPC UA Server As Interface To A Website en
Application Using The OPC UA Server As Interface To A Website en
https://support.industry.siemens.com/cs/ww/en/view/109742294
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
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.
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
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
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
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.
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
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
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.
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).
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.
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.
This application is valid for SINUMERIK 828D and 840D sl from software
version 4.7 SP 2.
Components
Table 2-1
Component Qty. Article number Note
SINUMERIK 828D 1 6FC5370-7AA30-0AA0 Alternatively, a SINUMERIK
840D sl can be used.
Table 2-2
Component Note
workspace_OPCUAClient.zip Java Projekt of the OpcDbClients
for the IDE eclipse
Siemens AG 2016 All rights reserved
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
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.
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.
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.
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.
The OPC UA server login that is used is defined in the OpcDbClient Class. This
must be adapted.
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".
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
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.
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
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.
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.
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.
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.
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.
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.
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
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
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