Browse Source

add EventFields 'Time' and 'SourceName' in server events tutorial to show Events in UaExpert (#1996)

UaExpert Client needs the mandatory EventField 'Time' to show the events on Event View.
Sameer AL-Qadasi 6 years ago
parent
commit
1d091f490c
1 changed files with 10 additions and 1 deletions
  1. 10 1
      examples/tutorial_server_events.c

+ 10 - 1
examples/tutorial_server_events.c

@@ -41,7 +41,8 @@ addNewEventType(UA_Server *server) {
  * All we need for this is our `EventType`. Once we have our event node, which is saved internally as an `ObjectNode`,
  * we can define the attributes the event has the same way we would define the attributes of an object node. It is not
  * necessary to define the attributes `EventId`, `ReceiveTime`, `SourceNode` or `EventType` since these are set
- * automatically by the server. In this example, we will only be setting `Severity` and `Message`.
+ * automatically by the server. In this example, we will be setting all the rest mandatory EventFields of the BaseEventType: 
+ * `Time` (to make the example UaExpert compliant), `Severity`, `Message` and `SourceName`.
  */
 static UA_StatusCode
 setUpEvent(UA_Server *server, UA_NodeId *outId) {
@@ -53,6 +54,10 @@ setUpEvent(UA_Server *server, UA_NodeId *outId) {
     }
 
     /* Set the Event Attributes */
+    UA_DateTime eventTime = UA_DateTime_now();
+    UA_Server_writeObjectProperty_scalar(server, *outId, UA_QUALIFIEDNAME(0, "Time"),
+                                         &eventTime, &UA_TYPES[UA_TYPES_DATETIME]);
+												 
     UA_UInt16 eventSeverity = 100;
     UA_Server_writeObjectProperty_scalar(server, *outId, UA_QUALIFIEDNAME(0, "Severity"),
                                          &eventSeverity, &UA_TYPES[UA_TYPES_UINT16]);
@@ -61,6 +66,10 @@ setUpEvent(UA_Server *server, UA_NodeId *outId) {
     UA_Server_writeObjectProperty_scalar(server, *outId, UA_QUALIFIEDNAME(0, "Message"),
                                          &eventMessage, &UA_TYPES[UA_TYPES_LOCALIZEDTEXT]);
 
+    UA_String eventSourceName = UA_STRING("Server");
+    UA_Server_writeObjectProperty_scalar(server, *outId, UA_QUALIFIEDNAME(0, "SourceName"),
+                                         &eventSourceName, &UA_TYPES[UA_TYPES_STRING]);
+
     return UA_STATUSCODE_GOOD;
 }