Examples For The SIMATIC S7-1200 / S7-1500 Web Server

Transcription

Examples for theSIMATIC S7-1200 /S7-1500 Web ServerSTEP 7 Basic (TIA Portal), STEP 7 Professional(TIA en/view/68011496SiemensIndustryOnlineSupport

Legal informationLegal informationUse of application examplesApplication examples illustrate the solution of automation tasks through an interaction of severalcomponents in the form of text, graphics and/or software modules. The application examples area free service by Siemens AG and/or a subsidiary of Siemens AG (“Siemens”). They are nonbinding and make no claim to completeness or functionality regarding configuration andequipment. The application examples merely offer help with typical tasks; they do not constitutecustomer-specific solutions. You yourself are responsible for the proper and safe operation of theproducts in accordance with applicable regulations and must also check the function of therespective application example and customize it for your system.Siemens grants you the non-exclusive, non-sublicensable and non-transferable right to have theapplication examples used by technically trained personnel. Any change to the applicationexamples is your responsibility. Sharing the application examples with third parties or copying theapplication examples or excerpts thereof is permitted only in combination with your own products.The application examples are not required to undergo the customary tests and quality inspectionsof a chargeable product; they may have functional and performance defects as well as errors. It isyour responsibility to use them in such a manner that any malfunctions that may occur do notresult in property damage or injury to persons. Siemens AG 2018 All rights reservedDisclaimer of liabilitySiemens shall not assume any liability, for any legal reason whatsoever, including, withoutlimitation, liability for the usability, availability, completeness and freedom from defects of theapplication examples as well as for related information, configuration and performance data andany damage caused thereby. This shall not apply in cases of mandatory liability, for exampleunder the German Product Liability Act, or in cases of intent, gross negligence, or culpable loss oflife, bodily injury or damage to health, non-compliance with a guarantee, fraudulentnon-disclosure of a defect, or culpable breach of material contractual obligations. Claims fordamages arising from a breach of material contractual obligations shall however be limited to theforeseeable damage typical of the type of agreement, unless liability arises from intent or grossnegligence or is based on loss of life, bodily injury or damage to health. The foregoing provisionsdo not imply any change in the burden of proof to your detriment. You shall indemnify Siemensagainst existing or future claims of third parties in this connection except where Siemens ismandatorily liable.By using the application examples you acknowledge that Siemens cannot be held liable for anydamage beyond the liability provisions described.Other informationSiemens reserves the right to make changes to the application examples at any time withoutnotice. In case of discrepancies between the suggestions in the application examples and otherSiemens publications such as catalogs, the content of the other documentation shall haveprecedence.The Siemens terms of use (https://support.industry.siemens.com) shall also apply.Security informationSiemens provides products and solutions with industrial security functions that support the secureoperation of plants, systems, machines and networks.In order to protect plants, systems, machines and networks against cyber threats, it is necessaryto implement – and continuously maintain – a holistic, state-of-the-art industrial security concept.Siemens‟ products and solutions constitute one element of such a concept.Customers are responsible for preventing unauthorized access to their plants, systems, machinesand networks. Such systems, machines and components should only be connected to anenterprise network or the Internet if and to the extent such a connection is necessary and onlywhen appropriate security measures (e.g. firewalls and/or network segmentation) are in place.For additional information on industrial security measures that may be implemented, please emens‟ products and solutions undergo continuous development to make them more secure.Siemens strongly recommends that product updates are applied as soon as they are availableand that the latest product versions are used. Use of product versions that are no longersupported, and failure to apply the latest updates may increase customer‟s exposure to cyberthreats.To stay informed about product updates, subscribe to the Siemens IndustrialSecurity RSS Feed at: s for the Web ServerEntry ID: 68011496, V2.1, 08/20182

Table of ContentsTable of ContentsLegal information . 21Preface . 52Hardware and Software Components Used . 63Basics of Standard Web Pages . 84Basics of User-Defined Web Pages . 94.14.24.35Reading and Writing with different Variable Types . 125.15.25.2.15.2.2 Siemens AG 2018 All rights reserved6Automation task . 27Functional mechanisms and use . 28S7 program structure. 29User-defined web page (HTML file) structure . 30Change Language on User-Defined Pages . 3110.110.210.2.110.2.210.311Automation task . 24Functional mechanisms and use . 25S7 program structure. 26User-defined web page (HTML file) structure . 26HTTP Redirection following an Error (S7-1500 only) . 279.19.29.2.19.2.210Automation task . 22Functional mechanisms and use . 22S7 program structure. 23User-defined web page (HTML file) structure . 23ENUM – Variable Value Replaced with Text . 248.18.28.2.18.2.29Automation task . 19Functional mechanisms and use . 19S7 program structure. 20User-defined web page (HTML file) structure . 21Displaying an S7 Array (S7-1500 only) . 227.17.27.2.17.2.28Automation task . 12Functional mechanisms and use . 13S7 program structure. 15User-defined web page (HTML file) structure . 16Displaying the Date and Time . 196.16.26.2.16.2.27Login and instructions for use . 9Web server – initializing the WWW system function . 9Libraries – jQuery and S7 Framework . 10Automation task . 31Functional mechanisms and use . 31S7 program structure. 32User-defined web page structure . 32Extending the example . 37Transferring Data without Reloading Pages Using AJAX . 3811.111.211.2.111.2.2Automation task . 39Functional mechanisms and use . 40S7 program structure. 41User-defined web page structure . 42Examples for the Web ServerEntry ID: 68011496, V2.1, 08/20183

Table of Contents12Displaying Data of a Datalog as a Graph . 4712.112.212.2.112.2.213Display Elements Using Scalable Vector Graphics . 5413.113.213.2.114 Siemens AG 2018 All rights reservedAutomation task . 69Functional mechanisms and use . 69S7 program structure. 70User-defined page structure . 70High-Performance Communication via a String . 7318.118.218.2.118.2.219Automation task . 66Functional mechanisms and use . 66S7 program structure. 67User-defined web page structure . 67Login on User-Defined Pages . 6917.117.217.2.117.2.218Programming task . 64Functional mechanisms and use . 64Button for CPU Restart . 6616.116.216.2.116.2.217Automation task . 58Functional mechanisms and use . 58S7 program structure. 59User-defined web page structure . 59Changing Pictures Using JavaScript . 6415.115.216Programming task . 54Functional mechanisms and use . 54Sample SVG element – rotary motion of a motor . 55S7 Diagnostics and Loading Indicator . 5814.114.214.2.114.2.215Automation task . 47Functional mechanisms and use . 48S7 program structure. 49User-defined web page structure . 50Automation task . 73Functional mechanisms and use . 74S7 program structure. 75User-defined web page structure . 78Installation . 8219.119.2Installing the hardware and software . 82Installing the application example . 8320Internet links . 8421History. 85Examples for the Web ServerEntry ID: 68011496, V2.1, 08/20184

1 PrefacePreface1Objective of the application examplesThe application examples in this document show you how to extend your own webpages on the S7-1200/1500 web server.This document describes the examples provided for downloading. It isrecommended to run the examples on a computer and simultaneously analyzethem with the aid of this document.Main contents of the application examples Siemens AG 2018 All rights reservedThe application examples cover the following key points: Reading and writing with different variable types Displaying the time Outputting arrays (S7-1500 only) Using the ENUM data type HTTP redirection following an error (S7-1500 only) Change language on user-defined pages Transferring data without reloading pages Displaying a datalog generated by the controller as a graph Creating display elements Displaying diagnostic information Changing pictures using JavaScript Restarting the CPU using a button Logging in on the user-defined page High-performance data transferAdvantagesIntegrated web server in the S7-1200 and S7-1500The standard web pages for easy display of service and diagnostic information areenabled with a single click.In addition, you can create custom, user-defined web pages that are referred tobelow as “user-defined pages”.Access from anywhereA web browser allows you to access the S7 web pages from anywhere in theworld.Application exampleUniversal use of the application example for the SIMATIC S7-1200 and S7-1500.BenefitsNo additional hardware and software required. The web server can be accessedover large distances using mobile communications devices such as tabletcomputers, smartphones, etc.NoteThe application examples in conjunction with the web server should not andcannot replace an HMI system.Examples for the Web ServerEntry ID: 68011496, V2.1, 08/20185

2 Hardware and Software Components UsedHardware and Software Components Used2The application examples were created with the following components.Hardware componentsTable 2-1: Hardware components used for the examples Siemens AG 2018 All rights reservedComponentNo.Order no.CPU 1511-1 PN16ES7511-1AK01-0AB0Firmware V2.0.5CPU 1214C DC/DC/DC16ES7214-1AG40-0XB0Firmware V4.2PG/PCwith Ethernet interface1--IE FC TPSTANDARD CABLE16XV1840-2AH10IE connecting cable,minimum orderquantity: 20mRJ45 plug connector26GK1901-1BB10-2AA0Can be mouldedNoteNoteFor these application examples, you need the current CPU firmware version.Depending on the CPU type, the following entries provide related links to theappropriate downloads: S7-1500: /78301349S7-1200: /107539750Software componentsTable 2-2: Software components used for the examplesComponentNo.Order no.SIMATIC STEP 7Professional V1416ES7822-1AA04-0YE5V14.0 (Update 2)Software tool for creatingHTML files such asFrontPage, Notepad , 1-Web pages createdwith Notepad Web browser such asInternet Explorer, Mozilla1)Firefox1-Created and testedwith IE11 and Firefox1)NoteNoteThe following web browsers were tested for communication with the CPU: Internet Explorer (version 11) Mozilla Firefox (version 50)The application examples are optimized for Firefox and IE11.Using other browsers may require changes regarding their display in thebrowser.Examples for the Web ServerEntry ID: 68011496, V2.1, 08/20186

2 Hardware and Software Components UsedOverall structureThe individual application examples consist of an S7 program running on an S71200/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 webfunctions without an S7 program.The web pages are opened using a web browser and consist of an HTML file as abasis.More complex examples include additional JavaScript files with the “js” fileextension.Figure 2-1: Hardware configuration for the application examplesPROFINETIndustrial Ethernet Siemens AG 2018 All rights reservedBrowserS7-1500S7-1200Sample files and projectsThe following list contains the files required for this example, consisting of the S7project and this PDF document.Table 2-3: Examples – source filesComponentComments68011496 examples for S7WebServer CODE v21.zipThe file contains theSTEP 7 project with theappropriate HTML files inthe \html directory.68011496 examples for S7WebServer en DOC v21.pdfThis document.Examples for the Web ServerEntry ID: 68011496, V2.1, 08/20187

3 Basics of Standard Web Pages3Basics of Standard Web PagesRequirementsIn STEP 7, the following settings are required in the CPU properties. The web server must be activated. If you require secure access to the web pages, check the “Permit access onlywith HTTPS” check box. Automatic refresh of web pages is enabled.The default refresh interval is 10 seconds.The interval can be set in the range from 1 to 999s.Access via HTTP or HTTPSThe URL “http://ww.xx.yy.zz” or “https://ww.xx.yy.zz” provides you with access tothe standard web pages. “ww.xx.yy.zz” corresponds to the CPU‟s IP address.HTTPS is used for encrypting and authenticating communication between thebrowser and the web server. When the “Permit access only with HTTPS” checkbox is checked, the CPU‟s web pages can only be opened via HTTPS. Siemens AG 2018 All rights reservedCPU certificateIf the browser reports a certificate error, proceed as described in the following view/63314183Access rights for login to the web pages in STEP 7By factory default, the “Everybody” user is set in each SIMATIC S7-1200/1500controller.This user has limited access rights and no password.(This prevents access to user-defined pages.)To have full access to user-defined pages, you have to log in with a user who hasthe required access rights. You can parameterize users, passwords and accessrights with STEP 7 in the S7-1200/1500 controller properties.The login input fields are located in the top left corner of each standard web pageof the S7-1200/1500 controller.Figure 3-1: Login window on standard web pageSIMATIC S7-1200 / S7-1500 standard web pagesVia the integrated standard web page, the S7-1200 and S7-1500 web serveralready offers a large amount of information about the respective CPU.The structure of the standard web pages is described in detail in the S7-1500 WebServer Function Manual; it is not the subject of this document.Examples for the Web ServerEntry ID: 68011496, V2.1, 08/20188

4 Basics of User-Defined Web PagesBasics of User-Defined Web Pages4For the basics of user-defined pages, please refer to this application example:“Creating and using user-defined web pages on S7-1200 / ww/en/view/680114964.1Login and instructions for useIn TIA Portal, each example name starts with the chapter number:Example: Chapter 5 corresponds to program name “05ReadAndWriteS7.”The web contents for the examples can be found in the appropriate S7 project onyour computer in the “ \html .” folder.Login of the user-defined pages in the application examplesUser:Password:4.2admins7Web server – initializing the WWW system function Siemens AG 2018 All rights reservedIn the application examples, the “WWW” system function (SFC 99) is called byOB 1.This block call is described in all examples, including the reference to this chapter.No.1FunctionThe “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 serverand the controller.The Web DB (DB 333) is connected to the WWW function. The Web DB and theFragment DB(s) store the structure of the user-defined pages.2NoteMore instructions and block calls are described in the respective applicationexamples.For basic information about generating data blocks for user-defined pages,please refer to the “First steps” of the following n/view/68011496Examples for the Web ServerEntry ID: 68011496, V2.1, 08/20189

4 Basics of User-Defined Web Pages4.3Libraries – jQuery and S7 FrameworkThe web pages of the application examples consist of HTML documents,JavaScript files and JavaScript libraries.The file structures can be found in the respective application examples.Some application examples use the “jQuery” and S7 Framework JavaScriptlibraries. These examples are listed in the following table.Table 4-1: Libraries used in the application examples Siemens AG 2018 All rights reservedChapterno.Chapter namejQueryS7Framework10Change Language on User-Defined PageX-12Displaying Data of a Datalog as a GraphXX14S7 Diagnostics and Loading IndicatorXX16Button for CPU RestartXX17Login on User-Defined PageXX18High-Performance Communication via a StringXXIntegrate the jQuery library and the appropriate JavaScript files that access or usethis jQuery library into your HTML base document. For example, the “S7Framework” JavaScript file uses the jQuery library; in the HTML code, it istherefore below the call of the jQuery library.Figure 4-1: Call of JavaScript libraries in the HTML documentjquery-2.1.3.min.js (jQuery library)The “jquery-2.1.3.min.js” file is a library that enables more efficient programmingwith JavaScript. The library contains basic DOM, event, effects and Ajax functionsthat are not described in detail in this document. The library‟s methods are typicallyaccessed by the prefixed “jQuery” object identifier.This object identifier is replaced with a “ ” sign, which reduces the total number ofcharacters in a JavaScript file.Example:jQuery.post(URL, DATA) .post(URL, DATA)For general information about jQuery, visit: https://jquery.com/Examples for the Web ServerEntry ID: 68011496, V2.1, 08/201810

4 Basics of User-Defined Web PagesS7 framework.jsThe JavaScript file contains a number of functions for converting and processingdata 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-1500controller. Both controllers access the same web files.However, depending on the CPU, access to the default web server differs in termsof IDs, login and other functions. A controller type check is therefore implementedin the examples.The following table lists the S7 Framework functions.Table 4-2: S7 Framework functions Siemens AG 2018 All rights reservedNo.Code description1Assignment of variable types within S7 Framework2PLC functions (different tasks as a library in the framework)-Functions and variables forAJAX (data transfer)JSON (data processing of strings using parser)CPU type (access to S7-1200/1500 web server)Logon/logoff (referenced to S7 standard web page, “Portal.mwsl”)Loading indicator (definition and function for animated loading icon)- Error handling within S7 Framework data processingNoteIn the code, you will find information about the functions.A detailed description of the functions is not the subject of this guide.Examples for the Web ServerEntry ID: 68011496, V2.1, 08/201811

5 Reading and Writing with different Variable Types5Reading and Writing with different VariableTypes5.1Automation taskThe task is to read and rewrite variables of different data types.NoteThe DTL data type is only supported by the S7-1500.Requirements for the automation taskTwo HTML pages have to be programmed:One HTML page that allows you to read/write variables of different types. One HTML page that allows you to read special variables. Siemens AG 2018 All rights reserved Examples for the Web ServerEntry ID: 68011496, V2.1, 08/201812

5 Reading and Writing with different Variable Types5.2Functional mechanisms and useOverall structureThe application example consists of an S7 program and two HTML documents thatare displayed as web pages in a browser.User-defined page structureThe following figure shows the user-defined page for displaying simple PLC tagsthat are read/write accessed.The top “Simple Variables” access S7 flags, whereas the “Structure and Array”variables access a “DB 1” data block.Figure 5-1: User-defined page for reading/writing simple variables1 Siemens AG 2018 All rights reserved3243142Table 5-1: Web page for reading/writing simple variablesItemDescription1This link takes you to the HTML web page with the special variables,“Reading special variables”.2This column displays the current values of the variables.3The value to be written is entered in this column.4The “Write” buttons transfer the values to the CPU.Table 5-2: Instructions for using the user-defined pageStepInstruction1In the “New Value” column, enter a value corresponding to the data type.2Click the “Write” button.3The value appears in the “Current Value” column.4Click this link if you want to open the “Reading special variables” web page.Examples for the Web ServerEntry ID: 68011496, V2.1, 08/201813

5 Reading and Writing with different Variable TypesThe following figure shows the structure of the user-defined page for readingspecial variables.Figure 5-2: User-defined page for reading/writing special variables1 Siemens AG 2018 All rights reserved23Table 5-3: Web page for reading/writing special variablesItemDescription1This link takes you to the web page for reading/writing PLC tags.2This column displays the names of the special variables.3This column displays the information (value) of the respective specialvariable.Examples for the Web ServerEntry ID: 68011496, V2.1, 08/201814

5 Reading and Writing with different Variable Types5.2.1S7 program structureThe diagrammatic representation below shows the S7 program structure. TheHTML web page is called cyclically. The following sections describe the dataexchange with the blocks.Figure 5-3: S7 program for reading/writing variablesWeb serverUser-defined pagesDB 33Web DB /DB 334Fragment DBDB1TestDBOB1MainSFC 99WWW Siemens AG 2018 All rights reservedDB2HTTP InfoHow OB 1 worksNo.1FunctionThe 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 the PLC tagsThe top section of the first HTML page defines simple PLC tags (flags) that can beread/written using the web page.Contents of DB1The “TestDB” (DB1) defines variables that can be read/written using the web page.Exception: the “WWW RET VAL” variable. This variable contains the return valueof the WWW function.Contents of DB2DB2 “HTTP Info” stores the special variables; in this case: HEADER Requestvariables.The user can only read these variables using the web page. These variables arewritten using the web page via the web server.Examples for the Web ServerEntry ID: 68011496, V2.1, 08/201815

5 Reading and Writing with different Variable Types5.2.2User-defined web page (HTML file) structureNo.1Code sectionTo read/write a PLC tag from the PLC tags (tag table) of a web page, only the“variable name” in the syntax is relevant.General: “variable name”:: “testBit”: Siemens AG 2018 All rights reservedExampleExamples for the Web ServerEntry ID: 68011496, V2.1, 08/201816

5 Reading and Writing with different Variable TypesNo.To read/write a variable from a DB, the DB name and the variable name arerelevant. Siemens AG 2018 All rights reserved2Code sectionExamples for the Web ServerEntry ID: 68011496, V2.1, 08/201817

5 Reading and Writing with different Variable TypesNo. Siemens AG 2018 All rights reserved3Code sectionThe special variables (here: HTTP request variables) are saved in the DB variableswith UDP commands.This DB variable is read by the HTML file.Note:http request variables are global variables within a script‟s scope.Examples for the Web ServerEntry ID: 68011496, V2.1, 08/201818

6 Displaying the Date and Time6Displaying the Date and Time6.1Automation taskThe task is to display the CPU‟s time on a web page.Requirements for the automation task6.2 Read the time in the STEP 7 program using the “RD LOC T” function. Program a web page that displays the time. Update the time with the aid of a second HTML file (inline frame) integrated inthe HTML file.For a description of the term „inline frame‟, please refer to Chapter 11.Functional mechanisms and useThe application example consists of an S7 program and two HTML documents thatare displayed as web pages in a browser. Siemens AG 2018 All rights reservedUser-defined page structureThe date and time are displayed horizontally and centered on the user-definedpage.Figure 6-1: User-defined page for displaying the date and timeSetting the time in the controllerThe first step is to set the current time in the data source, i.e., in the CPU.1. Open TIA Portal and the program example.2. In the Project tree, right-clic

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