16
Application example 06/2017 SIMATIC IOT2000 Connection to Microsoft Azure Cloud SIMATIC IOT2040

Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

Application example � 06/2017

SIMATIC IOT2000 Connectionto Microsoft Azure CloudSIMATIC IOT2040

Page 2: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

Warranty and liability

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 2

S

iem

ens

AG

2017

All

right

sre

serv

ed

Warranty and liability

Note The Application Examples are not binding and do not claim to be completeregarding the circuits shown, equipping and any eventuality. The ApplicationExamples do not represent customer-specific solutions. They are only intendedto provide support for typical applications. You are responsible for ensuring thatthe described products are used correctly. These Application Examples do notrelieve you of the responsibility to use safe practices in application, installation,operation and maintenance. When using these Application Examples, yourecognize that we cannot be made liable for any damage/claims beyond theliability clause described. We reserve the right to make changes to theseApplication Examples at any time without prior notice.If there are any deviations between the recommendations provided in theseApplication Examples and other Siemens publications – e.g. Catalogs – thecontents 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 ofthe examples, information, programs, engineering and performance data etc.,described in this Application Example shall be excluded. Such an exclusion shallnot apply in the case of mandatory liability, e.g. under the German Product LiabilityAct (“Produkthaftungsgesetz”), in case of intent, gross negligence, or injury of life,body or health, guarantee for the quality of a product, fraudulent concealment of adeficiency or breach of a condition which goes to the root of the contract(“wesentliche Vertragspflichten”). The damages for a breach of a substantialcontractual obligation are, however, limited to the foreseeable damage, typical forthe type of contract, except in the event of intent or gross negligence or injury tolife, body or health. The above provisions do not imply a change of the burden ofproof to your detriment.Any form of duplication or distribution of these Application Examples or excerptshereof is prohibited without the expressed consent of the Siemens AG.

Securityinforma-tion

Siemens provides products and solutions with industrial security functions thatsupport the secure operation of plants, systems, machines and networks.In order to protect plants, systems, machines and networks against cyberthreats, it is necessary to implement – and continuously maintain – a holistic,state-of-the-art industrial security concept. Siemens’ products and solutions onlyform 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 beconnected to the enterprise network or the internet if and to the extent necessaryand with appropriate security measures (e.g. use of firewalls and networksegmentation) in place.Additionally, Siemens’ guidance on appropriate security measures should betaken into account. For more information about industrial security, please visithttp://www.siemens.com/industrialsecurity.

Siemens’ products and solutions undergo continuous development to make themmore secure. Siemens strongly recommends to apply product updates as soonas available and to always use the latest product versions. Use of productversions that are no longer supported, and failure to apply latest updates mayincrease customer’s exposure to cyber threats.To stay informed about product updates, subscribe to the Siemens IndustrialSecurity RSS Feed under http://www.siemens.com/industrialsecurity.

Page 3: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

Table of contents

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 3

S

iem

ens

AG

2017

All

right

sre

serv

ed

Table of contentsWarranty and liability ............................................................................................... 21 Task................................................................................................................. 4

1.1 Overview ........................................................................................... 4

2 Application Example ...................................................................................... 5

2.1 Preconditions ..................................................................................... 52.2 Install software on SIMATIC IOT2000 ................................................ 52.3 Test the OPC UA connection ............................................................. 72.4 Create an IoT Hub within Microsoft Azure .......................................... 92.5 Create a device identity ................................................................... 122.6 Use the full application example ....................................................... 132.7 Visualization via Power BI ................................................................ 14

3 Checklist ....................................................................................................... 154 Related links ................................................................................................. 165 History .......................................................................................................... 16

Page 4: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

1 Task

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 4

S

iem

ens

AG

2017

All

right

sre

serv

ed

1 Task1.1 Overview

IntroductionThis application example shows how to browse an OPC UA Server running on aSIMATIC S7-1500, subscribe to the browsed items and send the items’ values toMicrosoft Azure’s IoT Hub.

GoalsAfter working through this document you will know how to∂ Use the example OPC UA Client∂ Send data to the Microsoft Azure IoT Hub with the provided script

NOTICE Precondition!

To use this sample it is required that the Initial Operation in the Document“Setting up the SIMATIC IOT2000” has been executed once.

Page 5: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

2 Application Example

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 5

S

iem

ens

AG

2017

All

right

sre

serv

ed

2 Application ExampleThis application contains an OPC UA Client – written in JavaScript - subscribing allvalues of a Browse Startpoint of the OPC UA Server of the SIMATIC S7-1500Software Controller and sending this data to the Microsoft Azure IoT Hub.

2.1 Preconditions

Make sure that the OPC UA Server on the SIMATIC S7-1500 is running and thatthe SIMATIC S7-1500 is connected to the same IP network as the SIMATICIOT2000. Test the connection to the OPC UA server on S7-1500 via SIMATICOPC Scout or UA OPC Explorer and note down its OPC UA endpoint (IP addressand port number).

2.2 Install software on SIMATIC IOT2000

To use this Application Example use the required scripts downloaded together withthis document (“OPCUA_Azure.zip”).

NOTE For installing the needed packages the IOT2000 requires an internet connection!

The following table shows how to install the additional node.Table 2-2

No. Action

1. Extract the downloaded archive2. Copy the extracted folder (OPCUA_Azure) to a directory of your choice (i.e

using WinSCP)

3. Go to this directory by typing in “cd directory”

Page 6: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

2 Application Example

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 6

S

iem

ens

AG

2017

All

right

sre

serv

ed

No. Action

4. Install the needed node.js packages by typing in “npm install”This lasts a few minutes.

Page 7: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

2 Application Example

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 7

S

iem

ens

AG

2017

All

right

sre

serv

ed

2.3 Test the OPC UA connection

For testing the connection from the SIMATIC IOT2000 to the OPC UA Server of theS7-1500 CPU there is a script called “browse_test_opcua.js”.You can find some possible browse start points in the OPC UA Server XML Exportof the TIA Portal V14. In this case “OPC_UA_Values” is used, which is aDatablock.The following table shows how to use the “browse_test_opcua.js” script

Table 2-1

No. Action

1. Edit “browse_test_opcua.js” by typing in “nano browse_test_opcua.js” orusing the editor of WinSCP.

2. Change IP address/Port of your OPC UA Server, Browse start point andDevideID (optional)

3. Save the file

Page 8: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

2 Application Example

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 8

S

iem

ens

AG

2017

All

right

sre

serv

ed

No. Action

4. Type in “node browse_test_opcua.js” to start the script.First test should output some values read from the OPC UA server. Interruptit via Ctrl+C.

Page 9: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

2 Application Example

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 9

S

iem

ens

AG

2017

All

right

sre

serv

ed

2.4 Create an IoT Hub within Microsoft Azure

NOTE For all the following steps of this document the IOT2000 requires an internetconnection!

Create an IoT Hub for your SIMATIC IOT2000 to connect to.The following table shows how to complete this task by using the Azure portal.

Table 2-2

No. Action

1. Sign in to the Azure portal2. In the Jumpbar, click New > Internet of Things > IoT Hub.

Page 10: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

2 Application Example

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 10

S

iem

ens

AG

2017

All

right

sre

serv

ed

No. Action

3. In the IoT hub blade, choose the configuration for your IoT hub.

∂ In the Name box, enter a name for your IoT hub. If the Name is validand available, a green check mark appears in the Name box.

∂ Select a pricing and scale tier. This tutorial does not require a specifictier. For this tutorial, use the free F1 tier.

∂ In Resource group, either create a resource group, or select anexisting one. For more information, see Using resource groups tomanage your Azure resources.

∂ In Location, select the location to host your IoT hub. For this tutorial,choose your nearest location.

Page 11: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

2 Application Example

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 11

S

iem

ens

AG

2017

All

right

sre

serv

ed

No. Action

4. When you have chosen your IoT hub configuration options, click Create. Itcan take a few minutes for Azure to create your IoT hub. To check the status,you can monitor the progress on the Startboard or in the Notifications panel.

5. When the IoT hub has been created successfully, click the new tile for yourIoT hub in the Azure portal to open the blade for the new IoT hub.Make a note of the Hostname, and then click Shared access policies.

6. In the Shared access policies blade, click the iothubowner policy and thencopy and make note of the IoT Hub Connection String inthe iothubowner blade. For more information, see Access control in the "IoTHub developer guide

7. You have now created your IoT hub. You have the IoT Hub Hostname andthe IoT Hub Connection String that you need to complete the rest.

Page 12: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

2 Application Example

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 12

S

iem

ens

AG

2017

All

right

sre

serv

ed

2.5 Create a device identity

In this section we create a device identity in the identity registry in your IoT hub. A device cannotconnect to IoT hub unless it has an entry in the identity registry.

For more information, see the Identity Registry section of the IoT Hub developer guide.

When you run this console app, it generates a unique device ID and key that your device canuse to identify itself when it sends device-to-cloud messages to IoT Hub.

Table 2-3

No. Action

1. Edit the script” CreateDeviceIdentity.js”: replace the placeholder value withthe IoT Hub Connection String for the hub you created in the previoussection, and edit the device name (optional).

2. Save the file3. Run the” CreateDeviceIdentity.js” script by typing in “node

CreateDeviceIdentity.js”4. Make a note of the Device ID and Device Key for your connection string

which is an output of the script.

Page 13: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

2 Application Example

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 13

S

iem

ens

AG

2017

All

right

sre

serv

ed

2.6 Use the full application example

Now you have all required information that you need to send data to the IoT Hub ofthe Microsoft Azure Cloud.

Table 2-4

No. Action

1. Edit the script „application_example.js”2. Change IP address/Port of your OPC UA Server, Browse start point and

DevideID (optional)Use the same data as in Table 2.1, No.2

3. Use Hostname, DeviceID and Device Key to complete your ConnectionString

4. Save the file5. Run the Application Example by typing in “node application_example.js”6. The Usage tile in the Azure portal shows the number of messages sent to

the IoT hub:

Page 14: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

2 Application Example

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 14

S

iem

ens

AG

2017

All

right

sre

serv

ed

2.7 Visualization via Power BIIn order to display the sent data you can use for example Power BI.

Figure 2-1

How to setup Power BI is described here.

NOTE To sign up to Power BI a business email address is required!

Page 15: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

3 Checklist

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 15

S

iem

ens

AG

2017

All

right

sre

serv

ed

3 ChecklistThis chapter contains a Checklist which summarizes all important steps in thisapplication example.

Table 3-1

No. Action

1. Make sure preconditions are given2. Copy files to the SIMATIC IOT20003. Install the required software4. Test OPC UA connection5. Create an Microsoft Azure IoT Hub6. Make note of the Hostname7. Make note of the Connection String8. Create Device Identity using Connection String9. Make note of the DeviceID and the Device Key10. Use full application example11. Change OPC UA data in “application_example.js”12. Edit “var connectionString” using Hostname, DeviceID and Device Key

Page 16: Application example 06/2017 SIMATICIOT2000 Connection to ......2 Application Example SIMATIC IOT2000 Connection Microsoft Azure Cloud Version 1.0, 06/2017 10 S i e m e n s A G 2 0

4 Related links

SIMATIC IOT2000 Connection Microsoft Azure CloudVersion 1.0, 06/2017 16

S

iem

ens

AG

2017

All

right

sre

serv

ed

4 Related links

Table 4-1

Topic

\1\ SIMATIC IOT2000 forumwww.siemens.com/iot2000-forum

\2\ SIMATIC IOT2000 Setting Uphttps://support.industry.siemens.com/tf/ww/en/posts/155642/

\3\ SIMATIC IOT2000 Getting Startedhttps://support.industry.siemens.com/tf/ww/en/posts/155643/

\4\ IoT Hub Getting Startedhttps://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-node-node-getstarted

\5\ Power BIhttps://blogs.msdn.microsoft.com/uk_faculty_connection/2016/03/20/consuming-data-on-microsoft-azure-iot-hub-into-microsoft-power-bi/

\6\ Microsoft Azure Portalhttps://portal.azure.com/

5 History

Table 5-1

Version Date Modifications

V1.0 06/2017 First version