Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
SIMATIC S7-1200 /
S7-1500 Web Server
Note The Application Examples are not binding and do not claim to be complete
regarding the circuits shown, equipping and any 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,
body or health, guarantee for the quality of a product, fraudulent concealment of a
Siemens AG 2017 All rights reserved
Security Siemens provides products and solutions with industrial security functions that
informa- support the secure operation of plants, systems, machines and networks.
tion In order to protect plants, systems, machines and networks against cyber
threats, it is necessary to implement and continuously maintain a holistic,
state-of-the-art industrial security concept. Siemens products and solutions only
form one element of such a concept.
Customer is responsible to prevent unauthorized access to its plants, systems,
machines and networks. Systems, machines and components should only be
connected to the enterprise network or the internet if and to the extent necessary
and with appropriate security measures (e.g. use of firewalls and network
segmentation) in place.
Additionally, Siemens guidance on appropriate security measures should be
taken into account. For more information about industrial security, please visit
http://www.siemens.com/industrialsecurity.
Siemens products and solutions undergo continuous development to make them
more secure. Siemens strongly recommends to apply product updates as soon
as available and to always use the latest product versions. Use of product
versions that are no longer supported, and failure to apply latest updates may
increase customers exposure to cyber threats.
To stay informed about product updates, subscribe to the Siemens Industrial
Security RSS Feed under http://www.siemens.com/industrialsecurity.
Table of Contents
Warranty and Liability ................................................................................................. 2
1 Preface ................................................................................................................ 5
2 Hardware and Software Components Used .................................................... 6
3 Basics of Standard Web Pages ........................................................................ 8
4 Basics of User-Defined Web Pages ................................................................. 9
4.1 Login and instructions for use .............................................................. 9
4.2 Web server initializing the WWW system function ............................ 9
4.3 Libraries jQuery and S7 Framework ............................................... 10
5 Reading and Writing with different Variable Types ..................................... 12
5.1 Automation task .................................................................................. 12
5.2 Functional mechanisms and use ........................................................ 13
5.2.1 S7 program structure.......................................................................... 15
5.2.2 User-defined web page (HTML file) structure .................................... 16
6 Displaying the Date and Time ........................................................................ 19
6.1 Automation task .................................................................................. 19
6.2 Functional mechanisms and use ........................................................ 19
6.2.1 S7 program structure.......................................................................... 20
Siemens AG 2017 All rights reserved
1 Preface
Objective of the application examples
The application examples in this document show you how to extend your own web
pages on the S7-1200/1500 web server.
This document describes the examples provided for downloading. It is
recommended to run the examples on a computer and simultaneously analyze
them with the aid of this document.
Advantages
Integrated web server in the S7-1200 and S7-1500
The standard web pages for easy display of service and diagnostic information are
enabled with a single click.
In addition, you can create custom, user-defined web pages that are referred to
below as user-defined pages.
Access from anywhere
A web browser allows you to access the S7 web pages from anywhere in the
world.
Application example
Universal use of the application example for the SIMATIC S7-1200 and S7-1500.
Benefits
No additional hardware and software required. The web server can be accessed
over large distances using mobile communications devices such as tablet
computers, smartphones, etc.
Note The application examples in conjunction with the web server should not and
cannot replace an HMI system.
Hardware components
Table 2-1: Hardware components used for the examples
Component No. Order no. Note
CPU 1511-1 PN 1 6ES7511-1AK01-0AB0 Firmware V2.0.5
PG/PC 1 - -
with Ethernet interface
Note For these application examples, you need the current CPU firmware version.
Siemens AG 2017 All rights reserved
Depending on the CPU type, the following entries provide related links to the
appropriate downloads:
S7-1500: https://support.industry.siemens.com/cs/ww/en/view/78301349
S7-1200: https://support.industry.siemens.com/cs/ww/en/view/107539750
Software components
Table 2-2: Software components used for the examples
Component No. Order no. Note
SIMATIC STEP 7 1 6ES7822-1AA04-0YE5 V14.0 (Update 2)
Professional V14
Software tool for creating 1 - Web pages created
HTML files such as with Notepad++
FrontPage, Notepad++,
Web browser such as 1 - Created and tested
Internet Explorer, Mozilla with IE11 and Firefox
1)
Firefox
1)
The following web browsers were tested for communication with the CPU:
Internet Explorer (version 11)
Mozilla Firefox (version 50)
Note The application examples are optimized for Firefox and IE11.
Using other browsers may require changes regarding their display in the
browser.
Overall structure
The individual application examples consist of an S7 program running on an S7-
1200/1500 and a web page running on the integrated web server of the S7.
Exceptions are the examples in Chapter 13 and 15 that show general web
functions without an S7 program.
The web pages are opened using a web browser and consist of an HTML file as a
basis.
More complex examples include additional JavaScript files with the js file
extension.
Industrial Ethernet
Browser
S7-1500 S7-1200
Siemens AG 2017 All rights reserved
CPU certificate
If the browser reports a certificate error, proceed as described in the following FAQ:
Siemens AG 2017 All rights reserved
https://support.industry.siemens.com/cs/ww/en/view/63314183
The login input fields are located in the top left corner of each standard web page
of the S7-1200/1500 controller.
OB 1.
This block call is described in all examples, including the reference to this chapter.
No. Function
1 The WWW system function (SFC 99) is called in OB1.
This function initializes the CPU web server.
Cyclically calling the function in OB1 allows interaction between the web server
and the controller.
The Web DB (DB 333) is connected to the WWW function. The Web DB and the
Fragment DB(s) store the structure of the user-defined pages.
2 More instructions and block calls are described in the respective application
examples.
Note For basic information about generating data blocks for user-defined pages,
please refer to the First steps of the following entry:
https://support.industry.siemens.com/cs/ww/en/view/68011496
Integrate the jQuery library and the appropriate JavaScript files that access or use
this jQuery library into your HTML base document. For example, the S7
Framework JavaScript file uses the jQuery library; in the HTML code, it is
therefore below the call of the jQuery library.
Example:
jQuery.post(URL, DATA)
$.post(URL, DATA)
S7_framework.js
The JavaScript file contains a number of functions for converting and processing
data from a SIMATIC S7-1200/1500.
The S7 Framework programming uses elements from the jQuery library. Therefore,
in the HTML code, always call the S7 Framework after the jQuery library.
There are separate application examples for the S7-1200 and the S7-1500
controller. Both controllers access the same web files.
However, depending on the CPU, access to the default web server differs in terms
of IDs, login and other functions. A controller type check is therefore implemented
in the examples.
Note In the code, you will find information about the functions.
A detailed description of the functions is not the subject of this guide.
1
4 2 3 4
Siemens AG 2017 All rights reserved
3 1 2
1
This link takes you to the HTML web page with the special variables,
Reading special variables.
2 This column displays the current values of the variables.
3 The value to be written is entered in this column.
4 The Write buttons transfer the values to the CPU.
Table 5-2: Instructions for using the user-defined page
Step Instruction
1 In the New Value column, enter a value corresponding to the data type.
2 Click the Write button.
3 The value appears in the Current Value column.
4 Click this link if you want to open the Reading special variables web page.
The following figure shows the structure of the user-defined page for reading
special variables.
2 3
Siemens AG 2017 All rights reserved
DB1 SFC 99
TestDB WWW
DB2
HTTP_Info
Siemens AG 2017 All rights reserved
How OB 1 works
No. Function
1 The first block call in OB 1 is the WWW function (SFC 99).
For more information about the function, please refer to Chapter 4.2.
Contents of DB1
The TestDB (DB1) defines variables that can be read/written using the web page.
Exception: the WWW_RET_VAL variable. This variable contains the return value
of the WWW function.
Contents of DB2
DB2 HTTP_Info stores the special variables; in this case: HEADER_Request
variables.
The user can only read these variables using the web page. These variables are
written using the web page via the web server.
Example :=testBit:
Siemens AG 2017 All rights reserved
Note:
http request variables are global variables within a scripts scope.
The date and time are displayed horizontally and centered on the user-defined
page.
Figure 6-1: User-defined page for displaying the date and time
How OB 1 works
No. Function
1 The first block call in OB 1 is the WWW function (SFC 99).
For more information about the function, please refer to Chapter 4.2.
2 The RD_LOC_T instruction (SFC 154) reads the CPUs time and saves it to the
Clock DB (DB 1) to the time variable.
2 The inline frame (Update_Page.html file) writes the time to this div box.
3 The inline frame must be integrated into the index.html file in order to integrate it
into the functional sequence.
4 The Update_Page.html file specifies which variables are cyclically updated and
where to store them.
(This is implemented using the ID in the JavaScript file and in the HTML code.)
Siemens AG 2017 All rights reserved
Referenced to:
For information about this update method, please refer to the following FAQ:
http://support.automation.siemens.com/WW/view/en/97044123
1 2
DB1
Data
How OB 1 works
No. Function
1 The first block call in OB 1 is the WWW function (SFC 99).
Siemens AG 2017 All rights reserved
For more information about the function, please refer to Chapter 4.2.
3
Siemens AG 2017 All rights reserved
Table 8-1 ENUM user-defined page variable values are replaced with text
Item Description
These buttons allow you to set the alarm variable to a value between 0 and
1
3.
2 This table shows the assignment of the text to the numerical value.
3 This is where the appropriate text is output.
DB1
AlarmVariable
How OB 1 works
No. Function
1 The first block call in OB 1 is the WWW function (SFC 99).
For more information about the function, please refer to Chapter 4.2.
No. Function
1 This DB stores the alarm variable that can be read/written by the user-defined
page.
The variable is modified by the selection of the user-defined page
(here: alarm=0)
4 The assigned text is used when writing the PLC tag. The associated value (digit) is
written to the PLC tag.
2 3
1 1 2
Item Description
1 In this field, enter a new input value.
2 The Check the value button sends the value to the CPU.
If the input value is greater than 100, a new user-defined page opens. In
3
this example, the new user-defined page has red text.
Note If the checked variable is influenced by the controller, the user-defined page has
to be cyclically refreshed. Otherwise, no HTTP redirect will take place.
To go to the home page, set the variable value in TIA Portal to less than 100
and reload the user-defined page.
DB1 FC 1
Data Check
How OB 1 works
No. Function
1 The first block call in OB 1 is the WWW function (SFC 99).
For more information about the function, please refer to Chapter 4.2.
Siemens AG 2017 All rights reserved
2 The Check function determines whether the 100 limit was exceeded.
If this is the case, the headerLocation variable is set to 1 and headerStatus is
set to 302. Due to this, the system switches to the user-defined page with the
error message. If the value was not exceeded, both variables are set to 0.
On the user-defined page, you can change between German and English. To do
this, click the appropriate flag icon.
How OB 1 works
No. Function
1 The first block call in OB 1 is the WWW function (SFC 99).
For more information about the function, please refer to Chapter 4.2.
The diagrammatic overview below shows the basic file structure of the user-defined
pages.
The term i18n that recurs in the following sections stands for a software
development process for implementing the change language option independently
of the actual program code. The term i18n results from internationalization, where
18 stands for the number of letters between i and n.
For efficient programming of the Demo10.js script code and compatible
programming of the function of the user-defined pages across browsers, the jQuery
library for JavaScript is integrated.
jQuery library
from third-party
jquery-2.1.3.min.js
vendor
jQuery function
jquery.cookie.js from third-party
vendor
Demo10.html
The HTML document defines the structure of the user-defined page and the calls of
the JavaScript files used, see Chapter 10.2.2.1.
Throughout the file structure, the language assignment is ensured by the de and
en identifiers.
Demo10.js
Contains the interactive functions used to implement the user inputs, see Chapter
10.2.2.2.
Also defines the behavior of the cookie used. The JavaScript files code syntax is
supported by the jQuery library.
i18n.txt
The i18n.txt text file contains the multilingual text elements, Demo10.html and
the script functions that are called from i18n:0.0.1.js.
i18n.0.0.1.js
Contains the functions for changing the language and transferring the texts with the
specific language from i18n.txt to the HTML document.
jquery.cookie.js
The JavaScript file provides functions for defining and managing cookies.
In this context, the Demo10.js JavaScript file uses these functions and creates or
modifies the existing cookie of the standard web page, see Chapter 10.2.2.2. For
more information about the JavaScript file used here, visit the following web page:
- https://github.com/carhartl/jquery-cookie
o https://github.com/carhartl/jquery-cookie/blob/d72bb07e29962330db61aae1eda07f6312419840/src/jquery.cookie.js
o https://github.com/js-cookie/js-cookie/tree/master/src
The texts are directly in the HTML code and are not translated!
Siemens AG 2017 All rights reserved
The language class with the (data-lang=..) property is assigned to the change
language elements, here, e.g., German.
The (data-lang) property specifies the language the page is to change to.
Note: For other languages, the code section has the same structure.
2 The following code section implements the assignment of the texts to the buttons
and the output field.
Left: elements.button1
Right: elements.button2
Bottom: elements.output
3 When the user clicks an element with (class=language), the (language) property
Siemens AG 2017 All rights reserved
Example:
When the user-defined page is opened for the first time, the value of the
I18n.setLanguage function is applied from the cookie.
If there is no cookie, the language is set to en by default.
4 When clicked, the function outputs the text in the current language based on the
identifying name.
The data-i18n property is set to the current ID, java.output1, so that the text is
translated the next time the language is changed.
5 Note:
For more information about changing texts with JavaScript, please refer to the
Demo10.js files code.
Extending Demo10.html
1. Extend the code section as shown in the figure.
2. In the Images path, provide a reference to the new flag icon (xx.png).
3. Change the text assignment for data-i18n.
2 3
Extending i18n.txt
Add more languages to the i18n.txt text file. The text elements for de and en
are assigned to the appropriate names (e.g., lang.en). As an example of these
names, the following figure shows a code section that must be duplicated if you
want to add a new language. Proceed in the same way to extend the text
elements.
1. Duplicate the code section.
2. Add the new language item to the code section.
3. Change the name to assign the new code section, in this case lang.xx.
AJAX
AJAX (Asynchronous JavaScript and XML) provides a method for exchanging
data asynchronously between a web browser and the web server. Data is
exchanged without reloading the web page itself.
Inline frame
Inline frames allow web pages to be split into segments to separate web contents
from the surrounding web page.
The separated contents are available as independent HTML documents and
displayed by the main web page in a defined browser area with a defined size.
Therefore, the contents of the inline frame refresh simultaneously with the
surrounding page.
Siemens AG 2017 All rights reserved
The difference to AJAX becomes clear in Firefox as the tab displays an icon for
loading the web page and the bottom status pane displays the Waiting
for192.168.0.1 message.
When using AJAX, these messages are not displayed as the web page itself is not
reloaded.
Basic function:
Read the input value for the flow velocity Velocity
Display the level as a bar, depending on the flow velocity.
Requirement for communication between STEP 7 and the user-defined page using AJAX
For the refresh using AJAX to work, integrate the file format with dynamic content
in the CPU settings.
Siemens AG 2017 All rights reserved
.htm;.html;.dat
4
3
3 4
1 1 2 2
Siemens AG 2017 All rights reserved
Table 11-2: User-defined page for reloading pages using AJAX/inline frame
Item Description
11 This is where you enter new values for the flow velocity Velocity.
22 This button transfers the entered value to the controller.
33 Depending on the input value, the bar is filled in blue.
44 This link toggles the user-defined page between inline frame and AJAX.
A restart resets the variables in DB 1 to their start values. When running OB 1, the
user-defined page is refreshed by SFC 99.
Figure 11-5: S7 program for reloading pages using AJAX/inline frame
How OB 1 works
No. Function
1 The first block call in OB 1 is the WWW function (SFC 99).
For more information about the function, please refer to Chapter 4.2.
2 Each OB 1 cycle increments the refValue variable by 1. When the value 2000
is reached, the dynValue variable is increased by 1. This variable of the [Byte]
type scales the level display to 255 steps. If the value is increased by 255+1, the
dynValue variable is reset to 0.
The diagrammatic overview below shows the basic file structure of the user-defined
pages.
This description focuses on the JavaScript files code elements, which makes basic
knowledge of HTML necessary for this application example.
Figure 11-6: Diagrammatic overview of the user-defined page
HTML files
Inline frame
Demo11.html update11.html
Style sheet
Link
demo.css
update.dat
Demo11.html
Defines the structure of the user-defined page and contains the JavaScript
functions for updating the S7 variables using the inline frame. The <Head> of the
user-defined page contains the JavaScript functions.
Demo11_ajax.html
Defines the structure of the user-defined page and contains the JavaScript
functions for AJAX in the user-defined page <Head>.
The PLC tags are updated using the JavaScript functions.
update11.dat
Contains the dynValue and velocity reference variables that are called from the
JavaScript file in Demo11_ajax.html. (DoHttpRequest function).
demo.css
Defines the style sheet for the user-defined pages for AJAX and inline frame.
ajaxbase.js
The JavaScript file contains the functions for communication and data exchange
between different web browsers and web servers.
No. Demo.html
1 The Start function is executed after each page refresh.
ForceUpdate determines the bar length from the HTML document and sends it.
Formatting for Firefox and IE is done for the bar display.
Siemens AG 2017 All rights reserved
3 A form that sends values using a submit button is used for writing the Velocity
value.
No. Demo11_ajax.html
1 The Start function is executed after each page refresh.
OnTimer updates the value of DynValue every 200ms using the DoHttpRequest
function call from this file: ajaxbase.js.
Four values are transferred to the function.
Siemens AG 2017 All rights reserved
When all values have been updated, the UpdateCallback function is called.
No. Demo11_ajax.html
4 The UpdateCallback function processes the read values and the status code.
The response variable contains the updated values of the PLC tags. For
processing in a JavaScript file, the values must be split and reassigned.
The status variable contains the current HTTP status code.
If the HTTP status code is less than 300, the ForceUpdate function is called and
the length of the updated bar is calculated.
Siemens AG 2017 All rights reserved
No. Demo11_ajax.html
5 Selecting the Send via AJAX button calls the send_ajax_request function.
Note In this example, sine and cosine values are cyclically written to the SMC or the
CPUs memory.
Regarding the read/write cycles, please refer to this entry:
https://support.industry.siemens.com/cs/ww/en/view/109482591
Alternatively, you can program a ring buffer for the values that is used to save a
limited number of values and display them in the graph.
Siemens AG 2017 All rights reserved
Figure 12-1: User-defined page for displaying data from a datalog in a line graph
1
2
Siemens AG 2017 All rights reserved
Table 12-1: User-defined page for displaying data from a datalog in a line graph
Item Description
11 Datalog stored on memory card as SinusUndCosinus.csv file
22 Graph displayed on user-defined page (source file: SinusUndCosinus.csv)
3 Button for updating data [Load new data]
OB1
Web server DB 333
Web DB / Main
DB 334
Fragment DB
User-defined pages SFC 99
WWW
DB2 FB 1
ControlCounter Counter
How OB 1 works
No. Function
1 The first block call in OB 1 is the WWW function (SFC 99).
For more information about the function, please refer to Chapter 4.2.
Siemens AG 2017 All rights reserved
2 FB 1 calculates sine and cosine values and creates a datalog. The parameters and
name of the datalog CSV file are written to static variables. The sine and cosine
values are cyclically saved to this datalog.
The status and error code and the input parameter for deleting the datalog content
is stored in DB 2.
The diagrammatic overview below shows the basic file structure of the example.
Libraries from
third-party vendors
jquery-2.1.3.min.js
jquery.flot.min.js
Siemens AG 2017 All rights reserved
jquery.flot. time.min.js
Demo.js
Siemens AG 2017 All rights reserved
The Demo12.js file calls functions from the different libraries to create a graph
from the data of a datalog (CSV file). For information about processing the data,
please refer to the source code.
S7_framework.js
The JavaScript file contains a number of functions for converting and processing
data from a SIMATIC S7.
For more information about the S7 Framework, please refer to Chapter 4.3.
S7_framework.css
Defines the style sheet for the HTML user-defined pages
The src property specifies the respective file path. User-defined pages cannot
directly access a datalog.
2 The datalog CSV files are stored on the standard web page that must be opened
for access.
The PLC type is transferred to the S7 Framework with the following function.
The function name of decodeCSV is the destination for the read values.
3 Datalog (process values)
All time values are converted to [Date.UTC] format and sorted chronologically.
The data is prepared for the graph template and evaluated in the JavaScript file
(jquery.flot.time.min.js).
This function also defines the graph properties.
(For example, connect points, no steps in graph.)
Note This example does not contain a specific S7 program. The display elements do
not explicitly access data of a SIMATIC S7.
You will find the HTML file in the project folder in html_indicatingElements.
The user-defined page shows different display elements that can be modified and
controlled using a slider below the display elements. For connection to an S7,
replace the slider with the appropriate UDP variables.
Figure 13-1: User-defined page with SVG (Scalable Vector Graphics) display elements
Note To extend your application, copy the SVG elements code section directly to your
HTML document. If necessary, replace the input variable of the slider element as
required for your application.
3 stroke=#ff0033
The stroke property specifies the border color/line color of SVG elements.
4 stroke-width=20
The stroke-width property specifies the border thickness/line thickness of SVG
elements.
5 stroke-dasharray=188.25 63.08
The stroke-dasharray property deletes parts of the border or a line of SVG
elements.
The first value specifies the length to be shown. The second value specifies the
length to be deleted. The two lengths alternate on the border/line until they have
circled around the border/reached the end of the line. As a result, you get a dash
border/line.
Note: For circles, the border is the circumference.
It is calculated as follows: 2 * * r.
6 fill=white
The fill property specifies the fill color or font color of the SVG element.
7 transform=rotate(135, 55, 55)
The transform rotate property rotates SVG elements. The first number is the
number of degrees and specifies how far the element will be rotated. The second
and third number specify the point around which the element will be rotated.
8 id=gauge.pointer
The id property assigns an SVG element an ID to be accessed using JavaScript.
</text>
The text tag creates text.
The x property specifies the position of the bottom right point of the text field on
the X axis, y defines the corresponding point on the Y axis.
The font-size property specifies the font size.
The font-family property specifies the font.
The desired text is written to this tag.
No. Code section (structure of a JavaScript script)
1 <script>
var newValue
document.getElementById(gauge.pointer).
setAttribute(transform,rotate(+newValue+,55,55))
</script>
document.getElementById()
Specifies the element to be accessed or modified.
setAttribute
The function changes the property of elements. Elements that do not represent
JavaScript variables are put in quotation marks. Prior to executing the function,
JavaScript variables are replaced with the variable value.
diagnostic message displays detailed information about this message below the
table.
How OB 1 works
No. Function
1 The first block call in OB 1 is the WWW function (SFC 99).
For more information about the function, please refer to Chapter 4.2.
Siemens AG 2017 All rights reserved
The diagrammatic overview below shows the basic structure of the user-defined
page.
Files from
Library from third-
Siemens
party vendor
Diagnostic jquery
Demo14.html
_0.0.3.js -2.1.3.min.js
User-defined
file
Demo14.js S7_framework.js
Demo14.html
The HTML document defines the structure of the user-defined page and the calls of
the JavaScript files used, see Chapter 14.2.2.1. The document defines that clicking
the diagnostic messages displays them in a table.
Demo14.js
The JavaScript file integrates the S7 Framework to start the loading indicator.
diagnostic_0.0.1.js
The diagnostic_0.0.1.js file accesses tags with a defined ID.
The diagnostic display is inserted into these tags.
S7_framework.js
The JavaScript file contains a number of functions for converting and processing
data from a SIMATIC S7.
For more information about the S7 Framework, please refer to Chapter 4.3.
4 In this div tag, the Event information of a diagnostic message is displayed in the
table when the appropriate message is clicked.
2
indicator is to be displayed to the S7 Framework.
The S7 Framework detects when an AJAX function is executed and shows/hides
the loading indicator accordingly.
The loading indicator is shown when the div tag with ID diagTableDiv is empty.
The following query is programmed for this.
Note This example has no S7 program. You will find the HTML file in the project folder
in html_pictureChange.
Figure 15-1: User-defined page for changing pictures using a JavaScript variable
Siemens AG 2017 All rights reserved
2 With these HTML elements, one button labeled Red and one button labeled
Green are displayed.
Clicking the Green button triggers the changePic JavaScript function and
transfers the green value to it. In the JavaScript file, the parameter (color)
therefore includes the value (green).
To change a picture depending on a PLC tag, the PLC tag must be read cyclically.
Cyclic reading is done by the IF statement.
When the green value has been transferred to the function, the previous path to
the red picture is changed to the path of the green picture.
How OB 1 works
No. Function
1 The first block call in OB 1 is the WWW function (SFC 99).
For more information about the function, please refer to Chapter 4.2.
The diagrammatic overview below shows the basic file structure of the user-defined
page.
Figure 16-3: Diagrammatic overview of the user-defined page
HTML file JavaScript files
Demo16.html
In the Demo16.html file, all JavaScript files are integrated and the button is
defined.
Demo16.js
The JavaScript file performs the restart with the aid of S7_framework.js.
S7_framework.js
The JavaScript file contains a number of functions for converting and processing
data from a SIMATIC S7.
For more information about the S7 Framework, please refer to Chapter 4.3.
How OB 1 works
No. Function
1 The first block call in OB 1 is the WWW function (SFC 99).
For more information about the function, please refer to Chapter 4.2.
The diagrammatic overview below shows the basic file structure of the user-defined
Siemens AG 2017 All rights reserved
page.
Figure 17-3: Diagrammatic overview of the user-defined page
Demo17.html
All JavaScript files are integrated into the Demo17.html file.
Demo17.js
The JavaScript file allows the user to log in and out with the aid of
S7_framework.js.
S7_framework.js
The JavaScript file contains a number of functions for converting and processing
data from a SIMATIC S7.
For more information about the S7 Framework, please refer to Chapter 4.3.
3 In the <style> tag, the appropriate IDs or the class is accessed to change the style
properties of the input fields and buttons.
3 When the page has loaded, the system checks whether the user is already logged
in via the standard web page or a previous login operation.
If no user is logged in, a pop-up appears that reads:
Please log in!
AJAX
AJAX (Asynchronous JavaScript and XML) provides a method for exchanging
data asynchronously between a web browser and the web server. Data is
exchanged without reloading the web page itself.
ASCII strings are cyclically read using the S7 Framework (JavaScript) and split
into single variables.
The values are individually sent to the controller.
The values are sent from a form to the controller.
Requirement for communication between STEP 7 and the user-defined page using AJAX
Updating and writing PLC tags using AJAX is implemented on the user-defined
page. To this end, the json file format must be added to the user-defined page
properties in Files with dynamic content:.
Figure 18-1: Requirement update using AJAX with json in S7
.htm;.html;.json
Figure 18-2: User-defined page for high-performance data transfer using AJAX
2
Siemens AG 2017 All rights reserved
3
1 5
3
4
4 6
Table 18-2: User-defined page for high-performance data transfer using AJAX
Item Description
1 With the Speed value, you influence the speed of the package.
2 Signal state of the sensor: (green = free; red = package detected)
3 Count that shows the packages that have already passed.
4 [send] transfers the name and age to the controller.
Table 18-3: Instructions for using the user-defined page
Step Instruction
1 Change the Speed.
2 Enter the name and age of the packages recipient.
3 Select the send button.
4 In TIA Portal, open the Plc2Web data block.
5 Click Monitor.
6 Verify that the name and age have been received.
DB 1 FB 1
Plc2Web Counter
Siemens AG 2017 All rights reserved
FC 1
WebCom
The function block calculates the following output variables as simulation values for
the sequence displayed on the web page.
position:
calculates the packages position.
lightBarrier:
checks whether the package is below the sensor.
counterPackages:
If the sensor detects a package, a count is incremented.
Siemens AG 2017 All rights reserved
No. Function
3 FC 1 WebCom (web communication)
The function initially converts the simulation values of FB 1 to a webString
variable. The webserverString string variable follows from this variable.
If you want to transfer additional values, you must extend the string in this block.
The TIA Portal system function HTA converts the following variable types to an
ASCII string.
SINT
Siemens AG 2017 All rights reserved
INT
LINT
DINT
Example:
If you want to convert variables of the REAL or LREAL type, make sure to
first convert them to DWORD or LWORD. Then convert these variables to
DINT or LINT.
A bit is converted to an ASCII string using an IF statement.
General: Example:
IF bool THEN
char := 1;
ELSE
char := 0;
END_IF;
Example:
No. Function
4 DB 1 Plc2Web
DB1 contains all variables that are sent from the CPU to the user-defined page or
read.
The data block also contains the concatenated string variable, webserverString.
The diagrammatic overview below shows the basic file structure of the user-defined
page.
This description focuses on the JavaScript files code elements, which makes basic
knowledge of HTML necessary for this application example.
jquery-
2.1.3.min.js
JSON files
dataWrite.json dataRead.json
Controller
Demo18.html
All JavaScript files are integrated into the Demo16.html file.
Demo18.js
The Demo18.js JavaScript file controls read/write from/to the controller by calling
functions from the S7_framework.js library.
S7_framework.js
The JavaScript file contains a number of functions for converting and processing
data from a SIMATIC S7.
For more information about the S7 Framework, please refer to Chapter 4.3.
The Demo18.js file uses S7 Framework functions to transfer data via the JSON
files.
4 The updateValues function further processes the read values. The values are
transferred to the values array.
First value = values[0]
Second value = values[1] etc.
str is used for loading variables that were not converted to the string.
2 dataWrite.json
The file contains the parameters of the string and the UDP commands of the PLC
tags to be written.
The information for writing the string corresponds to the information for reading,
see above.
19 Installation
19.1 Installing the hardware and software
Installing the hardware
The following figure shows the hardware configuration for the examples.
The PC (web browser) is connected to the CPU (web server) via Industrial Ethernet
using the PN interface.
The SIMATIC S7 controllers were used separately as the examples use only one
IP address for the S7 controller.
Industrial Ethernet
Siemens AG 2017 All rights reserved
Note Follow the installation and connection guidelines provided in the appropriate
manuals and installation instructions.
20 Internet links
This table provides a selection of links for related information.
https://jquery.com/
21 History
Table 21-1: Document history
Version Date Modifications
V1.0 08/2015 First version