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:59 UTC

[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.

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"))