You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by cd...@apache.org on 2018/08/13 15:08:55 UTC

[incubator-plc4x] branch DerDackel-s7_azure_iothub_example created (now d0d80ea)

This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a change to branch DerDackel-s7_azure_iothub_example
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git.


      at d0d80ea  Manually updated the project: - Added ASF headers - Made the Maven build work (Were version conflicts in the MS dependencies) - Fixed some little problems in the Example itself.

This branch includes the following new commits:

     new 5202c9d  Implement basic example of connecting an S7 device to Azure IoT Hub
     new 552385d  Merge branch 's7_azure_iothub_example' of https://github.com/DerDackel/incubator-plc4x into DerDackel-s7_azure_iothub_example
     new 1436e2c  Merge branch 'master' of github.com:apache/incubator-plc4x into DerDackel-s7_azure_iothub_example
     new d0d80ea  Manually updated the project: - Added ASF headers - Made the Maven build work (Were version conflicts in the MS dependencies) - Fixed some little problems in the Example itself.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-plc4x] 04/04: Manually updated the project: - Added ASF headers - Made the Maven build work (Were version conflicts in the MS dependencies) - Fixed some little problems in the Example itself.

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch DerDackel-s7_azure_iothub_example
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit d0d80eabc497954fa89d200bc5449c46332648c3
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Aug 13 17:08:28 2018 +0200

    Manually updated the project:
    - Added ASF headers
    - Made the Maven build work (Were version conflicts in the MS dependencies)
    - Fixed some little problems in the Example itself.
---
 examples/azure/pom.xml                             | 62 +++++++++++++++++++---
 .../azure/iothub/S7PlcToAzureIoTHubSample.java     | 27 ++++++++--
 2 files changed, 79 insertions(+), 10 deletions(-)

diff --git a/examples/azure/pom.xml b/examples/azure/pom.xml
index 0e010a9..b84f0d7 100644
--- a/examples/azure/pom.xml
+++ b/examples/azure/pom.xml
@@ -1,15 +1,53 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+-->
 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
   <parent>
     <artifactId>examples</artifactId>
     <groupId>org.apache.plc4x.examples</groupId>
     <version>0.0.1-SNAPSHOT</version>
   </parent>
-  <modelVersion>4.0.0</modelVersion>
 
   <artifactId>azure</artifactId>
+  <name>Examples: Azure IoT Hub</name>
+  <description>
+    Implementation of a PLC4X application gathering information from
+    a PLC and making that available in an Azure IoT Hub.
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <configuration>
+          <usedDependencies>
+            <usedDependency>org.apache.plc4x:plc4j-protocol-s7</usedDependency>
+          </usedDependencies>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
 
   <dependencies>
     <dependency>
@@ -22,17 +60,29 @@
       <artifactId>plc4j-core</artifactId>
       <version>0.0.1-SNAPSHOT</version>
     </dependency>
-    <dependency>
-      <groupId>org.apache.plc4x</groupId>
-      <artifactId>plc4j-protocol-s7</artifactId>
-      <version>0.0.1-SNAPSHOT</version>
-    </dependency>
 
     <dependency>
       <groupId>com.microsoft.azure.sdk.iot</groupId>
       <artifactId>iot-device-client</artifactId>
       <version>1.3.30</version>
     </dependency>
+
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-protocol-s7</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+      <scope>runtime</scope>
+    </dependency>
   </dependencies>
 
+  <dependencyManagement>
+    <dependencies>
+      <dependency>
+        <groupId>org.apache.qpid</groupId>
+        <artifactId>proton-j</artifactId>
+        <version>0.18.0</version>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
 </project>
\ No newline at end of file
diff --git a/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java b/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java
index 0e183c3..ec046bc 100644
--- a/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java
+++ b/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java
@@ -1,3 +1,21 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
 package org.apache.plc4x.java.examples.azure.iothub;
 
 import com.microsoft.azure.sdk.iot.device.*;
@@ -30,25 +48,26 @@ public class S7PlcToAzureIoTHubSample {
     /**
      * Example code do demonstrate sending events from an S7 device to Microsoft Azure IoT Hub
      *
-     * @param args Expected: [device address, IoT-Hub connection string].
+     * @param args Expected: [plc4x connection string, plc4x address, IoT-Hub connection string].
      */
     public static void main(String[] args) {
         logger.info("Connecting");
         try (PlcConnection plcConnection = new PlcDriverManager().getConnection(args[0])) {
             logger.info("Connected");
 
-            client = new DeviceClient(args[1], protocol);
+            client = new DeviceClient(args[2], protocol);
             client.open();
 
             Optional<PlcReader> reader = plcConnection.getReader();
 
             if (reader.isPresent()) {
                 PlcReader plcReader = reader.get();
-                Address outputs = plcConnection.parseAddress("OUTPUTS/0");
+                Address outputs = plcConnection.parseAddress(args[1]);
 
                 while (true) {
                     // Simulate telemetry.
-                    TypeSafePlcReadResponse<Byte> plcReadResponse = plcReader.read(new TypeSafePlcReadRequest<>(Byte.class, outputs)).get();
+                    TypeSafePlcReadResponse<Byte> plcReadResponse = plcReader.read(
+                        new TypeSafePlcReadRequest<>(Byte.class, outputs)).get();
 
                     System.out.println("Outputs: " + Long.toBinaryString(plcReadResponse.getResponseItem()
                         .orElseThrow(() -> new IllegalStateException("No response available"))


[incubator-plc4x] 02/04: Merge branch 's7_azure_iothub_example' of https://github.com/DerDackel/incubator-plc4x into DerDackel-s7_azure_iothub_example

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch DerDackel-s7_azure_iothub_example
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 552385d353bc2e3fc5bf9c74fdc7e33a93ea98e1
Merge: d54464b 5202c9d
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Aug 13 16:16:04 2018 +0200

    Merge branch 's7_azure_iothub_example' of https://github.com/DerDackel/incubator-plc4x into DerDackel-s7_azure_iothub_example

 examples/azure/pom.xml                             | 38 +++++++++++
 .../azure/iothub/S7PlcToAzureIoTHubSample.java     | 76 ++++++++++++++++++++++
 examples/pom.xml                                   |  1 +
 3 files changed, 115 insertions(+)


[incubator-plc4x] 03/04: Merge branch 'master' of github.com:apache/incubator-plc4x into DerDackel-s7_azure_iothub_example

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch DerDackel-s7_azure_iothub_example
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 1436e2c3f30b07c4d3f2bf68bcf3dcda636d15a4
Merge: 552385d d220353
Author: Christofer Dutz <ch...@c-ware.de>
AuthorDate: Mon Aug 13 16:56:08 2018 +0200

    Merge branch 'master' of github.com:apache/incubator-plc4x into DerDackel-s7_azure_iothub_example

 src/site/asciidoc/protocols/delta-v/reverse-engineering.adoc | 11 ++++++-----
 src/site/site.xml                                            |  2 +-
 2 files changed, 7 insertions(+), 6 deletions(-)


[incubator-plc4x] 01/04: Implement basic example of connecting an S7 device to Azure IoT Hub

Posted by cd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

cdutz pushed a commit to branch DerDackel-s7_azure_iothub_example
in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git

commit 5202c9df366972a206777f33dca0e4737874a8d5
Author: Sebastian Jackel <se...@codecentric.de>
AuthorDate: Fri Aug 10 14:48:01 2018 +0200

    Implement basic example of connecting an S7 device to Azure IoT Hub
---
 examples/azure/pom.xml                             | 38 +++++++++++
 .../azure/iothub/S7PlcToAzureIoTHubSample.java     | 76 ++++++++++++++++++++++
 examples/pom.xml                                   |  1 +
 3 files changed, 115 insertions(+)

diff --git a/examples/azure/pom.xml b/examples/azure/pom.xml
new file mode 100644
index 0000000..0e010a9
--- /dev/null
+++ b/examples/azure/pom.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <parent>
+    <artifactId>examples</artifactId>
+    <groupId>org.apache.plc4x.examples</groupId>
+    <version>0.0.1-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+
+  <artifactId>azure</artifactId>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-api</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-core</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.plc4x</groupId>
+      <artifactId>plc4j-protocol-s7</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.microsoft.azure.sdk.iot</groupId>
+      <artifactId>iot-device-client</artifactId>
+      <version>1.3.30</version>
+    </dependency>
+  </dependencies>
+
+</project>
\ No newline at end of file
diff --git a/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java b/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java
new file mode 100644
index 0000000..0e183c3
--- /dev/null
+++ b/examples/azure/src/main/java/org/apache/plc4x/java/examples/azure/iothub/S7PlcToAzureIoTHubSample.java
@@ -0,0 +1,76 @@
+package org.apache.plc4x.java.examples.azure.iothub;
+
+import com.microsoft.azure.sdk.iot.device.*;
+import org.apache.plc4x.java.PlcDriverManager;
+import org.apache.plc4x.java.api.connection.PlcConnection;
+import org.apache.plc4x.java.api.connection.PlcReader;
+import org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadRequest;
+import org.apache.plc4x.java.api.messages.specific.TypeSafePlcReadResponse;
+import org.apache.plc4x.java.api.model.Address;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Optional;
+
+public class S7PlcToAzureIoTHubSample {
+
+    private static final Logger logger = LoggerFactory.getLogger(S7PlcToAzureIoTHubSample.class);
+
+    private static IotHubClientProtocol protocol = IotHubClientProtocol.MQTT;
+    private static DeviceClient client;
+
+    public static class Callback implements IotHubEventCallback {
+
+        @Override
+        public void execute(IotHubStatusCode iotHubStatusCode, Object ctx) {
+            System.out.println("Received status: " + iotHubStatusCode.name());
+        }
+    }
+
+    /**
+     * Example code do demonstrate sending events from an S7 device to Microsoft Azure IoT Hub
+     *
+     * @param args Expected: [device address, IoT-Hub connection string].
+     */
+    public static void main(String[] args) {
+        logger.info("Connecting");
+        try (PlcConnection plcConnection = new PlcDriverManager().getConnection(args[0])) {
+            logger.info("Connected");
+
+            client = new DeviceClient(args[1], protocol);
+            client.open();
+
+            Optional<PlcReader> reader = plcConnection.getReader();
+
+            if (reader.isPresent()) {
+                PlcReader plcReader = reader.get();
+                Address outputs = plcConnection.parseAddress("OUTPUTS/0");
+
+                while (true) {
+                    // Simulate telemetry.
+                    TypeSafePlcReadResponse<Byte> plcReadResponse = plcReader.read(new TypeSafePlcReadRequest<>(Byte.class, outputs)).get();
+
+                    System.out.println("Outputs: " + Long.toBinaryString(plcReadResponse.getResponseItem()
+                        .orElseThrow(() -> new IllegalStateException("No response available"))
+                        .getValues().get(0).longValue()));
+
+                    plcReadResponse.getResponseItem().map(byt -> {
+                            String result = Long.toBinaryString(byt.getValues().get(0).longValue());
+                            Message msg = new Message("{ \"bits\" : \"" + result + "\"}");
+                            // Send the message.
+                            Callback callback = new Callback();
+
+                            client.sendEventAsync(msg, callback, new Object());
+                            return byt;
+                        }
+                    );
+
+                    Thread.sleep(1000);
+                }
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+}
diff --git a/examples/pom.xml b/examples/pom.xml
index 574edcd..5e63794 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -41,6 +41,7 @@
     <module>iotree</module>
     <module>kafka-bridge</module>
     <module>plclogger</module>
+    <module>azure</module>
   </modules>
 
   <dependencyManagement>