LHTTP DOC V10 en
LHTTP DOC V10 en
LHTTP DOC V10 en
Communication
(LHTTP)
Siemens
SIMATIC S7-1500, Open User Communication Industry
Online
https://support.industry.siemens.com/cs/ww/en/view/109763879 Support
Legal information
Legal information
Use of application examples
Application examples illustrate the solution of automation tasks through an interaction of several
components in the form of text, graphics and/or software modules. The application examples are
a free service by Siemens AG and/or a subsidiary of Siemens AG (“Siemens”). They are non-
binding and make no claim to completeness or functionality regarding configuration and
equipment. The application examples merely offer help with typical tasks; they do not constitute
customer-specific solutions. You yourself are responsible for the proper and safe operation of the
products in accordance with applicable regulations and must also check the function of the
respective application example and customize it for your system.
Siemens grants you the non-exclusive, non-sublicensable and non-transferable right to have the
application examples used by technically trained personnel. Any change to the application
examples is your responsibility. Sharing the application examples with third parties or copying the
application 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 inspections
of a chargeable product; they may have functional and performance defects as well as errors. It is
your responsibility to use them in such a manner that any malfunctions that may occur do not
result in property damage or injury to persons.
Disclaimer of liability
Siemens shall not assume any liability, for any legal reason whatsoever, including, without
limitation, liability for the usability, availability, completeness and freedom from defects of the
application examples as well as for related information, configuration and performance data and
any damage caused thereby. This shall not apply in cases of mandatory liability, for example
under the German Product Liability Act, or in cases of intent, gross negligence, or culpable loss of
life, bodily injury or damage to health, non-compliance with a guarantee, fraudulent
non-disclosure of a defect, or culpable breach of material contractual obligations. Claims for
damages arising from a breach of material contractual obligations shall however be limited to the
© Siemens AG 2019 All rights reserved
foreseeable damage typical of the type of agreement, unless liability arises from intent or gross
negligence or is based on loss of life, bodily injury or damage to health. The foregoing provisions
do not imply any change in the burden of proof to your detriment. You shall indemnify Siemens
against existing or future claims of third parties in this connection except where Siemens is
mandatorily liable.
By using the application examples you acknowledge that Siemens cannot be held liable for any
damage beyond the liability provisions described.
Other information
Siemens reserves the right to make changes to the application examples at any time without
notice. In case of discrepancies between the suggestions in the application examples and other
Siemens publications such as catalogs, the content of the other documentation shall have
precedence.
The Siemens terms of use (https://support.industry.siemens.com) shall also apply.
Security information
Siemens provides products and solutions with Industrial Security functions that support the secure
operation of plants, systems, machines and networks.
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 constitute one element of such a concept.
Customers are responsible for preventing unauthorized access to their plants, systems, machines
and networks. Such systems, machines and components should only be connected to an
enterprise network or the Internet if and to the extent such a connection is necessary and only
when 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 visit
https://www.siemens.com/industrialsecurity.
Siemens’ products and solutions undergo continuous development to make them more secure.
Siemens strongly recommends that product updates are applied as soon as they are available
and that the latest product versions are used. Use of product versions that are no longer
supported, and failure to apply the latest updates may increase customer’s exposure to cyber
threats.
To stay informed about product updates, subscribe to the Siemens Industrial Security RSS Feed
at: https://www.siemens.com/industrialsecurity.
LHTTP
Entry ID: 109763879, V1.0, 05/2019 2
Table of contents
Table of contents
Legal information ......................................................................................................... 2
1 Introduction ........................................................................................................ 4
1.1 Overview............................................................................................... 4
1.2 Mode of operation ................................................................................ 5
1.3 Components used ................................................................................ 5
2 Engineering ........................................................................................................ 6
2.1 Components of the library .................................................................... 6
2.2 Interface description ............................................................................. 7
2.2.1 LHTTP_Get .......................................................................................... 7
2.2.2 LHTTP_Post ......................................................................................... 9
2.2.3 LHTTP_FindStringInArray .................................................................. 11
2.2.4 LHTTP_ExtractStringFromArray ........................................................ 12
2.2.5 LHTTP_ExtractStringFromArrayExt ................................................... 13
2.2.6 LHTTP_typeTLS ................................................................................. 14
2.3 Integration into the user project .......................................................... 15
2.3.1 Configuring the Ethernet interface ..................................................... 15
2.3.2 Certificate management ..................................................................... 16
2.3.3 Integrating blocks into the user program ............................................ 22
2.4 Error handling ..................................................................................... 24
3 Additional information .................................................................................... 26
© Siemens AG 2019 All rights reserved
LHTTP
Entry ID: 109763879, V1.0, 05/2019 3
1 Introduction
1 Introduction
1.1 Overview
The Hypertext Transfer Protocol (HTTP) is a data transfer protocol used primarily
to load Web pages from the World Wide Web.
Due to the increasing networking of plants and the advancement of the Internet of
Things (IoT), HTTP and HTTPS also play an increasingly important role in
automation technology.
The library for HTTP communication (LHTTP) enables the data exchange of a
SIMATIC S7-1500 PLC via the integrated Ethernet interface with another device in
the local network or a web server in the Internet via HTTP or HTTPS.
LHTTP
Entry ID: 109763879, V1.0, 05/2019 4
1 Introduction
Due to the integrated certificate management in the TIA portal, it is also possible to
transfer data securely with HTTPS using the same components.
LHTTP
Entry ID: 109763879, V1.0, 05/2019 5
2 Engineering
2 Engineering
2.1 Components of the library
Function blocks and functions
Table 2-1: Function blocks and functions of the Library
Name Version Description
LHTTP_Get V1.0.0 Realizes the HTTP method GET
LHTTP_Post V1.0.0 Realizes the HTTP method POST
LHTTP_FindStringInArray V1.0.0 Searches an array of chars for a given string
LHTTP_ExtractString V1.0.0 Extracts a string between two specified text
FromArray parts from an array of chars
LHTTP_ExtractString V1.0.0 Same function as
FromArrayExt "LHTTP_ExtractStringFromArray" with extended
options
LHTTP
Entry ID: 109763879, V1.0, 05/2019 6
2 Engineering
Description
The block implements the HTTP method GET to retrieve data from a web server.
Parameters
Figure 2-1: LHTTP_Get
LHTTP_Get
LHTTP
Entry ID: 109763879, V1.0, 05/2019 7
2 Engineering
Principle of operation
The user specifies the requested resource in the form of a URL, e.g.
"http://httpbin.org/get" or "https://192.168.0.1:80/index.html", at the "url" parameter.
Optional parameters can be passed with two variants:
• Appended to the URL at the parameter "url" with a "?" in front, e.g. " URL, e.g.
"http://httpbin.org/get?lang=en&country=de".
• At the separate parameter "data", e.g. "lang=en&country=de"
With a rising edge at the "execute" parameter, the block queries the IP address
associated with the host at the configured DNS server if necessary and establishes
a connection to the Web server.
If the specified URL starts with "https", a secure connection is established. In this
case, the certificate of the requested web server must be referenced by the
parameter "tls" (see section 2.2.6). If the web server requires client authentication,
the certificate of the PLC must also be referenced.
The module creates the HTTP request from the specified URL and sends it to the
server.
The server responds with the requested data or an error message. After all
telegrams have been received successfully, the block closes the connection to the
server again.
© Siemens AG 2019 All rights reserved
Note The block outputs the HTTP status code received from the server with the first
received telegram and writes the user data of each received telegram directly
into the memory area connected to the parameter "responseData". Evaluate the
user data only after the output "done" has been set.
Note The block doesn't support redirects. If the server responds with a redirect (HTTP
response code 3xx) the block outputs an error (see chapter 2.4).
Check the URL and correct it if necessary.
LHTTP
Entry ID: 109763879, V1.0, 05/2019 8
2 Engineering
2.2.2 LHTTP_Post
Description
The block implements the HTTP method POST to transfer data to a web server.
Parameters
Figure 2-2: LHTTP_Post
LHTTP_Post
LHTTP
Entry ID: 109763879, V1.0, 05/2019 9
2 Engineering
Principle of operation
The user specifies the requested resource in the form of a URL, e.g.
"http://httpbin.org/post" or "https://192.168.0.1:80/index.html", at the parameter
"url".
The format of the user data to be transferred at the parameter "data" depends on
the web server. For web form elements data is usually described in key-value
pairs, e.g. "usr=admin&pwd=12345".
With a rising edge at the "execute" parameter, the block queries the IP address
associated with the host at the configured DNS server if necessary and establishes
a connection to the web server.
If the specified URL starts with "https", a secure connection is established. In this
case, the certificate of the requested web server must be referenced by the
parameter "tls" (see section 2.2.6). If the web server requires client authentication,
the certificate of the PLC must also be referenced.
The module creates the HTTP request from the specified URL and sends it to the
server.
The server responds with the requested data or an error message. After all
telegrams have been received successfully, the block closes the connection to the
server again.
Note The block outputs the HTTP status code received from the server with the first
received telegram and writes the user data of each received telegram directly
© Siemens AG 2019 All rights reserved
into the memory area connected to the parameter "responseData". Evaluate the
user data only after the output "done" has been set.
Note The block doesn't support redirects. If the server responds with a redirect (HTTP
response code 3xx) the block outputs an error (see chapter 2.4).
Check the URL and correct it if necessary.
LHTTP
Entry ID: 109763879, V1.0, 05/2019 10
2 Engineering
2.2.3 LHTTP_FindStringInArray
Description
The function "LHTTP_FindStringInArray" searches an Array of Char for a string
and returns its position as return value.
Parameters
Figure 2-3: LHTTP_FindStringInArray
LHTTP_FindStringInArray
String searchFor
searchIn
Array[*] of Char Array[*] of Char
LHTTP
Entry ID: 109763879, V1.0, 05/2019 11
2 Engineering
2.2.4 LHTTP_ExtractStringFromArray
Description
The LHTTP_ExtractStringFromArray function extracts a string between two
specified text parts from an array of chars.
Parameters
Figure 2-4: LHTTP_ExtractStringFromArray
LHTTP_ExtractStringFromArray
extracted
String textBefore String
String
String textAfter
searchIn
Array[*] of Char Array[*] of Char
LHTTP
Entry ID: 109763879, V1.0, 05/2019 12
2 Engineering
2.2.5 LHTTP_ExtractStringFromArrayExt
Description
The function "LHTTP_ExtractStringFromArrayExt" extracts a string between two
specified text parts from an array of char with extended options.
NOTE This function is part of the library to enable the user to parse the received data
although it is not used by the blocks of the library.
Parameters
Figure 2-5: LHTTP_ExtractStringFromArrayExt
LHTTP_ExtractStringFromArrayExt
extracted
String textBefore String
String
String textAfter position DInt
includeBefore
Bool length Int
After
DInt startPos
searchIn
© Siemens AG 2019 All rights reserved
LHTTP
Entry ID: 109763879, V1.0, 05/2019 13
2 Engineering
2.2.6 LHTTP_typeTLS
The PLC data type "LHTTP_typeTLS" references the certificates required for
secure connections via HTTPS.
Note The IDs of the certificates can be found in the global certificate manager under
"Security settings > Security features > Certificate manager" or in the certificate
manager of the respective device under "Device properties > Protection and
Security > Certificate manager".
Detailed instructions can be found in the chapter 2.3.2.
LHTTP
Entry ID: 109763879, V1.0, 05/2019 14
2 Engineering
Configure router
To operate HTTP communication across subnet boundaries, e.g. via the Internet,
you must specify the IP address of your router in the device properties of your PLC.
Proceed as follows:
LHTTP
Entry ID: 109763879, V1.0, 05/2019 15
2 Engineering
With HTTPS, the user data is transmitted in encrypted form. Web server and client
(in this case the PLC) exchange certificates with each other before data transfer. In
order for the PLC to confirm the authenticity of the web server, it must know the
root certificate from which the web server certificate is derived.
In the TIA Portal, the certificates are managed in a global certificate manager. The
certificate manager contains an overview of all certificates used in the project. In
the certificate manager, for example, you can import new certificates and export,
renew, or replace existing certificates. Each certificate is assigned an ID that can
be used to reference the certificate in the program modules.
If you want to transfer data securely using HTTPS, perform the following steps:
1. Open the section "Security settings > Settings" from the project navigation.
2. Click on "Protect this project" and assign a user name and password.
Figure 2-8
© Siemens AG 2019 All rights reserved
LHTTP
Entry ID: 109763879, V1.0, 05/2019 16
2 Engineering
2. Click on the lock in the address bar and then on "Certificate (Valid)".
Figure 2-9
4. Select the top certificate (root certificate from which the others are derived) and
click View Certificate.
Figure 2-10
LHTTP
Entry ID: 109763879, V1.0, 05/2019 17
2 Engineering
LHTTP
Entry ID: 109763879, V1.0, 05/2019 18
2 Engineering
7. From the project navigation, open the "Security settings > Security features >
Certificate manager” area.
8. Open the "Trusted certificates and root certification authorities".
9. Right-click in the workspace and select "Import".
Figure 2-13
10. Import the previously saved certificate from the web server.
Figure 2-14
LHTTP
Entry ID: 109763879, V1.0, 05/2019 19
2 Engineering
LHTTP
Entry ID: 109763879, V1.0, 05/2019 20
2 Engineering
6. Select "Self signed" and the encryption algorithm "sha256RSA" for the highest
compatibility and confirm with "OK".
Figure 2-17
© Siemens AG 2019 All rights reserved
LHTTP
Entry ID: 109763879, V1.0, 05/2019 21
2 Engineering
8. Click the same cell again and select the Web server's imported root certificate.
Figure 2-18
© Siemens AG 2019 All rights reserved
For general information on dealing with libraries in the TIA Portal, see section 3.1.
LHTTP
Entry ID: 109763879, V1.0, 05/2019 22
2 Engineering
5. If you use HTTPS, also create a variable of the PLC data type
"LHTTP_typeTLS" (see section 2.2.6 for information on the PLC data type).
Figure 2-20
created DBs.
Figure 2-22
Note Use different connection IDs at the parameter "connID" if you use "LHTTP_Get"
and "LHTTP_Post" in parallel, use the FBs several times or use the OUC blocks
for other functions in your program.
LHTTP
Entry ID: 109763879, V1.0, 05/2019 23
2 Engineering
or is not supported.
16#8106 The length of the user data could not be read.
16#8107 Chunk-coded message could not be decoded.
16#8300 The web server responded with a redirection. Redirections
are not supported by the LHTTP library.
16#8408 Request timeout. Check the Ethernet connection of the
PLC and the URL.
16#8600 The FB is in an invalid state.
1 -- Error in subordinate statement TSEND_C. See TIA Portal
Information System for Workaround.
2 -- Error of subordinate statement TRCV. See TIA Portal
Information System for Workaround.
3 -- Error of subordinate statement MOV_BLK_VARIANT in
region "TE_IDENTITY". See TIA Portal Information System
for Workaround.
4 -- Error of subordinate statement MOV_BLK_VARIANT in
region "TE_CHUNKED". See TIA Portal Information
System for Workaround.
5 16#9xxx The web server responded with an error message. The
received HTTP status code is output in the back digits of
the output "status".
LHTTP
Entry ID: 109763879, V1.0, 05/2019 24
2 Engineering
Server Error
502 Bad Gateway The server could not fulfill its functionality as a gateway
or proxy because it received an invalid response.
503 Service The server is temporarily unavailable.
Unavailable
504 Gateway The server could not perform its function as a gateway or
Timeout proxy because it did not receive a response from the
servers or services it was using within a specified period
of time.
LHTTP
Entry ID: 109763879, V1.0, 05/2019 25
3 Additional information
3 Additional information
3.1 Libraries in the TIA Portal
Most of the blocks are stored as types in the library. Thus the modules are
versioned and can use the following advantages:
• Central update function for library elements
• Versioning of library elements
Note For information on library use in general, see the Guide to Library Use:
https://support.industry.siemens.com/cs/ww/en/view/109747503
Note All blocks in the library were created according to the programming style guide:
https://support.industry.siemens.com/cs/ww/en/view/81318674
https://support.industry.siemens.com/cs/ww/en/view/37364723
• In less than 10 minutes, TIA Portal: Time Savers – Global libraries
https://support.industry.siemens.com/cs/ww/en/view/78529894
• Which elements from STEP 7 (TIA Portal) and WinCC (TIA Portal) can be
stored in a library as a type or as a copy template?
https://support.industry.siemens.com/cs/ww/en/view/109476862
• How can you automatically open a global library when starting TIA Portal V13
or higher and use it as a corporate library, for example?
https://support.industry.siemens.com/cs/ww/en/view/100451450
LHTTP
Entry ID: 109763879, V1.0, 05/2019 26
4 Appendix
4 Appendix
4.1 Service and support
Industry Online Support
Do you have any questions or need assistance?
Siemens Industry Online Support offers round the clock access to our entire
service and support know-how and portfolio.
The Industry Online Support is the central address for information about our
products, solutions and services.
Product information, manuals, downloads, FAQs, application examples and videos
– all information is accessible with just a few mouse clicks:
https://support.industry.siemens.com
Technical Support
The Technical Support of Siemens Industry provides you fast and competent
support regarding all technical queries with numerous tailor-made offers
– ranging from basic support to individual support contracts. Please send queries
to Technical Support via Web form:
www.siemens.com/industry/supportrequest
© Siemens AG 2019 All rights reserved
Service offer
Our range of services includes the following:
• Plant data services
• Spare parts services
• Repair services
• On-site and maintenance services
• Retrofitting and modernization services
• Service programs and contracts
You can find detailed information on our range of services in the service catalog
web page:
https://support.industry.siemens.com/cs/sc
LHTTP
Entry ID: 109763879, V1.0, 05/2019 27
4 Appendix
LHTTP
Entry ID: 109763879, V1.0, 05/2019 28