Frequently Asked Questions – Web Alarm

Where can I find the steps to setup the Web Trend?
We have a HTML5 project with and one of the requirements is to be able to click on an alarm in the alarm control and move to a specific page based on the alarm. Is that possible or would the alarm control need to be modified?
In the alarmbinding, add the following config field: rowClickCallback : yourFunction The callback passes one argument that represents the data in the row that was clicked.  You could then parse the data, which is just an array of all the fields in the alarm.

Overview – Web Alarm Programming

If you are interested in visualizing your data in a desktop or mobile browser with zero programming, you may be interested in Getting Started with the Web HMI Dashboard.

Features

The OAS Web HMI provides a flexible, platform-independent way to integrate with Open Automation Software Servers. The addition of the Alarm Control allows you to retrieve and interact with real time and historical alarms from the OAS Server. Included in this release are:

  • A configuration interface for specifying Alarms to monitor and be displayed
  • A client-side Javascript API for interacting with Alarm data and extending functionality

Requirements

OAS Web HMI Alarm Control requires the following:

  • an instance of anOpen Automation Software Serveraccessible over an internal or external network
  • working knowledge of HTML
  • working knowledge of Javascript
  • working knowledge of OAS Web HMI configuration

Installation and Configuration

Configuration of OAS Web HMI will not be covered in this document. Once you have a working installation of OAS Web HMI, adding Alarm Control configuration is fairly simple. As with OAS Web HMI, the following are required for Alarm Control operation:

  • jQuery v1.8.3 or later, found at jquery.com and is also distributed with the Web HMI product
  • The OAS Web HMI Script Library
  • The OAS Web HMI Stylesheet, which is used for styling modal dialogs and can be modified to fit your web design
  • A small block of Javascript containing an authentication token and URL location of the Open Automation Software Server
  • The OAS Web Alarm Stylesheet, which is used for styling alarm colors and fonts to fit your web design
  • DataTables jQuery plugin, included with the Web HMI distribution
  • FontAwesome web font, included with the Web HMI distribution, and used for high quality inline icons

The following is an example of a properly configured, minimal HTML page:

<html>
    <head>
        <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
        <script type="text/javascript" src="js/opc-lib-min.js"></script>
        <link rel="stylesheet" stype="text/css" href="css/opc-style.css"/>
        <script type="text/javascript">
            OAS_config = {
                token:'7e61b230-481d-4551-b24b-ba9046e3d8f2',
                serverURL: 'http://localhost:58725'
            };
        </script>
    </head>
    <body>
        Hello World
    </body>
</html>

Of course, this example does not contain any bindings to OAS Server Tags, but contains all elements necessary to connect to a server located at http://localhost:58725 using an authentication token of 7e61b230-481d-4551-b24b-ba9046e3d8f2.

Alarm Control description and options

After defining the Alarm Control bindings, or Alarm Bindings, the OAS Web HMI library will continually poll the server for realtime data, or Historical Data, depending on the context.

The Javascript OAS_config variable contains several options for determining the behavior of the Script Library. This variable is a standard JSON construct. The minimal definition with defaults displayed is:

OAS_config =
{
    interval: 1000,             
    token:'',                           
    serverURL:'http://localhost:58725'
};

To add Alarm Bindings to this configuration, you will add the following node to your OAS_config construct. The alarm_bindings node is an array of Alarm Binding objects, each representing data to be displayed in a single table.

alarm_bindings:[
{
  alarmid: <string>, 
  callback: <function>,
  rowClickCallback: <function>,
  showDelete: <bool>,
  showHistory: <bool>,
  showComment: <bool>,
  showSearch: <bool>,
  showInfo: <bool>,
  pagination: <bool>,
  pageLength: <number>,
  height: <number>,
  filter: {
    includealarmactive: <bool>,
    includealarmactiveacked: <bool>,
    includealarmnotactive: <bool>,
    includealarmnotactiveacked: <bool>
    maxpriority: <number>,
    minpriority: <number>,
    alarmgroups: <array of string>,
    alarmtypes: <array of string>   
  },
  networkNodes: <array of string>,
  columns: <array of objects>
}
  • alarmid: string
    A unique identifier for the alarm which is used to bind to an HTML element of the same id. When the page is rendered, the script library will fill the designated element with the alarm control.
  • callback: function(ab, data)
    This optional callback will be executed after each call to the server, passing in a reference to the Alarm Binding object, and the raw data returned by the server.
  • rowClickCallback: function(data)
    This optional callback will be executed after a row in the alarm control is clicked, passing in the data for the selected row.
  • showDelete: bool
    If set to true, a delete icon will be displayed on each alarm row. Clicking the icon will cause the alarm to be deleted on the server and in the web interface. If the current user does not have rights to delete the alarm, this icon will be displayed in a disabled state. The showDelete option defaults to true if omitted.
  • showHistory: bool
    If set to true, fields will be displayed in the header of the alarm control allowing users to select a date range to display historical alarms. The showHistory option defaults to false if omitted.
  • dateTimeFormat: string
    Format for the alarm date and time
alarm_bindings:[
          {
            alarmid:"alarm1",
            dateTimeFormat: "yyyy/mm/dd hh:MM aa"
          }

yyyy : 4-digit year

yy: 2-digit year

mm: 2-digit month

dd: 2-digit day

hh: hours (12)

HH: hours (24)

MM: minutes

ss: seconds

aa: am/pm.

  • showComment: bool
    If set to true, a comment icon will be displayed on each alarm row. Clicking the icon will allow users to add a comment to the alarm. If the current user does not have rights to comment on the alarm, this icon will be displayed in a disabled state. The showComment option defaults to true if omitted.
  • showSearch: bool
    If set to true, a search field will be displayed in the header of the alarm control allowing users to quickly filter alarms by any free text. The showSearch option defaults to true if omitted.
  • showInfo: bool
    If set to true, a brief summary will be displayed in the footer of the alarm control, describing the number of records being displayed. The showInfo option defaults to true if omitted.
  • pagination: bool
    If set to true, alarms will be paginated within the view based on the number of alarms allowed per page (defaults to 10). The pagination option defaults to true if omitted.
  • pageLength: number
    This optional value determines the maximum number of alarms to display on each page. This setting defaults to 10 and has no effect if pagination is disabled.
  • height: number
    This optional value indicates the fixed height in pixels that the alarm control will be rendered. If alarms exceed the rendered height, they will be scrollable within the alarm control window. If the height setting is omitted, the alarm control will expand to fit the number of controls it contains.
  • filter: object
    This filter object partially determines which alarms are pulled from the server to be displayed. If the filter object is omitted, the default setting are as follows:
{
    includealarmactive: true,
    includealarmactiveacked: true,
    includealarmnotactive: true,
    includealarmnotactiveacked: false,
    maxpriority: 1000000,
    minpriority: 0,
    alarmgroups:[],
    alarmtypes:[
        "Digital", 
        "High",
        "High High",
        "Low",
        "Low Low",
        "Operator Event",
        "ROC",
        "System",
        "Tag Event"
    ]
}
  • networkNodes: array of strings
    This optional value will pull alarms for specific network nodes. If omitted, it will pull only alarms for the Open Automation Software Server to which the client is connected, or effectively ‘localhost’.
  • columns: array of column objects
    By default, the alarm control will display the following columns in the following order:

    • Alarm Date/Time
    • Active
    • Alarm Value
    • Text
    • Alarm Type
    • Group
    • Priority
    • Document

If you would like to alter the order, hide any of these columns, or include others, you will need to include a full definition and settings for all data fields exposed by the alarm interface. The default array is as follows:

[
    {name: "AlarmID", text: "Alarm ID", type: "string", visible: false},
    {name: "AlarmDateTime", text: "Alarm Date/Time", type: "datetime", visible: true, sort:'desc', width:'130px', searchable:false},
    {name: "Active", text: "Active", type: "boolean", visible: true, width:'50px', align:'center'},
    {name: "AlarmValue", text: "Alarm Value", type: "string", visible: true, align:'right'},
    {name: "Text", text: "Text", type: "string", visible: true},
    {name: "AlarmType", text: "Alarm Type", type: "string", visible: true},
    {name: "Group", text: "Group", type: "string", visible: true},
    {name: "Priority", text: "Priority", type: "string", visible: true, width:'50px', align:'right'},
    {name: "AckedDateTime", text: "Acked Date/Time", type: "datetime", visible: false},
    {name: "Acked", text: "Acked", type: "boolean", visible: false},
    {name: "AckedUser", text: "Acked User", type: "string", visible: false},
    {name: "ClearedDateTime", text: "Cleared Date/Time", type: "datetime", visible: false},
    {name: "ClearedValue", text: "Cleared Value", type: "string", visible: false},
    {name: "NetworkNode", text: "Network Node", type: "string", visible: false},
    {name: "Units", text: "Units", type: "string", visible: false},
    {name: "TimeDelay", text: "Delay Time", type: "string", visible: false},
    {name: "Document", text: "Document", type: "string", width:'50px', align:'center', visible: true, searchable:false, sortable:false},
    {name: "Comment", text: "", type: "string", visible: false, searchable:false, sortable:false},
    {name: "OKToComment", text: "Comment", type: "string", width:'50px', align:'center', visible: true, searchable:false, sortable:false},
    {name: "OKToDelete", text: "Delete", type: "string", width:'50px', align:'center', visible: true, searchable:false, sortable:false}
]
  • name: string : the unique column identifier. These must be written as is, since each column name corresponds to an alarm field.
  • text: string: the column header label.
  • type: string: string|datetime : determines how the field is rendered.
  • visible: bool: determines if the column is rendered. All columns must be defined, but not all columns must be displayed.
  • width: string: optional pixel width for the column written in the format ’00px’. By default the column will expand to fit.
  • align: string: left|right|center : optional text alignment, defaults to left
  • searchable: bool: values included when using the inline search box, defaults to true.
  • sortable: bool: allows the user to sort all alarms by clicking the column header, defaults to true.

grouping: bool
Enable or disable grouping by alarms. You must also supply a list of columns used for grouping alarms in the groupingColumns property.

groupingColumns: string
A comma-delimited list of columns used for grouping alarms. The order in which the columns are listed will be the order in which they will be grouped. Also, columns listed in the groupingColumns will not be displayed in alarm table columns.

Acknowledging Alarms

While the alarm control is active, users can acknowledge alarms by double-clicking an alarm row. Once acknowledged, the alarm will change appearance based on the configured styling.

Styling the Alarm Control

The alarm control is styled with an external stylesheet. This stylesheet is included with the distribution and can be seen in the example. If you are comfortable manipulating CSS for styling your web applications, altering these styles is fairly straightforward.

With this stylesheet, you will be able to set the colors, fonts, backgrounds and more for each type of alarm as well as their current state, and combinations thereof.

Miscellaneous

OAS.init()

Use OAS.init() after making any changes to OAS_config. For example, when altering any alarm features, you can then call OAS.init() to force the OAS_config to reload with the new settings.

Getting Started – Web Alarm

The following content will get you started with Web Alarm, building your own web user interfaces with real time and historical alarm data.

NOTE: If you want to visualize your data in a desktop or mobile browser with zero programming, you may be interested in the OAS Open UIEngine .
The UIEngine is a robust no-code web application and HMI builder for developing rich user interfaces in a browser-based development environment.
See the UIEngine Documentation to learn more.

For full reference information visit Programming Reference – Web Alarm

Example: Simple Web Alarm

The following sample illustrates how to display real time web alarms as well as enabling a feature to switch between real time and historical alarms.

Step 1

Configure Web Services within the OAS Platform. For instructions on how to accomplish this as well as optionally using SSL for secure communications, see the following article:
Configuring OAS Web Services

Step 2

Be sure to follow instructions for configuring Web HMI as the Alarm Control is an extension of that library.

In addition to the 3 previous script libraries (jQuery, json2, and opc-lib-min) copy one additional file from the same source location (C:\Program Files\Open Automation Software\OAS\HTML_HMI\js) to the same destination as the others, placing it a datatables directory:

jquery.dataTables.min.js

Step 3

In the head section of the HTML file, add the following script library reference:

<script type="text/javascript" src="js/datatables/jquery.dataTables.min.js”></script>

Step 4

Next, copy 3 additional css files into the css directory:

  1. font-awesome.min.css
  2. jquery.dataTables.css
  3. opc-alarm-style.css

Step 5

In the head section of the HTML file, add the following script references:

<link rel="stylesheet" stype="text/css" href="css/font-awesome.min.css"/>
<link rel="stylesheet" stype="text/css" href="css/jquery.dataTables.css"/>
<link rel="stylesheet" stype="text/css" href="css/opc-alarm-style.css"/>

Step 6

Once you have an HTML file set up and successfully running HTML, modify the OAS_config script to look like the following:

OAS_config = {
    token:'7e61b230-481d-4551-b24b-ba9046e3d8f2',
    serverURL: 'http://localhost:58725/',
    alarm_bindings:[
      {
        alarmid:"alarm1", 
        showDelete: true,
        showHistory: true
      }
    ]
  };

Note: As with the Web HMI configuration, you must specify the serverURL that includes the Node Name and Port Number that has been registered by the OAS Service Control Manager.

Step 7

In the body of your HTML, add an element where the alarm control will be drawn, using the following bit of HTML:

<div id="alarm1"></div>

Note: The id of the div element is “alarm1“, which matches the alarmid configured in the previous step.

Step 8

Save the HTML file and add it to your application in the same way as other Web HMI web pages. The complete file should look like the following:

<html>
    <head>
      <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
      <script type="text/javascript" src="js/opc-lib-min.js"></script>
      <script type="text/javascript" src="js/datatables/jquery.dataTables.min.js"></script>
      <link rel="stylesheet" stype="text/css" href="css/opc-style.css"/>
      <link rel="stylesheet" stype="text/css" href="css/font-awesome.min.css"/>
      <link rel="stylesheet" stype="text/css" href="css/jquery.dataTables.css"/>
      <link rel="stylesheet" stype="text/css" href="css/opc-alarm-style.css"/>
      <script type="text/javascript">
        OAS_config = {
          token:'7e61b230-481d-4551-b24b-ba9046e3d8f2',
          serverURL: 'http://localhost:58725/',
          alarm_bindings:[
            {
              alarmid:"alarm1",
              showDelete:true,
              showHistory:true
            }
          ]       
        };
      </script>
    </head>
    <body>
      <div id="alarm1"></div>   
    </body>
</html>

Overview – Web Alarm

NOTE: If you want to visualize your data in a desktop or mobile browser with zero programming, you may be interested in the OAS Open UIEngine .
The UIEngine is a robust no-code web application and HMI builder for developing rich user interfaces in a browser-based development environment.
See the UIEngine Documentation to learn more.

For full reference information visit Programming Reference – Web Alarm

The OAS Web Alarm provides a flexible, platform-independent way to integrate with Open Automation Software Servers. The addition of the Alarm Control allows you to retrieve and interact with real time and historical alarms from the OPC Server. Included in this release are:

  • A configuration interface for specifying Alarms to monitor and be displayed
  • A client-side Javascript API for interacting with Alarm data and extending functionality

Trend Binding Callback

The Trend Binding Callback function that you implement must have the following definition:

function myCallbackFunction(data) {
    ... your custom implementation here ...
}

You can name the function anything, as long as it takes a single argument. An example of how this might be used along with a set of Trend Bindings follows:

<script type="text/javascript">
    OAS_config = {
        token:'7e61b230-481d-4551-b24b-ba9046e3d8f2',
        serverURL: 'http://localhost:58725',
        trend_bindings: [
            {
                chartid: "myChart",
                samplerate: 1,
                timeframe: 100,
                tags:[
                    {
                        label:"ramp",
                        tag:"Ramp.Value",
                        color:"#090"
                    },
                    {
                        label: "random",
                        tag: "Random.Value",
                        color: "#f00"
                    }
                ],
                retain: 100,
                callback: myTrendCallback
            }
        ]
    };
 
    function myTrendCallback(data) {
        // display raw data in debug console
        console.log(data);
    }
</script>

Additional Features of Flot

When using the OAS.Flot.buildTrendData() method, all attributes on the Tag Definition are passed through to Flot, and applied to the Flot series object.

In this way, you can set up your series definition within the trend_bindings and they will seamlessly flow through to Flot when the chart is plotted. This is precisely how the label and color attributes are used.

Then, from within any Flot event handlers, those values are available for manual parsing. You can see how this was done in the Interactive Chart example, where the popup label is set to the color defined on the series.

The following links are useful references for the Flot library:

Flot Charts: http://www.flotcharts.org/

Flot API Reference: https://github.com/flot/flot/blob/master/API.md

3rd Party Flot Plugins: http://jumflot.jumware.com/examples/pluginsV2.html

Utility Functions

The following Javascript functions are provided as helper methods for formatting and extracting data from each callback or elsewhere within an application referencing the OAS Web HMI libraries.

OAS.init()  :  forces a reinitialization of the OAS_config for the entire page

Use OAS.init() after making any changes to OAS_config. For example, when altering any trend_binding features, you can then call OAS.init() to force the OAS_config to reload with the new settings.

OAS.Flot.buildTrendData(data)  :  convert trend data to Flot series data
  • data: object
    This utility converts the data returned in the trend callback into data series objects directly usable by the Flot charting library. This should only be executed within the context of a trend callback and only when using the Flot library.
OAS.Util.padleft(value, pad, len)  :  left-pad a string with another string
  • value: string
    The original string to be padded. This can also be anything that can be converted to a string, like a numeric.
  • pad: string
    The padding string, typically a single character (e.g. ‘0’ when padding numbers)
  • len: number
    The desired total length of the output string. For example, if you want to convert the number 9 to ‘009’ you would call OAS.Util.padleft(9,'0',3).
OAS.Util.formatDate(dt, format)  :  convert a Javascript Date object to a formatted string
  • dt: date
    The date to be converted.
  • format: string
    A standard date formatting string which replaces specific tokens with parts of the date and time. Valid tokens:
yyyy    : 4-digit year
yy      : 2-digit year
mm      : 2-digit month (e.g. February = '02')
dd      : 2-digit day of the month
HH      : 2-digit hours (24 hour format)
hh      : 2-digit hours (12 hour format)
MM      : 2-digit minutes
ss      : 2-digit seconds
aa      : am/pm designator
AA      : AM/PM designator

Examples: (January 6, 1970 2:23 pm as date input)

"yyyy-mm-dd HH:MM:ss"   > 1970-01-06 14:23:00
 
"mm/dd/yy hh:MM aa"     > 01/06/1970 02:23 pm
OAS.Trend.getTrendBinding(data)
  • data: object
    This utility returns an instance of a Trend Binding object given a set of data returned in the trend callback. This is useful for determining which chart and set of pens the data is for, since the trend binding calls are asynchronous.

 

Historical Data

To display historical data in a chart, you configure your Trend Binding exactly as if you were displaying trend data, then make a single JavaScript call:

OAS.Trend.getHistoryData(trend_binding, startDate, endDate);
  • trend_binding: string|trend_binding object
    This can be either a string, or a reference to a Trend Binding object. If you pass a string, it must match the chartid of an existing Trend Binding. This is the trend binding that will be placed into “History Mode”. Executing this more than once will have no effect.
  • startDate: string|date
    A Javascript Date object or string that can be converted into a Javascript Date (e.g. “01/31/2013 07:22 am”). This date and time is the start of the timespan for History data points requested from the server.
  • endDate: datetime
    A Javascript Date object or string that can be converted into a Javascript Date (e.g. “01/31/2013 07:22 am”). This date and time is the end of the timespan for History data points requested from the server.

Executing OAS.Trend.getHistoryData will place the chart in “History Mode”, displaying a static set of data for the configured Tags, between the start and end dates provided. There may be a brief delay between the execution and the display of the History Data. This is the result of the server generating the data set and sending it back to the client.

To revert back to “Real Time Mode” and to see live data, execute:

OAS.Trend.resumeTrendData(trend_binding);
  • trend_binding: string|trend_binding object
    This can be either a string, or a reference to a Trend Binding object. If you pass a string, it must match the chartid of an existing Trend Binding. This is the trend binding that will be placed back into “Real Time Mode”. Executing this more than once will have no effect.

Explicit Data Logging Group Reference

The getHistoryData call requests data for Tags within Data Logging Groups on the OAS Server. In cases where the Tag is being logged to multiple Logging Groups, you can choose which group will be used to extract data from the external database. To do this you specify the historytag field in the tag definition of your trend_binding. More information on trend_binding configurations can be found here.

Data Object

Each time the Trend Binding Callback function is called, a data object will be passed in, containing the following structure:

{
    chartinstanceguid: <string>, 
    firsttime: <datetime>, 
    lasttime: <datetime>, 
    message: <string>,
    numberofvalues: <integer>,
    penvalues: <array>,
    timesforreturnalldata: <array>,
    status: <string>
}
  • chartinstanceguid: string
    A unique identifier assigned to the Trend Binding by the OAS Server. This is used to identify the requesting client and individual binding so the server efficiently provides the client only data that is required and not previously sent. This value is used internally by the OAS Web HMI library.
  • firsttime: datetime
    A datetime representing the timestamp of the FIRST value in the series of values supplied in the data object. Combined with lasttime, you can determine the time scale for the data set.
  • lasttime: datetime
    A datetime representing the timestamp of the LAST value in the series of values supplied in the data object. Combined with firsttime, you can determine the time scale for the data set.
  • message: string
    A message sent from the server in the event of an error. For normal successful callbacks, this will be blank.
  • numberofvalues: integer
    The number of values in each array of values within the context of this data set.
  • penvalues: array
    Penvalues are an array of integer arrays, each containing a set of values corresponding directly to Tag Definitions in the Trend Binding. These arrays are provided in the same order that the Tag Definitions. Example:
[
    [0.50, 0.653, 0.480, 0.12],
    [16, 12, 38, 120]
]

The example above corresponds to a Trend Binding with 2 Tag Definitions. The full data structure may look something like the following. Note, that numberofvalues is the number of values in each set of penvalues, not the number of penvalues itself:

{
    chartinstanceguid: "d7a2b517-df07-4b5f-ab05-fd6a5e7d534b"
    firsttime: Fri Jun 28 2013 14:25:39 GMT-0400 (Eastern Daylight Time)
    lasttime: Fri Jun 28 2013 14:25:42 GMT-0400 (Eastern Daylight Time)
    message: ""
    numberofvalues: 4
    penvalues: [
        [0.50, 0.653, 0.480, 0.12],
        [16, 12, 38, 120]
    ],
    status: "OK"
}
  • timesforreturnalldata: array
    If the returnalldatawithtimes option is set to true, the timesforreturnalldata will be present in the data set. This array will contain the same number if entries in each array for each pen, and each entry will be a timestamp representing the actual date/time for the corresponding pen value.
  • status: string
    The status of the callback. For successful operations, this will be “OK” and “ERROR” for all others. So you may choose to only process results with the status is “OK” and ignore others, or display a custom message to the user.