[GitHub] asfgit closed pull request #11: Implement basic example of connecting an S7 device to Azure IoT Hub

2018-08-13 Thread GitBox
asfgit closed pull request #11: Implement basic example of connecting an S7 
device to Azure IoT Hub
URL: https://github.com/apache/incubator-plc4x/pull/11
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/examples/azure/pom.xml b/examples/azure/pom.xml
new file mode 100644
index 0..0e010a9c1
--- /dev/null
+++ b/examples/azure/pom.xml
@@ -0,0 +1,38 @@
+
+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;>
+  
+examples
+org.apache.plc4x.examples
+0.0.1-SNAPSHOT
+  
+  4.0.0
+
+  azure
+
+  
+
+  org.apache.plc4x
+  plc4j-api
+  0.0.1-SNAPSHOT
+
+
+  org.apache.plc4x
+  plc4j-core
+  0.0.1-SNAPSHOT
+
+
+  org.apache.plc4x
+  plc4j-protocol-s7
+  0.0.1-SNAPSHOT
+
+
+
+  com.microsoft.azure.sdk.iot
+  iot-device-client
+  1.3.30
+
+  
+
+
\ 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 0..0e183c3c0
--- /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 reader = plcConnection.getReader();
+
+if (reader.isPresent()) {
+PlcReader plcReader = reader.get();
+Address outputs = plcConnection.parseAddress("OUTPUTS/0");
+
+while (true) {
+// Simulate telemetry.
+TypeSafePlcReadResponse 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 574edcdd6..5e6379431 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -41,6 +41,7 @@
 iotree
 kafka-bridge
 plclogger
+azure
   
 
   


 



[GitHub] bodewig commented on issue #12: fix a few typos

2018-08-13 Thread GitBox
bodewig commented on issue #12: fix a few typos
URL: https://github.com/apache/incubator-plc4x/pull/12#issuecomment-412537899
 
 
   As somebody toying with the idea of using gitbox for some other projects I'd 
be interested in hearing what went wrong :-)
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz commented on issue #12: fix a few typos

2018-08-13 Thread GitBox
chrisdutz commented on issue #12: fix a few typos
URL: https://github.com/apache/incubator-plc4x/pull/12#issuecomment-412530954
 
 
   And it does seem as if this revealed syncing problems from GitHub back to 
GitBox ... will investigate this.


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] chrisdutz closed pull request #12: fix a few typos

2018-08-13 Thread GitBox
chrisdutz closed pull request #12: fix a few typos
URL: https://github.com/apache/incubator-plc4x/pull/12
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/site/asciidoc/protocols/delta-v/reverse-engineering.adoc 
b/src/site/asciidoc/protocols/delta-v/reverse-engineering.adoc
index 47ac51058..53211fa8c 100644
--- a/src/site/asciidoc/protocols/delta-v/reverse-engineering.adoc
+++ b/src/site/asciidoc/protocols/delta-v/reverse-engineering.adoc
@@ -28,7 +28,7 @@ We kindly were provided with access to a DeltaV system used 
for training.
 
 Therefore we were able to change a few things without fearing to break 
anything important.
 
-This system consisted of tree DeltaV controllers, two Operator-System instances
+This system consisted of three DeltaV controllers, two Operator-System 
instances
 So in general there were three types of systems involved:
 
 1. DeltaV Controller
@@ -156,6 +156,7 @@ During this we managed to reverse engineer the connection 
on the wrapper-protoco
  Connecting
 
 When an OS is booted, the following communication could be observed:
+
 1. The OS sends a wrapper-protocol type `0x0003` to the controller.
 2. The controller responds with a `0x0004` message back to the controller.
 3. After receiving the `0x0004` message, the OS sends a type `0x0002` message 
with a wrapped type `0x0501`
@@ -163,7 +164,7 @@ When an OS is booted, the following communication could be 
observed:
 5. The controller sends a very similar packet as the `0x0501` packet back to 
the OS
 6. The OS acknowledges this packet back to the controller
 
-From looking at the packet in WireSharks byte and ASCII view, we could see 
ASCII characters that seem to relate to test strings.
+From looking at the packet in WireShark's byte and ASCII view, we could see 
ASCII characters that seem to relate to test strings.
 A quick consultation of the guy in charge of these systems made us realize 
that these strings refer to parts of the controllers software.
 Digging even deeper made us realize that the 4 byte values relate to unix 
timestamps - at least we could decode the byte values to absolutely sensible 
dates.
 So it seems that In these packets each participant compares it's software 
state in order to know all are using compatible versions.
@@ -198,9 +199,9 @@ So we started with the value 0 and incremented that in 
steps of 1 till 20 and th
 
 And we could see that there were certain parts of the packet that seem to 
change when changing values, most of the packet remaining constant.
 When changing a value back to the original value, the packets payload was 
identical in this part.
-As the packets didn't all have the same content and some times blocksp were 
added and left away in regular intervals, lead us to the impression, that these 
packets too consist of a fixed packet header followed by blocks.
+As the packets didn't all have the same content and some times blocks were 
added and left away in regular intervals, lead us to the impression, that these 
packets too consist of a fixed packet header followed by blocks.
 In our case the changing blocks all had two indicator bytes `0x0b08` with the 
4 bytes after that changing according to the input.
-Some times a block of bytes was added before this block, then the entire 
content was just pushed back.
+Sometimes a block of bytes was added before this block, then the entire 
content was just pushed back.
 
 The last of such blocks would always be a sequence of 9 bytes: 
`0x0100`, so we assume this is sort of the `terminating block` 
of such a packet.
 
@@ -228,7 +229,7 @@ However when using what we learnt on the old captures we 
did, it turned out that
 So it seems that `0x08` indicates the type of an `signed 32 bit IEE 754 
floating point value`.
 Eventually the `0x0b` part referred to some sort subscription-id.
 
-As we seem to be doing a subscription based communication, the OS has to tell 
the controller what information he is interested in.
+As we seem to be doing a subscription based communication, the OS has to tell 
the controller what information it is interested in.
 
 Right now we are assuming that in one of the other `0x04` packets a 
subscription is initiated and assigned with some sort of id and this id is used 
to identify which value is actually changed.
 
diff --git a/src/site/site.xml b/src/site/site.xml
index 472490e01..e2339a800 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -112,7 +112,7 @@
 
   
   
-  
+  
   
   
   


 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For 

[GitHub] chrisdutz commented on issue #12: fix a few typos

2018-08-13 Thread GitBox
chrisdutz commented on issue #12: fix a few typos
URL: https://github.com/apache/incubator-plc4x/pull/12#issuecomment-412528417
 
 
   Well I guess I can simply merge this from the GitHub ui ... thanks for this 
:-)


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services