From fe933ace8c35622c22b7d4353cfbcd2fbf3ea553 Mon Sep 17 00:00:00 2001 From: Hans Gschossmann Date: Fri, 17 Nov 2017 09:50:04 +0100 Subject: [PATCH] Send SourceTimestamp in ISO 8601 format and OPC UA status code as uint, address review comments. --- README.md | 7 ++++--- src/IotHubMessaging.cs | 6 +++--- src/OpcSession.cs | 17 ++++++++++------- src/telemetryconfiguration.json | 7 ++++--- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 53c10f8..40c0ec0 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ The syntax of the configuration file is as follows: // "DisplayName": "CurrentTime", // "Value": { // "Value": "10.11.2017 14:03:17", - // "SourceTimestamp": "2017-11-10 14:03:17Z" + // "SourceTimestamp": "2017-11-10T14:03:17Z" // } // } @@ -202,7 +202,7 @@ The syntax of the configuration file is as follows: // members won't be nested: // "DisplayName": "CurrentTime", // "Value": "10.11.2017 14:03:17", - // "SourceTimestamp": "2017-11-10 14:03:17Z" + // "SourceTimestamp": "2017-11-10T14:03:17Z" // The 'Flat' property can only be used for the 'MonitoredItem' and 'Value' // objects of the 'Defaults' object and will be used for all // messages sent by publisher. @@ -216,10 +216,11 @@ The syntax of the configuration file is as follows: "Publish": true, "Name": "SourceTimestamp" }, - // StatusCode is the 32 bit OPC UA status code formatted as hexadezimal number. + // 'StatusCode' is the 32 bit OPC UA status code "StatusCode": { "Publish": false, "Name": "StatusCode" + // 'Pattern' is ignored for the 'StatusCode' value }, // 'Status' is the symbolic name of 'StatusCode' "Status": { diff --git a/src/IotHubMessaging.cs b/src/IotHubMessaging.cs index 12dfdf5..80e810e 100644 --- a/src/IotHubMessaging.cs +++ b/src/IotHubMessaging.cs @@ -404,7 +404,7 @@ namespace OpcPublisher // process Value object properties if (!string.IsNullOrEmpty(messageData.Value) || !string.IsNullOrEmpty(messageData.SourceTimestamp) || - !string.IsNullOrEmpty(messageData.StatusCode) || !string.IsNullOrEmpty(messageData.Status)) + messageData.StatusCode != null || !string.IsNullOrEmpty(messageData.Status)) { if (!(bool)telemetryConfiguration.Value.Flat) { @@ -434,7 +434,7 @@ namespace OpcPublisher } // process StatusCode - if (!string.IsNullOrEmpty(messageData.StatusCode)) + if (messageData.StatusCode != null) { await _jsonWriter.WritePropertyNameAsync(telemetryConfiguration.Value.StatusCode.Name); await _jsonWriter.WriteValueAsync(messageData.StatusCode); @@ -527,7 +527,7 @@ namespace OpcPublisher // sanity check that the user has set a large enough IoTHub messages size if ((_iotHubMessageSize > 0 && jsonMessageSize > _iotHubMessageSize ) || (_iotHubMessageSize == 0 && jsonMessageSize > iotHubMessageBufferSize)) { - Trace(Utils.TraceMasks.Error, $"There is a telemetry message (size: {jsonMessageSize}), which will not fit into an IoTHub message (max size: {_iotHubMessageSize}]."); + Trace(Utils.TraceMasks.Error, $"There is a telemetry message (size: {jsonMessageSize}), which will not fit into an IoTHub message (max size: {iotHubMessageBufferSize}]."); Trace(Utils.TraceMasks.Error, $"Please check your IoTHub message size settings. The telemetry message will be discarded silently. Sorry:("); _tooLargeCount++; continue; diff --git a/src/OpcSession.cs b/src/OpcSession.cs index ed1f1a6..559ac42 100644 --- a/src/OpcSession.cs +++ b/src/OpcSession.cs @@ -150,7 +150,7 @@ namespace OpcPublisher public string DisplayName; public string Value; public string SourceTimestamp; - public string StatusCode; + public uint? StatusCode; public string Status; public bool PreserveValueQuotes; @@ -193,9 +193,12 @@ namespace OpcPublisher { SourceTimestamp = telemetryConfiguration.Value.SourceTimestamp.PatternMatch(SourceTimestamp); } - if (telemetryConfiguration.Value.StatusCode.Publish == true) + if (telemetryConfiguration.Value.StatusCode.Publish == true && StatusCode != null) { - StatusCode = telemetryConfiguration.Value.StatusCode.PatternMatch(StatusCode); + if (!string.IsNullOrEmpty(telemetryConfiguration.Value.StatusCode.Pattern)) + { + Trace($"'Pattern' settngs for StatusCode are ignored."); + } } if (telemetryConfiguration.Value.Status.Publish == true) { @@ -249,13 +252,13 @@ namespace OpcPublisher } if (telemetryConfiguration.Value.SourceTimestamp.Publish == true && value.SourceTimestamp != null) { - // use the SourceTimestamp as reported in the notification event argument in univeral sortable format - messageData.SourceTimestamp = value.SourceTimestamp.ToString(); + // use the SourceTimestamp as reported in the notification event argument in ISO8601 format + messageData.SourceTimestamp = value.SourceTimestamp.ToString("o"); } if (telemetryConfiguration.Value.StatusCode.Publish == true && value.StatusCode != null) { // use the StatusCode as reported in the notification event argument - messageData.StatusCode = value.StatusCode.Code.ToString("X"); + messageData.StatusCode = value.StatusCode.Code; } if (telemetryConfiguration.Value.Status.Publish == true && value.StatusCode != null) { @@ -278,7 +281,7 @@ namespace OpcPublisher messageData.PreserveValueQuotes = true; if (markerStart >= 0) { - // we either have a value in quotes of just a value + // we either have a value in quotes or just a value int valueLength; int valueStart = marker.Length; if (valueString.IndexOf("\"", valueStart) >= 0) diff --git a/src/telemetryconfiguration.json b/src/telemetryconfiguration.json index b03a0b5..1500044 100644 --- a/src/telemetryconfiguration.json +++ b/src/telemetryconfiguration.json @@ -13,7 +13,7 @@ // "DisplayName": "CurrentTime", // "Value": { // "Value": "10.11.2017 14:03:17", -// "SourceTimestamp": "2017-11-10 14:03:17Z" +// "SourceTimestamp": "2017-11-10T14:03:17Z" // } // } @@ -101,7 +101,7 @@ // members won't be nested: // "DisplayName": "CurrentTime", // "Value": "10.11.2017 14:03:17", - // "SourceTimestamp": "2017-11-10 14:03:17Z" + // "SourceTimestamp": "2017-11-10T14:03:17Z" // The 'Flat' property could only be used for the 'MonitoredItem' and 'Value' // configuratíon settings of the 'Defaults' objet and will be used for all JSON // messages sent by publisher. @@ -115,10 +115,11 @@ "Publish": true, "Name": "SourceTimestamp" }, - // StatusCode is the 32 bit OPC UA status code formatted as hexadezimal number. + // 'StatusCode' is the 32 bit OPC UA status code "StatusCode": { "Publish": false, "Name": "StatusCode" + // 'Pattern' is ignored for the 'StatusCode' value }, // 'Status' is the symbolic name of 'StatusCode' "Status": {