Professional Documents
Culture Documents
S7-1200 / S7-1500
CPUs for connecting
to MindSphere
Siemens
Blocks for S7-1200 / S7-1500 CPUs Industry
Online
https://support.industry.siemens.com/cs/ww/en/view/109772284 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.
Table of contents
Legal information ......................................................................................................... 2
1 Introduction ........................................................................................................ 4
1.1 Overview............................................................................................... 4
1.2 Principle of operation............................................................................ 6
1.3 Components used ................................................................................ 8
2 Engineering ........................................................................................................ 9
2.1 Block description .................................................................................. 9
2.1.1 FB "LMindConn_MQTT" interface description ..................................... 9
2.1.2 FC "MindSphereDataStringCollector" interface description ............... 12
2.1.3 FC "ConvertValueToMsString" interface description ......................... 13
2.1.4 Overview of data types ....................................................................... 14
2.2 Configuration ...................................................................................... 17
2.2.1 Connecting components..................................................................... 17
2.2.2 Create TIA Portal Project ................................................................... 17
2.3 Integrating FB and Fcs into the user program ................................... 20
2.3.1 Opening "LMindConn_MQTT" Global Library .................................... 20
2.3.2 Copying FB, FCs into the user program ............................................. 22
2.3.3 Calling FB "LMindConn_MQTT" in the user program ........................ 23
2.3.4 Calling FC "MindSphereDataStringCollector" in the user
program .............................................................................................. 26
2.3.5 Creating global data blocks ................................................................ 28
© Siemens AG 2019 All rights reserved
1 Introduction
1.1 Overview
Motivation
Digitization has a major impact on the economy and society and is progressing
inexorably. The "Internet of Things" (short: IoT) is one of the main drivers of
digitization. The term "Internet of Things" is synonymous with one of the biggest
current dynamics of change: The increasing networking and automation of devices,
machines and products.
The protocol "Message Queue Telemetry Transport" (short: MQTT) is used in the
"Internet of Things" as a communication protocol. Its lightweight approach opens
up new possibilities for automation.
Features of MQTT
The MQTT protocol is distinguished by the following features:
© Siemens AG 2019 All rights reserved
Applicative implementation
MindSphere is the cloud-based, open IoT operating system from Siemens. Using
the "MindConnect IoT Extension" upgrade, it is possible to connect devices to
MindSphere over MQTT.
In order to implement the MQTT protocol in a SIMATIC S7 CPU and transmit data
to MindSphere, the library "LMindConn_MQTT" offers you an adequate solution.
The "LMindConn_MQTT" library provides you with function blocks for the
SIMATIC S7-1500 and the SIMATIC S7-1200 CPUs. The function blocks integrate
the MQTT client function. It enables the following functions:
• Transmitting MQTT messages to "MindConnect IoT Extension" (publisher role)
• Receive messages from "MindConnect IoT Extension" (subscriber role)
The communication can be secured via a TLS connection.
Note When transmitting characters (Char) and character sequences (String), only
UTF-8 Chars are permitted.
© Siemens AG 2019 All rights reserved
Engineering MindSphere
Certificate Store
idx Cert_Name 1
1 Cert_xy
Topic x Topic z
S7-CPU 3 Message Message
(MQTT-Client) Topic y
Message
Topic y
Message
© Siemens AG 2019 All rights reserved
Publish
Subscribe
Table 1-1
Step Description
1 Determine the CA certificate of the MQTT broker.
2 Importing the third-party certificate into STEP 7 (TIA Portal) The certificate
is now in the global certificate manager of STEP 7.
3 You must assign the imported certificate to the S7 CPU. To recognize the
certificate as valid, the time of the S7 CPU must be current.
4 The "LMindConn_MQTT" takes over the following functions:
• Conversion of data points to a MindSphere-conformant string
• Establish connection to the MQTT broker "MindConnect IoT
Extension" in MindSphere
• Publisher to send MQTT messages to MindSphere
• Subscriber to receive MQTT messages from MindSphere
MindSphere
DataString
Values
© Siemens AG 2019 All rights reserved
Table 1-2
No. FB / FC Description
1 FB "LMindConnMQTT" Controls the communication
between S7 CPU and
MindSphere based on MQTT
protocol.
2 FC "ConvertValueToMsString" This function converts the value
of a data point to a MindSphere-
conformant string (MQTT
payload).
3 FC "MindSphereDataStringCollector" This function generates a
MindSphere-conformant string in
order to send the values of up to
50 data points to MindSphere.
2 Engineering
2.1 Block description
Note In TIA Portal V16 the FB and the FCs from the "LMindConn_MQTT" library are
available for S7-1500 CPUs and S7-1200 CPUs.
In STEP 7 V15.1 the FB and the FCs from the "LMindConn_MQTT" library are
available for S7-1500 CPUs.
The FB and the Fcs are designed for "optimized block access".
Input parameters
Table 2-1
Parameter Data type Description
connect Bool Control input
© Siemens AG 2019 All rights reserved
Output parameters
Table 2-2
Parameter Data type Description
connectionEstablished Bool True if following conditions are met:
• TCP connection is established
(instLMQTT_Client.tcpEstablished = true)
• MQTT connection is established
(instLMQTT_Client.mqttEstablished = true)
The FB is ready to send PUBLISH packets.
done Bool True for a cycle if the job for sending a PUBLISH
packet was successfully completed.
busy Bool TRUE if one of the following jobs is running:
• Connection setup
• Sending PUBLISH packet (one-time or
continuous)
• Creating shell in MQTT broker "MindConnect
IoT Extension" and receiving messages on
the topic "s/ds"
error Bool TRUE for a cycle if an error occurs, e.g.
• while the connection is being established
• for a current job
• connection is broken
© Siemens AG 2019 All rights reserved
In/out parameters
Table 2-3
Parameter Data type Description
mindSphereDataMessage WString MindSphere-conformant string (MQTT payload),
which is assembled in the FC
"MindSphereDataStringCollector".
receivedData "LMindConn_MQTT_ Received data from MQTT broker "MindConnect
typeMindSphere IoT Extension" (topic and message)
Message" You can find detailed information on the structure
of the PLC data type
"LMindConn_typeMindSphereMessage" in
chapter 2.1.4.
userParams "LMindConn_MQTT_ Data structure containing parameters for carrying
typeUserData" out the following functions:
• actively establish a connection to MQTT
broker "MindConnect IoT Extension"
• register device in MQTT broker "MindConnect
IoT Extension"
You can find detailed information on the structure
of the PLC data type "LMindConn_typeUserData"
in chapter 2.1.4.
instParamMqttClient "LMQTT_Client" Instance DB of the FB "LMQTT_Client"
© Siemens AG 2019 All rights reserved
Output parameters
Table 2-4
Parameter Data Description
type
Ret_val Word Status display:
• 16#8200: The length of the MindSphere-conformant string is greater
than the maximum allowed length of the MQTT payload (16384 bytes).
done Bool TRUE if the task of the Function (FC) was completed successfully, meaning
that the task of creating a MindSphere-conformant string was completed
successfully.
error Bool TRUE for a cycle if an error occurs
errorID DInt ID of data point that originated the error. Possible causes for an error are:
• The value that you want to transmit to MindSphere is not supported by
MindSphere.
• No data point for the value has been defined in MindSphere.
• When converting to a MindSphere-conformant string, the value was
assigned no template (200 or 400).
© Siemens AG 2019 All rights reserved
In/out parameters
Table 2-5
Parameter Data type Description
mindSphereDataString WString MindSphere-conformant string
containing all defined data points.
datapointDefinition Array[*] of "LMindConn_MQTT_ Display of MindSphere data points
typeMindsphereDatapoint" You can find detailed information on the
structure of the PLC data type
"LMindConn_MQTT_
typeMindsphereDatapoint" in
chapter 2.1.4.
value1 Variant Value to be sent to MindSphere. Define
"NULL" if the value is not used.
value2 Variant Value to be sent to MindSphere. Define
"NULL" if the value is not used.
value3 Variant Value to be sent to MindSphere. Define
"NULL" if the value is not used.
…
value50 Variant Value to be sent to MindSphere. Define
"NULL" if the value is not used.
Input parameters
Table 2-6
Parameter Data type Description
value Variant Value to be sent to MindSphere.
Output parameters
Table 2-7
Parameter Data type Description
error Bool TRUE if an error occurs
status Word Status display:
• 16#8100: Data type of the value to be transmitted is
not supported by MindSphere.
• 16#8102: No data point has been defined for the
value, or the MindSphere-conformant contains no
"200" or "400" template.
© Siemens AG 2019 All rights reserved
In/out parameters
Table 2-8
Parameter Data type Description
datapoint "LMindConn_MQTT_ Display of MindSphere data point
typeMindsphereDatapoint" You can find detailed information on the structure of the
PLC data type
"LMindConn_MQTT_typeMindsphereDatapoint" in
chapter 2.1.4.
To structure the data clearly, several data types have been created. The data types
used in the program are shown in the following list:
• "LMindConn_MQTT_typeDiagnostics"
• "LMindConn_MQTT_typeMindSphereMessage"
• "LMindConn_MQTT_typeUserData"
• "LMindConn_MQTT_typeMindsphereDatapoint"
"LMindConn_MQTT_typeDiagnostics"
This data type contains additional information on the error that has occurred in the
FB "LMindConn_MQTT".
The following table shows the structure of the
"LMindConn_MQTT_typeDiagnostics" data type.
Table 2-9
Parameter Data type Start value Description
subFBStatus DWord 16#0 Status display of the
FB "LMQTT_Client"
Detailed information can be found in
the Application Example at the Article
© Siemens AG 2019 All rights reserved
ID 109748872.
stateNumber DInt 0 Status number in the state machine
of the FB "LMindConn_MQTT" where
the error occurred.
You can find an overview of the
FB "LMindConn_MQTT" in
chapter 3.2.2.
subFBstateNumber DInt 0 Status number in the state machine
of the FB "LMQTT_Client" where the
error occurred.
Detailed information can be found in
the Application Example at the Article
ID 109748872.
"LMindConn_MQTT_typeMindSphereMessage"
This data type contains the received data from MQTT broker "MindConnect IoT
Extension" (topic and message).
The following table shows the structure of the
"LMindConn_MQTT_typeMindSphereMessage" data type.
Table 2-10
Parameter Data type Start value Description
topic WString[25] 'WSTRING#' Topic of the message that was
received.
message WString[300] WSTRING#'' Message that was received from the
MQTT broker "MindConnect IoT
Extension".
"LMindConn_MQTT_typeUserData"
This data type contains parameters in order to execute the following functions:
• actively establish a connection to MQTT broker "MindConnect IoT Extension"
and maintain it
• register user in MQTT broker "MindConnect IoT Extension"
• register device in MQTT broker "MindConnect IoT Extension"
The following table shows the structure of the "LMindConn_MQTT_typeUserData"
data type.
Table 2-11
Parameter Data type Start value Description
hwInterfaceId HW_ANY 0 HW ID of the PROFINET interface
of CPU or CP
connID CONN_OUC 16#0 ID of the TCP connection
ipAddressBroker Array[0..3] of ipAddressBroker[0] = IP address of the MQTT broker, e.g.
© Siemens AG 2019 All rights reserved
USInt 0 192.168.0.10
ipAddressBroker[1] = ipAddressBroker[0] = 192
0 ipAddressBroker[1] = 168
ipAddressBroker[2] = ipAddressBroker[2] = 0
0 ipAddressBroker[3] = 10
ipAddressBroker[3] =
0
urlAddressBroker String "" URL of the MQTT broker. The URL
must end with a dot (".").
Use the URL of MindConnect IoT
Extension, e. g.
mciotextension.eu1.mindsphere.io.
activateSecureComm Bool True True: Communication is secured via
TLS.
idTlsServerCertificate UInt 0 ID of the X.509 V3 certificate
(usually a CA certificate) to validate
the TLS server authentication. If this
parameter is "0", the TLS client
uses all (CA) certificates currently
loaded in the client's certificate store
to validate server authentication.
Only relevant when
"activateSecureConn" equals "true".
mqttUsername String[100] "" User name for logging on to the
MQTT broker.
Usually the e-mail address is used
as username to log into
MindConnect IoT Extension.
Set the username in following form:
"tenant/username".
"LMindConn_MQTT_typeMindsphereDatapoint"
© Siemens AG 2019 All rights reserved
2.2 Configuration
2.2.1 Connecting components
MindSphere
Internet
Internet
S7 CPU connection
Industrial Ethernet
Router
© Siemens AG 2019 All rights reserved
1. Create a TIA Portal project with the S7 CPU that you want to use for the
Application Example.
2. In the hardware and network editor, open the device view of the S7 CPU.
3. Select the S7 CPU. The properties of the S7 CPU are displayed in the
Inspector window.
4. In the "General" tab, navigate to "PROFINET interface [X1] > Ethernet
addresses" and enter the IP address and subnet mask for the Ethernet
interface of the CPU.
6. In the "General" tab, navigate to "DNS configuration" and enter the IP address
of the DNS server.
© Siemens AG 2019 All rights reserved
Note For the secured MQTT communication via TLS you need one of the following
components:
Requirement
• STEP 7 (TIA Portal) is open.
• You have created a new project in STEP 7 (TIA Portal) or have opened an
existing project.
• You have imported the certificate "QuoVadis Root CA 2 G3.cer" for
MindSphere into your STEP 7 project. Instructions on how to import the
certificate "QuoVadis Root CA 2 G3.cer" into STEP 7 (TIA Portal) can be found
in chapter 2.4.
Instructions
1. In the TIA Portal project, click the "Libraries" task card and open the "Global
Libraries" palette.
2. Click on the "Open global library" button. The "Open global library" dialog is
opened.
© Siemens AG 2019 All rights reserved
1. In the "LMindConn_MQTT" library you will find the FB and the FCs for the
S7-1500 CPUs and S7-1200 CPUs under "Types > 01_Blocks".
In the "LMindConn_MQTT" library you will find the used PLC data types under
"Types > 02_Types".
Figure 2-2
© Siemens AG 2019 All rights reserved
2. Insert the FB and the FCs for your S7 CPU via drag & drop into the folder
"Program blocks" of your device, e.g. S7-1500 CPU.
3. The data types that are used by the FB and the FCs are automatically inserted
into the folder "PLC data types" on your device, e.g. the S7-1500 CPU.
4. The FB "LMQTT_Client", which is used by the FB "LMindConn_MQTT", is
automatically inserted into the "Program blocks" folder of your device, e.g. the
S7-1500 CPU.
© Siemens AG 2019 All rights reserved
1. In the "Project tree" open the folder "Program blocks" of your CPU.
2. Double-click on the block "Main [OB1]" to open the corresponding program
editor.
3. Drag & drop the FB "LMindConn_MQTT" from the project tree to any OB 1
network.
6. Populate the inputs and outputs of the function block with the tags that you
created in the data block (see chapter 2.3.3 and 2.3.6).
© Siemens AG 2019 All rights reserved
1. In the "Project tree" open the folder "Program blocks" of your CPU.
2. Double-click on the block "Main [OB1]" to open the corresponding program
editor.
3. Drag & drop the FC "MindSphereDataStringCollector" from the project tree to
any OB 1 network.
© Siemens AG 2019 All rights reserved
4. Populate the inputs and outputs of the function block with the tags that you
created in the data block (see chapter 2.3.3).
© Siemens AG 2019 All rights reserved
This chapter shows you how to create global data blocks. These DBs have the
following functions:
• Definition of connection parameters
• Control and monitoring of communication with MindSphere
• Saving of MindSphere-conformant Strings (MQTT payload)
• Definition of tags whose values are sent to MindSphere
• Saving of received data
• Defining data points
3. Make the following settings and then confirm your entries with the "OK" button.
– Select the symbol "Data block".
– Select "Global DB" as the type.
– Enter the name of the DB, e.g. "ConnectionData".
– Activate the "Automatic" radio button for automatic number assignment.
The number of the global DB is assigned by the TIA Portal.
© Siemens AG 2019 All rights reserved
3. Make the following settings and then confirm your entries with the "OK" button.
– Select the symbol "Data block".
– Select "Global DB" as the type.
– Enter the name of the DB, e.g. "ControlAndDiagnostic".
– Activate the "Automatic" radio button for automatic number assignment.
The number of the global DB is assigned by the TIA Portal.
© Siemens AG 2019 All rights reserved
3. Make the following settings and then confirm your entries with the "OK" button.
– Select the symbol "Data block".
– Select "Global DB" as the type.
– Enter the name of the DB, e.g. "MindSphereData".
– Activate the "Automatic" radio button for automatic number assignment.
© Siemens AG 2019 All rights reserved
3. Make the following settings and then confirm your entries with the "OK" button.
– Select the symbol "Data block".
– Select "Global DB" as the type.
– Enter the name of the DB, e.g. "MindSphereDatapoints".
– Activate the "Automatic" radio button for automatic number assignment.
The number of the global DB is assigned by the TIA Portal.
© Siemens AG 2019 All rights reserved
6. Adjust the initial values for your data points to suit your application. In this
Application Example, 5 data points are defined.
7. Interconnect the tags with the FC "MindSphereDataStringCollector".
Table 2-16
Name Data type Interconnection at the
FC
datapoints Array[1.."MAX_DATAPOINTS"] of In/out parameter
"LMindConn_MQTT_ "datapointDefinition"
typeMindSphereDatapoint"
3. Make the following settings and then confirm your entries with the "OK" button.
– Select the symbol "Data block".
– Select "Global DB" as the type.
– Enter the name of the DB, e.g. "Values".
– Activate the "Automatic" radio button for automatic number assignment.
The number of the global DB is assigned by the TIA Portal.
© Siemens AG 2019 All rights reserved
6. Adjust the initial values for your numbers to suit your application.
7. Interconnect the tags with the FC "MindSphereDataStringCollector".
Table 2-17
Name Data type Interconnection at the
FC
motorSpeed Real Input "value1"
motortemperature Int Input "value2"
eventWarning String Input "value3"
sensorLifetime DInt Input "value4"
sensorStatus DWord Input "value5"
getValuesAndGenerateString Bool Input "EN"
3. Make the following settings and then confirm your entries with the "OK" button.
– Select the symbol "Data block".
– Select "LMQTT_Client" as type.
– Enter the name of the DB, e.g. "InstLMQTT_Client".
–
© Siemens AG 2019 All rights reserved
FB "LMindConn_MQTT"
Figure 2-5
© Siemens AG 2019 All rights reserved
FC "MindSphereDataStringCollector"
Figure 2-6
© Siemens AG 2019 All rights reserved
certificate manager".
Result
The new entry "Security Settings" appears in the project navigation.
Logging on users
After you have enabled the global security settings for the certificate manager, you
must log in to the security settings. You cannot access the global certificate
manager without logging in.
Log on as a security user for the security settings as described below:
1. Double-click "Settings" in the project navigation under "Security settings".
The user management editor opens, and the project protection area is
displayed.
2. Click the "Protect this project" button.
This opens the dialog "Protect Project".
Result
User administration is active. You are logged in as a project administrator and can
use the security settings.
If you have logged in, a line "Certificate manager" appears under the entry
"Security settings > Security features".
© Siemens AG 2019 All rights reserved
Result
The CA certificate of the MQTT broker "MindConnect IoT Extension" is located in
the global certificate manager.
Figure 2-7
The CA certificate is currently only located in the global certificate manager of the
TIA Portal. Certificates imported via the certificate manager in the global security
© Siemens AG 2019 All rights reserved
3. Go to the section "Certificates of the partner devices". Click "Add" in the table
© Siemens AG 2019 All rights reserved
4. Click in the new row. The selection for new certificates opens.
Result
The selected certificate was assigned to the S7 CPU and provided with an ID. The
ID is the number of the certificate. You enter this value in the connection
parameters for the parameter "idTlsServerCertificate" (see Table 2-11).
Figure 2-8
Log in to MindSphere and open the "Asset Manager" using the MindSphere
Launchpad.
Figure 2-9
© Siemens AG 2019 All rights reserved
Creating an aspect
1. Select "Aspects" in the menu bar and click on "Create aspect" to create an
aspect.
© Siemens AG 2019 All rights reserved
5. Create a type.
Creating a type
1. Select "Types" in the menu bar and click on "Create type" to create a type.
5. Create an asset.
Asset creation
1. Select "Assets" in the menu bar and click on "Create asset" to create an asset.
Register device
1. Open the MindConnect IoT Extension via the MindSphere Launchpad.
– Send the MQTT control packet with the topic "s/us" and the message text
for device registration.
3. Click on the device to open it.
4. Adjust the update interval (e.g. 1 minute) to monitor the connection and display
connection-related data.
The device data display the device name and device type that you entered in
STEP 7 (TIA Portal) in the connection parameters.
© Siemens AG 2019 All rights reserved
Note The Measurements item is not available until the data points have been sent for
the first time.
Create a group
1. Under "Groups" click "Add group".
2. Enter the group name, e.g. "MyGroup".
3. Click "Add group" to create a group.
4. Open the registered device under "Devices > All devices" and click "Edit".
© Siemens AG 2019 All rights reserved
5. Check the newly created group and click "Assign" to assign the device to a
group.
Device mapping
1. Under "Device mapping > Device mapping", assign the newly created asset
and the tags to the device and the data points.
2. In the "Devices" section, click on the newly created group. The assigned
device is displayed.
3. Select the device.
4. In the "Assets" section, select the newly created asset.
5. In the "Mappings" section, select the "Measurement mapping" options to
execute the assignment for numerical values, then click the command "Add
mapping". The "Add mapping" dialog opens.
© Siemens AG 2019 All rights reserved
Result
All measurement mappings that were created are shown in the "Mappings"
section. Status is "NEW".
10. In the "Mappings" section, select the "Event-data mapping" option to execute
the assignment for characters and Strings, then click the command "Add
mapping". The "Add mapping" dialog opens.
11. Select the "Event-data mapping" option.
12. Select the data point as source.
13. For a target, select the aspect and the tag to which the data point will be
assigned.
14. Click the "Add" button to add the assignment.
11
12
© Siemens AG 2019 All rights reserved
13
14
Result
All created Event-data mappings are displayed in the "Mappings" section.
Status is "NEW".
15
Result
The sent notification is displayed in the received data of the S7 CPU.
5. The assigned Chars and Strings are displayed in the table view.
Figure 2-10
© Siemens AG 2019 All rights reserved
Before you can test the Application Example, you must set the parameters for the
secured or unsecured TCP connection to the MQTT broker "MindConnect IoT
Extension" and for MQTT according to your specifications.
All parameters which you can define yourself are located in the global data block
"ConnectionData". Set the parameters in the "Start value" column.
Above all, you must enter your own value for the following parameters:
• IPv4 address or domain name of the MQTT Broker (URL of the MindConnect
IoT Extension). The domain name must end with a ".".
• Parameters for secure communication
– Status of the security feature (On/Off) for this connection. The security
function is activated by default.
– ID of the CA certificate (only relevant for a secure connection)
• MQTT parameters, e.g.
– Logon information to the MQTT broker "MindConnect IoT Extension": User
name and password
– Device name: Here, enter the name that will be created as a device name
for the device in MQTT broker "MindConnect IoT Extension".
© Siemens AG 2019 All rights reserved
– Device type: Here, enter the name that will be created as a device type for
the device in MQTT broker "MindConnect IoT Extension".
• Set the clock time of the S7 CPU.
Then load the project into your CPU.
Note If the TCP connection is established via the fully qualified domain name, you
must configure a DNS server in the CPU (see chapter 2.2.2).
2.6.2 Operation
Note MindSphere accepts a "payload" in the MQTT control packets with a maximum
length of 16384 bytes.
© Siemens AG 2019 All rights reserved
"status"
The output parameter "status" displays the error code:
Table 2-19
status Description Remedy
16#8300 User name and password for logon Enter the logon data in the
to MQTT broker "MindConnect IoT parameters "mqttUsername" and
Extension" are not defined. "mqttPassword" of the data type
"LMindConn_MQTT_typeUserData".
16#8400 The MindSphere-conformant string MindConnect IoT Extension supports
is too long. a max. message length of
16384 bytes.
16#8500 Multiple tasks are triggered at the In each case only trigger one task.
same time:
• "connect" and
"sendMessageDataOnce"
• "connect" and
"openCommandShell"
© Siemens AG 2019 All rights reserved
• "sendMessageDataOnce" and
"openCommandShell"
16#8600 An error has occurred in the Evaluate the "diagnostics" output.
FB "LMQTT_Client". You can find detailed information on
the "diagnostics" output in
chapter 2.1.4.
16#7000 FB "LMindConn_MQTT" is not Status information
active. Activate the FB "LMindConn_MQTT"
by setting the "connect" input to
"true".
16#7001 Connection to MQTT broker Status information
"MindConnect IoT Extension" is
established. It is possible to register
the device.
16#7002 Device is registered in MQTT Status information
broker "MindConnect IoT
Extension". Data can be sent and
received via MQTT.
"diagnostics"
You can find detailed information on the "diagnostics" output in chapter 2.1.4.
3 Useful information
3.1 Structure of the MindSphere-conformant string
3.1.1 Structure of the MQTT control packets
Fixed header
Req'd for all control packets
Variable header
Req'd for some control packets
Payload
Req'd for all control packets
Note MindSphere accepts a "payload" in the MQTT control packets with a maximum
© Siemens AG 2019 All rights reserved
Once an MQTT client connects to the MQTT broker, it can send messages to the
MQTT broker.
To do this, the MQTT client uses the "PUBLISH" packet. Because MQTT
messages are filtered and managed based on topics, each MQTT message must
contain a topic. The topic is part of the "Variable Header". The actual message text
is contained in the "payload".
The topic "s/us" is used to send data to MindSphere via MQTT. The message text
is arranged in a strictly defined structure.
Sending values
The figure below shows the structure of the message text for sending numeric
values. The template "200" is used for sending numeric values.
Figure 3-3
The figure below shows the structure of the message text for sending characters
(Char) and character sequences (String). The template "400" is used for sending
characters (Char) and character sequences (String).
Figure 3-4
Note When sending characters (Char) and character sequences (String), only UTF-8
Chars are permitted.
Template, c8y_Command
114, c8y_Command
Once an MQTT client has connected to the MQTT broker, it can create
subscriptions.
To create a subscription, the MQTT client uses the "SUBSCRIBE" packet. In order
to receive data from MindSphere via MQTT, the topic "s/ds" is subscribed to.
The topic "s/ds", to which the MQTT client would like to subscribe, is stored in the
"Payload".
Note Only UTF-8 Chars are allowed in the message to the subscribed topic "s/ds".
Note An MQTT connection setup is only possible if the TCP connection to the MQTT
broker is successfully established and then maintained.
An MQTT message can only be sent or received if there is a TCP and MQTT
connection to the MQTT broker.
3.2.2 Overview
State Description
PUBLISH In this state, the task for sending the message is started.
If the message has been sent successfully, the
FB "LMindConn_MQTT" switches to the "CONNECTED"
state.
If an error occurs while sending the message, the
FB "LMindConn_MQTT" switches to the
"STATE_ERROR" state.
SUBSCRIBE In this state, the task for subscribing to the topic "s/ds" is
started.
If the topic was successfully subscribed, the
FB "LMindConn_MQTT" switches to the "PUBLISH" state
in order to send the MindSphere-conformant String
needed for creating a shell.
The FB "LMindConn_MQTT" now receives messages on
the topic "s/ds".
If an error occurs while subscribing to the topic "s/ds", the
FB "LMindConn_MQTT" switches to the
"STATE_ERROR" state.
DISCONNECTED The FB "LMindConn_MQTT" switches to this state when a
negative edge is identified at the input parameter
"connect".
In this state, all parameters are reset. The
FB "LMindConn_MQTT" switches to the "IDLE" state
without any other step enabling condition.
© Siemens AG 2019 All rights reserved
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
Table 4-2
Version Date Change
V1.0 12/2019 First edition
V1.1 03/2020 • CP1243-1 and CP1243-7 LTE are added in
chapter 1.3 "Components used"
• The order is changed in chapter 2.3
• The screenshots are updated which have still shown
"LMQTT_instClient"