WebSocket

External Notifications can be used by a user to update a job or device, instantly when their status is changed and without making calls at regular intervals.

To receive external notifications you need the following:

    1. WebSocket Client

This can be implemented in the MIS System by following the below sample:

Install WebSocket4Net(open source websocket client implementation) nuget package:PM – Install-Package WebSocket4Net

    1. First a WebSocket connection is established between a user and the WebSocket server. URL: “ws://connect.aurelon.com:8080”

The Authorization is done using a MisKey which must be added by the user in WebSocket connection header fields with the key “MisKey” and the value of the MisKey.

//add MisKey in header
var customHeaderItems = new List{KeyValuePair{string, string}}();
customHeaderItems.Add(new KeyValuePair{string, string}(“MisKey”, miskey));

//create WebSocketClient
WebSocket webSocketClient = new WebSocket(“ws://connect.aurelon.com:8080”, “”, null, customHeaderItems, “”, “”, WebSocketVersion.None, null);

//open WebSocketClient connection
webSocketClient.Open();

    1. Register to Server events

The WebSocket Server will notify connected users with a JSON message when the status of a job or device has changed.

//attach to WebSocketClient events
webSocketClient.Error += new
EventHandler{SuperSocket.ClientEngine.ErrorEventArgs}(webSocketClient_Error);
webSocketClient.Opened += new EventHandler(webSocketClient_Opened);
webSocketClient.Closed += new EventHandler(webSocketClient_Closed);
webSocketClient.MessageReceived += new
EventHandler{MessageReceivedEventArgs}(webSocketClient_MessageReceived);

JSON message ex:
– for Job: {“JobGUID”:”DD6BDDF6-74BA-4BD0-AC48-94A251A8ECA6″}
– for Device: {“DeviceGUID”:”8F1D80AB-06D5-43F8-A015-20347D9DE22C”}

    1. Get updates

Once the notifications are received, you need to call the corresponding method to get the updates from the server.
In this step the user knows that an entity (job or device) has been modified and should make a REST call to External REST API (presented in details at point 1) get the latest values.

To connect to WebSocket Server (URL: “ws://connect.aurelon.com:8080”), the users must use a WebSocket Client.

MisKey

The MisKey value is generated in HUB Application in “Settings” -> “External API” page as shown in the next image

The user can regenerate the MisKey for an unlimited number of times using the “Generate” button. Using “Cancel” button the user will delete the MisKey stopping his access to notifications server.

Events

There are four event types being send using the WebSocket. All of these events only provide information about the object/information that has been changed in JSON format, specifying the GUID of the object. After receiving the event the REST API can be used to get the latest (updated) version of that object.

The following event types are defined:

  • Device : The device with the GUID in the message has changed. This happens when the device has status updates (like supply levels or processing state). Use /api/v2/device/<DeviceGUID>/status to get the actual status.
  • Job : The job with the GUID in the message has changed. This happens for each change in the job its audit log, so practically with each transaction or progress update. Use /api/v2/job/<JobGUID> to get the actual status.
  • Nest : The nest with the GUID is created and scheduled for production, canceled or deleted. The event contains both the NestGUID (use /api/v2/automation/nest/<NestGUID> to get the details) as well as the resulting job (use /api/v2/job/<JobGUID> to get the details). The Status field informs about what action has happened.