Authentication Examples

Security is included for free with all of the product features of Open Automation Software.   To ensure that all requests for server data be performed by an authorized user, the OAS Web HMI Script Library attaches an authentication token to each request. This token is generated by the Open Automation Software Server when provided a valid credential.  The token will expire after a period of disuse, or when the Open Automation Software Server is restarted, so it should be generated dynamically when a page is initially accessed.

This article covers how to generate and store these tokens with:

  1. ASP.NET both C# and VB
  2. JavaScript

STEP 1

The first step for either method is the same: define and configure your security groups and users. This Getting Started – Security article describes how to do that with the OAS configuration tool.  There is also a video about that here.  Security users and group can also be set up with the OAS programmatic interface, learn about that here.

You will need to include a few files at the top of your pages as well:

  •  jQuery v1.8.3 or later
  •  The OAS Web HMI Script Library
  • A small block of Javascript containing an authentication token and URL location of the Open Automation Software Server.

You can learn more about that on our Installation and Configuration page.


STEP 2

ASP.NET Authentication

Here is the login page for the .NET example:

In the button click event, first assign the username and password entered by the user to local variables.  Next, instantiate a new instance of the OASConfig.Config object. Then, assign the token returned by the GetToken method to an ASP.NET session variable.  Doing so allows you to retrieve that information in the subsequent pages.  Depending on the version of ASP.NET you are using, you can pass the token in different ways.  The example also stores the OAS Server address as a session variable.  Finally, redirect the user to the next page.

C#

protected void btnSubmit_Click(object sender, EventArgs e) {
  string un = username.Value; 
  string pw = password.Value; 
  string err = "";
  var config = new OASConfig.Config();
  Session["token"] = config.GetToken(un, pw, "", ref err); 
  Session["OASServer"] = "http://localhost:58725"; 
  Response.Redirect("default.aspx");
}

VB

Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
  Dim un As String = username.Value 
  Dim pw As String = password.Value 
  Dim err As String = ""
  Dim token As String = ""
  Dim config As New OASConfig.Config()  
  token = config.GetToken(un, pw, "", err) 
  Session("token") = token
  Session("OASServer") = "http://localhost:58725" 
  Response.Redirect("default.aspx")
End Sub

If a token was successfully created and the user has permissions to view tags, the display screen will look like this: 

If they did not provide valid credentials, the screen they will see will look like this:

The OAS Service generates a token whether or not the user provides valid credentials.  However, if the user has bypassed the login page, no token has been created.  So here, check to for the existence of a token. If none exists, return them to the login page to authenticate.  If one does exist, use the ASP.NET ScriptManager to programmatically write JavaScript to pass the token to the OAS Service on the client side.

C#

protected void Page_Load(object sender, EventArgs e) {
  string token = "";
  if (Session["token"] != null) {
    token = Session["token"].ToString();
  }
  if (token == "") {
    Response.Redirect("login.aspx");
  }
  ScriptManager.RegisterStartupScript(this, this.GetType(),
    "OASWebToken",
    "OAS_config = {token:'" + token + "',serverURL: '" + Session["OASServer"] + "'};",
    true);
}

VB

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
  Dim token As String = Session("token")
  If token = "" Then
    Response.Redirect("login.aspx")
  Else
    Dim server As String = Session("OASServer")
    ScriptManager.RegisterStartupScript(Page, Me.GetType(), "OASWebToken",
      "OAS_config = {token:'" + token + "',serverURL:'" + server + "'};", True)
  End If
End Sub

JavaScript Authentication

Next, let’s look at how to do this entirely from the client side using JavaScript.

At the top is the OAS_config tag, set with a dummy token and the OAS Service URL. I also have a watch_tags call in it so that it is talking to the OAS Service and am specifying a function, updateStuff(), in the refresh_callback. In the updateStuff() function, I first check to see if if a new token has been created in the submit function above. If it has been, I add it to window object’s localStorage so that I access it from subsequent pages. I then, redirect the user to the next page. There, the submit function takes the username and password and calls OAS.authenticate to validate the user and retrieve the new token. The event.preventDefault() stops the form from submitting and allow the updateStuff() to handle it.

JavaScript for Login Page

<script type='text/javascript'>
  OAS_config = {
    token:'-481d-4551-b24b-7e61b230ba9046e3d8f2',
    serverURL: 'http://localhost:58725',
    refresh_callback: updateStuff,
    watch_tags:["Sine.Value"]
  };

  $( document ).ready(function() {
    $( "#form1" ).submit(function( event ) { 
      // on submit, get the
      // username and pw and authenticate
      var un = $("#username").val();
      var pw = $("#password").val();
      OAS.authenticate(un,pw);
      event.preventDefault();
    });
  });
  
  function updateStuff() {
    if (OAS.token != OAS_config.token) {
      //check to see if a new token was created
      localStorage.setItem('token', OAS.token);  //store the token in local storage
      location.href = "default.htm"; // redirect to main page
      console.log("Token Set:" + localStorage.getItem('token'));
    }
  }
</script>

JavaScript for Display Page

At the top of your display pages, you will need to include the following JavaScript as well.  It retrieves the token from localStorage and puts in the OAS_config.

<script type='text/javascript'>  
   OAS_config  = {
   token: localStorage.getItem('token'),
   serverURL: 'http://localhost:58725'
   };        
</script>

STEP 3

The HTML for All Authentication Methods

If the a token has been generated, the user is allowed to stay on the page.  If authentication fails, the user should not be able to view anything; this can be accomplished by creating a Boolean tag in the OAS Configuration tool called FlagTrue. For organizational purposes, put it in a folder called SecurityDemoFlags. Set the default value of the flag to true. Surround the portion of the page that is not to be displayed to unauthorized users with a div tag. Use an OAS attribute on the tag to control visibility. If the user is not able to read tags, tags will come in with bad_q. Set the bad_q for the Boolean tag controlling visibility to false. With it set this way, unauthorized users will not be able to see this area of the page and authorized users will.

Below there is another div which displays the message: You do not have permission to view this page. Use the same flag to control visibility for this div.  When an unauthorized user visits the page, OAS sends the false bad_q indicator to the tag that set above. This div has an OAS attribute of “trigger: on_false”.

Learn more about adding OAS attributes to HTML tags here in our HTML Attribute Reference or by using our Web HMI Wizard.

In this demo, there are several tags and a button that toggles a pump on or off.  If the user has read permissions only, the button would display the value of the pump but would not allow the user to change it.   You can create different groups/users and control what the users are able to see and do.

<div style="margin-left: auto; margin-right: auto; width: 240px; text-align: center;">
  <img src='images/logo.png'/>
    <div id="divDisplay" style="margin-top:30px;" 
      oas-tag-vis='{
        "tag": "SecurityDemoFlags.FlagTrue.Value",
        "config": { "bad_q": false }
    }'>
    <div class="d1">
      <span class='heading'>Sine:</span>
      <label id='lb1' oas-tag-txt='{"tag":"Sine.Value"}'></label>
    </div>
    <div class="d1">
      <span class='heading'>Ramp:</span>
      <label id='lb2' oas-tag-txt='{"tag":"Ramp.Value"}'></label>
    </div>
    <div class="d1">
      <span class='heading'>Random:</span>
      <label id='lb3' oas-tag-txt='{"tag":"Random.Value"}'></label>
    </div>
    <div class="d1">
      <span class='heading'>Pump:</span>
      <button onclick="return false;" id='test' 
        oas-tag-txt='{
          "tag": "Pump.Value",
          "config": {
            "formats": {
              "bool_f": "Pump Off",
              "bool_t": "Pump On"
            }
          }
        }' 
        oas-tag-set='{
          "tag": "Pump.Value",
          "config": {
            "evt": "click",
            "set": "toggle",
            "set_confirm": false
          }
        }' 
        oas-tag-bkg='{
          "type": "group",
          "all_f": { "color": "#FF0033" },
          "bad_q": {},
          "group": [
            { "tag": "Pump.Value", "config": { "color": "#8DC642" } }
          ]}'>
      </button>
    </div>
  </div>
</div>

<div style="width: 500px; text-align: center; margin-left: auto; margin-right: auto;" id="divMessage"
  oas-tag-vis='{
    "tag": "SecurityDemoFlags.FlagTrue.Value",
    "config": { "trigger":"on_false" }
}'>You do not have permission to view this page.</div>

Here are downloadable source code examples for all three types of Authentication:

OAS File Locations

Following is where you can find the locations of the Open Automation Software options, license, and other default files.

Config Files Folder

The Config Files Folder is a specific folder in the operating where the OAS options, license, custom objects files are located.

Linux operating system there is a ConfigFiles sub-directory located in the directory you have deployed the OAS Engine.

Note: If moving the OAS Engine folder in Linux make sure all files in the ConfigFiles sub-directory are moved with the OAS Engine.

Windows operating system this is C:\ProgramData\OpenAutomationSoftware\ConfigFiles\

Note: ProgramData is by default a hidden directory in Windows and you can use Windows Explorer to show hidden folders.

To view ProgramData follow these steps.

  • open File Explorer options from Control Panel
  • Then to View Tab.
  • Uncheck “Hide protected Operating system files” and click on “Show hidden files and folders”
  • Press Yes and then OK.

 

OAS.Options

The OAS.Options file contains all settings defined under Configure-Options of the Configure OAS application.

OAS.License

The OAS.License file will be updated with an activation with the OAS Serial Number to enable product features and the number of tags in the license.

OAS.GUID

The OAS.GUID file will be generated the first time the OAS Engine starts on a new operating system.  This contains a unique identifier for store and forward functionality after a system restart.

OAS.CustomObjects

The OAS.CustomObjects file is generated any time a custom object is programmatically assigned using the OASConfig or OPCSystems component.  This is also the file that will persist all user changes for the Web HMI Dashboard.


OAS Options

All options can be set using the Configure OAS application with Configure-Options or programmatically with the OASConfig .NET component,  OPCSystems .NET component, or REST API for OAS.  All options are persisted in the OAS.Options file in the ConfigFiles sub-directory.

Default Configuration Files

Use the Configure OAS application with Configure-Options-Default Files to specify the default configuration files to load when the operating system restarts.  The location of all configuration files will be in the ConfigFiles sub-directory. These settings are stored with the OAS.Options file.

System Logging

Use the Configure OAS application with Configure-Options-System Logging to specify the file path of the OAS System Errors, Communication Errors, and Transaction Logs. These settings are stored with the OAS.Options file.

Store and Forward Folder

Use the Configure OAS application with Configure-Options-Data Buffer to specify the folder to use for data logging and alarm logging store and forward feature. This setting is stored with the OAS.Options file.

Retain Values on System Restart

Use the Configure OAS application with Configure-Options-Retain Values to specify the file path to retain Values and Alarm Limit changes, Time On and Counts, Realtime Trending, and Realtime Alarms. These settings are stored with the OAS.Options file.

File Data Source

The ConfigFiles subdirectory is the location for files when Tags are set to a Data Source of File-Text, Binary, or XML.


OPC UA Trusted Certificates

If the OPC UA Server you are connecting to has security restriction using Certificates you can move the rejected certificates to the trusted certificates under following paths.

Linux operating system there will be a pki sub-directory created under the directory where the OAS Engine is located.

Windows operating system this is C:\ProgramData\OpenAutomationSoftware\pki\

C:\ProgramData\OpenAutomationSoftware\pki\rejected\certs
C:\ProgramData\OpenAutomationSoftware\pki\trusted\certs

The OAS OPC Server third-party OPC UA client certificates location is pki-server sub-directory.

Linux operating system there will be a pki-server sub-directory created under the directory where the OAS Engine is located.

Windows operating system this is C:\ProgramData\OpenAutomationSoftware\pki-server\

C:\ProgramData\OpenAutomationSoftware\pki-server\rejected\certs
C:\ProgramData\OpenAutomationSoftware\pki-server\trusted\certs

Linux Installation

Prerequisites

For any Linux installation, general knowledge of Linux server configuration is required.
This includes being comfortable with the following tasks:

  • managing user accounts
  • managing files and user permissions
  • transferring files between machines
  • networking configuration
  • configuring services (daemons in systemd)

While OAS is happy to support the OAS installation and any issues related to the product, support does not include managing Linux server configuration and administrative tasks.


Deployment

After downloading the Linux OAS Engine from the OAS Downloads page extract the contents of the .ZIP file (e.g. oas-linux.zip) to any directory of the Linux operating system.  The contents can be copied to the target Linux machine directly, or you can copy the .ZIP archive and unzip on the Linux machine itself.


OAS Configuration Client

You can download the OAS Configuration Client from the same downloads page if you would like to configure your OAS instances from a Linux based operating system. To install the Configure OAS client see the Configure OAS Overview.


Installation Script

Note: Perform the installation on your Linux system using root access or with an account with sudo privileges.

The following are instructions for using the included installation script. This script has been thoroughly tested on Ubuntu, but may not work properly in all Linux distributions. For example some scripted operations are blocked on Debian and Debian variants such as Raspbian. If you experience issues running the script or if the OAS server does not start after running the script, we suggest using the Manual Installation method.

View the following video to view the following steps implemented with Ubuntu on a Raspberry Pi device.

Run the installation script to properly configure the OASEngine

Log into your Linux machine with an account that has root or sudo permissions. Either connect to the machine from an SSH session, or open a terminal on the machine itself, if you’re using a GUI.

Navigate to the daemon directory within the installation path and locate the oas_install.sh script. In this example, we’re using the ARM64 installation on a Raspberry Pi 4 running Ubuntu, but the same instructions and commands apply to any Linux distribution.

 

Ensure the installation script is executable, then run the installation using the following commands:

sudo chmod +x oas_install.sh
sudo ./oas_install.sh

NOTE: When you execute any script on Linux and receive an error such as “No such file or directory”, this may be resolved by converting the file to unix-type line breaks. This can be done with the command dos2unix which is installed using the following command on many Linux distributions:

sudo apt update
sudo apt install -y dos2unix

You will be prompted to enter the password for the root or administrator currently logged in if you don’t currently have sudo permissions.

The installation script will next walk you through the following:

  • Creating or selecting a user account for the OASEngine service. Using the defaults, an account called oasuser will be created.
  • Installing the service in the selected user’s account
  • Optionally starting the newly installed service
Step 1: run the installation and select a user account to host the OASEngine. If the user does not exist, you will be prompted to create a password for the new user.
Step 2: the installation completes and prompts to be started
Step 3: Installation completed and service started.rol
 

The OASEngine is now installed as a user service or daemon under the account selected or created (default: oasuser). This service is managed by systemd and can be controlled or monitored like any systemd service. By default, the OASEngine is now configured to start up when the machine reboots.

You can now use the Configure OAS application to configure the server. This can be done from any local or remote workstation or server using Windows or Linux. The Windows client is installed as part of the OAS platform. The Linux client can be downloaded and installed independently from the downloads page.

Ensure that the PC Firewall allows TCP communication on port 58727. For more information on configuring an OAS installation see the documentation for the Configure OAS application.


Manual Installation

Unless noted, all operations below must be performed under the root account, or using an account with sudo permissions.

Create a Service User Account

The following commands will create a user named oasuser, however you can use any valid username. If not using the default oasuser name, be sure to use that name in further instructions where oasuser is mentioned.

sudo useradd -m oasuser
sudo loginctl enable-linger oasuser
sudo passwd oasuser

The passwd command will prompt you to enter and confirm a password for this user. Be sure to store this password securely as it will be needed for logging in and managing the OAS Service.

Copy OAS Service files to Service User’s home

Copy the unzipped installation directory to the OAS Service user’s home. Then set ownership of the installation directory and contents to the OAS Service user. In this example, the install directory is oas-linux, but depending on the version being used, this may also be oas-linux-arm or oas-linux-arm64.

sudo chown -R oasuser:oasuser /home/oasuser/oas-linux

Configure OAS Service to start on boot

Edit the oas-engine.service file located in the daemon directory within the installation path using nano, vi or your favorite text editor on Linux. Modify the file by changing references to oasuser to your OAS Service username if you have chosen another, and modify the oas-linux path to oas-linux-arm or oas-linux-arm64 if you are using either of those versions. Make all modifications necessary for the file to resemble the one below:

[Unit]
Description=Open Automation Software Engine

[Service]
ExecStart=/home/oasuser/oas-linux/OASEngine
WorkingDirectory=/home/oasuser/oas-linux
SyslogIdentifier=oas-engine
PrivateTmp=false
KillMode=process

[Install]
WantedBy=default.target

Save and copy the oas-engine.service file to the .config directory using the commands below, again replacing oas-linux in the path as necessary:

sudo mkdir /home/oasuser/.config/systemd/user/
sudo cp /home/oasuser/oas-linux/daemon/oas-engine.service /home/oasuser/.config/systemd/user

Log out and log back in as the OAS Service user (oasuser) to complete the installation.

Enable and start the OAS Service

systemctl --user enable oas-engine
systemctl --user start oas-engine

Uninstall

Included with the OAS installation script is an uninstaller, as well. This file is oas_uninstall.sh and located in the same directory as the installation script. Similarly, you will need to mark this file for execution before running it. Only use this script if the installation script was successful. Use the following commands to mark for execution and then start the uninstaller:

sudo chmod +x oas_uninstall.sh
sudo ./oas_uninstall.sh

The uninstaller script will attempt to back out the installation by performing the following actions.

  • Stop the OASEngine service
  • Remove all installation files
  • Remove user account created for running the service (optional)
    When prompted to remove the OAS user account, you can choose ‘no’ to keep the account intact.

For manually uninstalling the OAS Service:

Log into the account created for running the OAS Service

Stop the OASEngine

systemctl --user stop oas-engine

Disable the systemd service

systemctl --user disable oas-engine

You can optionally remove the entire installation directory from the Service User account home or leave it in place if you plan on using OAS again at some point.


Service Control

Confirm that the service is running

Log into the Linux machine using the credential created during the installation. By default this is oasuser. Then, execute the following command to determine the oas-engine status:

systemctl --user status

This should return something similar to:

State: running
Jobs: 0 queued
Failed: 0 units
Since: Mon 2021-03-01 16:34:33 UTC; 3 weeks 6 days ago
CGroup: /user.slice/user-1001.slice/user@1001.service
├─oas-engine.service
│ └─2214 /home/oasuser/oas-linux-arm64/OASEngine

If you do not see the oas-engine.service listed as running, you can begin troubleshooting by attempting to run the OASEngine manually and checking for errors on startup in the console. To do this, locate the OASEngine executable within the installation directory for the user. This will be in the user’s home directory and named oas-linux, oas-linux-arm, or oas-linux-arm64 depending on the version installed. Within this directory, execute the following:

./OASEngine

This will directly start an instance of the service and output feedback on status. If any errors are reported on startup, make note of them and contact OAS Support for more information.

Managing the Service Installation

The installation script created a service configuration file that can be modified with any additional parameters, such as restart behavior. This is particularly useful if you want to automatically restart the OASEngine in the unlikely event that the process is killed or interrupted. You can locate the service configuration file on following path when logged in as the selected user:

~/.config/systemd/user/oas-engine.service

The contents of the file are the following, with the paths adjusted for the specific user and depending on the specific Linux distribution you are using:

[Unit]
Description=Open Automation Software Engine

[Service]
ExecStart=/home/oasuser/oas-linux-arm64/OASEngine
WorkingDirectory=/home/oasuser/oas-linux-arm64
SyslogIdentifier=oas-engine
PrivateTmp=false
KillMode=process

[Install]

Once you log into the Linux machine as the selected user, you can gracefully stop and start the service using the following commands:

Stop the service:

systemctl --user stop oas-engine

Start the service:

systemctl --user start oas-engine

Troubleshooting

The installation script throws errors or returns a ‘No such file or directory’ message

The file may contain incompatible line endings for Linux – see the instructions above for fixing this using the dos2linux command.

The Linux distribution you are using (e.g. Debian and variants) may be incompatible with the installation script. Follow the Manual Installation instructions.

The service does not start on reboot

Ensure that the service is enabled. Log into the server with the OAS Service account created or referenced during the installation – by default this is oasuser. Then execute the following command:

systemctl --user enable oas-engine

Also, be sure that the OAS Service user can run unattended and does not require a login session for services to run. Logged in as root or sudo user, execute the following command:

sudo loginctl enable-linger oasuser

Any other issues?

Contact support@oasiot.com and we will evaluate your configuration and determine the cause.

Getting Started Azure IoT Data Hub

Create an IoT hub

View the following video for a complete demonstration of how to send live data to Azure IoT Data Hub.

You need to create an IoT Hub for your device to connect to. The following steps show you how to complete this task using the Azure portal:

Step 1

Sign in to the Azure portal.

Step 2

From the left menu, Select Create a resource, then click Internet of Things, and then click IoT Hub.

Step 3

Under the Basics tab, fill in the information for your new hub.

Step 4

In Resource group, create a new resource group, or select an existing one. For more information, see Using resource groups to manage your Azure resources.

Step 5

In the Name box, enter a name for your IoT hub. If the Name is valid and available, a green check mark appears in the Name box.

Select a Pricing and scale tier. This tutorial does not require a specific tier.

Step 6

In Resource group, create a new resource group, or select an existing one. For more information, see Using resource groups to manage your Azure resources.

Step 7

In Location, select the location to host your IoT hub.

Step 8

When you have chosen your IoT hub configuration options, click Create. It can take a few minutes for Azure to create your IoT hub. To check the status, you can monitor the progress on the Startboard or in the Notifications panel.

Azure IoT Data Hub_110

When the IoT hub has been created successfully, open the blade of the new IoT hub, make a note of the Hostname, and then click the Keys icon.

Azure IoT Data Hub_111

Step 9

Click theiothubowner policy, then copy and make note of the connection string in the iothubowner blade.

Azure IoT Data Hub_112

You have now created your IoT hub and you have the hostname and connection string you need to complete the rest of this tutorial.

Azure IoT Data Hub_113

Create an IoT Driver

Step 1

Open Configure OAS

Step 2

Select Drivers

Azure IoT Data Hub_118

Step 3

Select your local or remote system

Step 4

Enter the Driver Name you wish to use.

Step 5

Select Azure IoT Driver from the combo box

Step 6

Enter the Azure IoT Device ID you want to use.

Step 7

Enter the Connection String from Step 5 of the previous section into the Azure IoT Hub Connection field.

Step 8

Enter the hostname from Step 4 of the previous section into the Azure IoT Hub URL Field.

Step 9

Select the preferred Azure IoT Transport.

Step 10

At the bottom Left of the configure application select Add.

Route Live Data to your Azure IoT Hub.

Step 1

Select Configure Tags.

Step 2

From the demo tags select the Ramp Tag.

Azure IoT Data Hub_120

Step 3

Select the Target button

Azure IoT Data Hub_121

Step 4

Enable Write to target.

Step 5

Select the Azure IoT Destination type.

Step 6

Select the Driver interface you created.

Step 7

Apply the Changes and you should now be writing to your IoT Hub.

Step 8

The message is formatted as follows.

{“deviceId”:”myFirstDevice”,”TagName”:”Ramp”,”Value”:66,”DataType”:”DoubleFloat”,”Quality”:true,”TimeStamp”:”2016-04-11T14:38:53.7125255″}

.

UDI for Raspberry Pi GPIO

Raspberry Pi Logo.svg

The Raspberry Pi has quickly become a popular device used to prototype or become the core of an Internet of Things (IOT) component. Being a small, single board computing platform allows it to be used where conventional computers would either be too large or unable to withstand environmental forces. Yet, because it runs a variant of Linux, it is a fully functional general purpose computer.

Pi devices were designed to be modified and expanded. As such each model includes many I/O ports as well as a bank of pins called the General Purpose I/O pins or GPIO. These pins are addressable, can be configured for either input or output, and in some cases can even support serial communication. The most common use is reading and writing boolean values.

In this diagram of a Raspberry Pi 3, you can see the bank of 40 GPIO pins on the right hand side. Older models only include 26 pins, and some models arrange them differently to fit on the PCB.

The Challenge

There are many open source libraries for reading and writing GPIO pin statuses in many different languages and operating systems. But rapidly prototyping an IoT device comes with many other challenges. So our goal was to produce a driver for the OAS Platform to allow an OAS server to communicate with a Pi device and access GPIO data, all without an admin or end-user needing to write code for each deployment. In short, we wanted to create a driver that behaves like existing OAS native drivers and is configurable through the OAS Configuration tools.

The Universal Driver Interface

With the release of the OAS Universal Driver Interface (UDI) SDK, developers can now create their own custom device or data drivers which act like and live side-by-side with existing native drivers such as our Allen Bradley or Siemens PLC drivers. In addition, UDI implementations can be deployed at the data source and be configured to communicate with a remote OAS server. This ensures that the data is captured reliably from the data source and transmitted to OAS as long as a network connection can be established.

The UDI for the Raspberry Pi GPIO acts as a conduit between the GPIO Data and OAS.

The technology that makes this possible is the .NET Core Framework, which can run on a Linux device.

Remote Driver Hosting

Built-in or “native” OAS Platform drivers such as the Allen Bradley and Siemens PLC drivers are part of the OAS services that run on a Windows server. But since the UDI libraries are based on the .NET 2.0 Standard, UDI drivers can be compiled to execute on any environment that supports the .NET Core runtime. This means you can host a custom driver on a remote device or server such as a Raspberry Pi, thus making data capture more efficient and distributing the load of your solution.

Tag Configuration

Another powerful feature of the UDI is the ability to define custom tag properties based on the driver. So when a Tag’s data source is selected as your UDI driver, your custom properties are displayed in the Tag configuration screen. In the case of the Pi GPIO UDI, we expose properties to control which GPIO Pin is mapped to a tag, and the data direction (input or output).

By changing the Pin Mode, this actually alters the Pin Mode within the the Pi device itself. Selecting the BCM Pin maps the Tag to the Pin using the BCM pin numbering scheme.

Output Pins: the tag value will be set to the pin value on the device

Input Pins: the tag value will be set to the current pin value on the device, and will also allow you to set the pin value on the device by setting the Tag to a boolean True or False.

Connection and Configuration on Startup

Each deployment of the Raspberry Pi UDI can be configured using an external file. This configuration file contains fields for uniquely identifying the device, as well as setting the remote OAS server address and port. When the driver spins up, it will make a network connection to the OAS server and begin transmitting data when an OAS Tag has been configured. Additionally, a UDI can be written to actually create and configure tags on a remote server, so that a deployment does not require any manual keying of Tag configuration fields, reducing errors and ensuring each follow on deployment can be completed with minimal effort.

The appsettings.json file:

ServiceNode: the remote OAS server address

PortNumber: OAS Server port

MachineName: the unique name for the device hosting the UDI Driver

Project Source Code

This UDI implementation for the Raspberry Pi is fully functional, but can be used as the basis of your own projects. Source code is available in C#, and requires the following:

  • MS Visual Studio 2017+
  • .NET Core 2.0+ Libraries

Download Project Source Code

For more information on the OAS Universal Driver Interface and how to develop your own, see the following articles:

One Click OPC UA

Tags can be automatically set up using the One Click OPC UA feature, which browses OPC UA servers automatically and creates tags based on the nodes defined in the OPC UA server. You can then delete tags from the configuration that are unnecessary.

Note: You will need to be running Open Automation Software Version 12.0.0.9 or greater to support the One Click OPC UA feature. You can download the latest version from our Open Automation Software Download page.

Step 1 – Configure OPC UA Driver

NOTE: If you have already defined a driver as described in the Getting Started – OPC UA Server guide you can proceed to Step 2 – Configure OPC UA Tags.

OAS

Start Configure OAS application from the program group Open Automation Software.

Select Configure-Drivers.

Configure Drivers

NOTE: To configure remote OAS Engines enter the IP Address or node name in the Network Node field and click on Select.

Network Node

Enter a meaningful Driver Interface Name that you will refer to this physical connection when defining Tags with an OPCUA Data Source.

OPC UA Driver Name

Set the Driver type to OPC UA.

OPC UA Driver

Define the Server Url property to the endpoint of the OPC UA server to connect to.

Server Url

Use the BROWSE button of the Security Profile to select one of the security profiles. Use None:None:Binary for the fastest interface.

OPC UA Security Profile
OPC UA Security Profiles

If the server requires user authentication enable the property User Security to define the Username and Password.

OPC UA User Security

NOTE: The certificate path is C:\ProgramData\OpenAutomationSoftware\pki on Windows and /ConfigFiles/pki/ on Linux. You may need to move the server’s certificate from the rejected\certs folder to the trusted\certs folder.

OPC UA Certificates

Select the Add Driver button in the upper left of the window to add the Driver Interface as an available selection when defining Tags in the next step.

Add Driver

Step 2 – Configure OPC UA Tags

Select Configure-Tags.

Menu Configure Tags

Select Add Group to add a group to place tags in.

Add Tag Group

Select the Group 01 group, then click the One Click Import button on the top toolbar.

One Click Import

Select the OPC UA Driver Interface defined in Step 1 if there are multiple drivers defined.

One Click OPC UA Driver

Select the IMPORT OPC UA ITEMS button.

Browse and select the parent folder containing all nodes this parent folder and all sub folders to automatically add.

One Click OPC UA Browse

Select to enable the options to Get Data Type from OPC UA Server and optionally the Descriptions.

Select the green Add Tags button in the lower left to all all nodes in this selected folder and all of its sub folders.

OPC UA Tags List

Optionally delete Tags and Groups you do not want to be included in the configuration that have been imported.
Select the Save button on the toolbar at the top.

Step 3 – Save OPC UA Tags and Drivers

Select the Save button on the toolbar at the top.

Load and Save

Enter a file name to be saved in C:\ProgramData\OpenAutomationSoftware\ConfigFiles directory on Windows or ConfigFiles subdirectory on Linux.

When prompted to set the file as the default configuration to load on startup select Yes.

Set Default Tag File

NOTE: The tags and and drivers are both saved into one file.

The tags defined are now ready for use in all OAS features like Data Logging, Data Route, and Open UIEngine.

Getting Started OPC DA

Open Automation Software Tags can be defined to connect to Classic OPC Data Access 2.xx and 3.0 Servers with the built in OPC Interface.

View the following video to see how to connect to a classic OPC DA server.

The following steps can be used to setup communications with Classic Data Access OPC Servers.

Step 1 – Configure OPC DA Tags

OAS

Start Configure OAS application from the program group Open Automation Software.

Select Configure-Tags.

Menu Configure Tags

NOTE: To configure remote OAS Engines enter the IP Address or node name in the Network Node field and click on Select.

Network Node

Select Add Group to add a group to place tags in.

Add Group
Add Tag Group

NOTE: You can add organizational Groups as many levels deep as you prefer and add tags to groups.  To do this first add a Group to the root level, then right click on the Group in the right window to add additional Groups or Tags.

Tag Group Options

Select Add Tag to add a tag to the group selected.

Add Tag
Add Tag to Group

Change the Data Source Tag property to OPC.

OPC Data Source

Use the Browse button to the right of the OPC Item to browse OPC Servers for the desired OPC Item.

Getting Started OPC Item

Select Local, the desired OPC Server, branch within the OPC Server, and OPC Item and click OK.
Getting Started OPC Browse

Note: If you wish to browse remote OPC servers via IP address see Networking OPC Data.

Specify the desired OPC Update Rate for the Tag.

Getting Started OPC Update Rate

To disable communications to the device you can use Enable by Tag to control when communications is active. Leave this property disabled to establish communications at all times.

Enable by Tag

The Device Read property can be used to disable continuous polling and request data on event from the transition from false to true of a value of a Boolean tag. Leave this property disabled to establish communications at all times.

Device Read

Select Apply Changes in the lower right to activate the communications for the OPC Item.

Apply Changes

The value from OPC Server for the OPC Item selected will appear in the current Value field.

Good Quality

NOTE: If the data quality is Bad Quality view the article Troubleshooting OPC Communications.

Step 2 – Define Multiple OPC Tags

To define multiple tags use one of the following optional methods.

  • Use One Click OPC to automatically create tags from all OPC Items from a selected OPC Server or branch within an OPC Server. Then selectively delete the groups and tags that are not required.
  • Use CSV Export and CSV Import on the toolbar together with Microsoft Excel to add or modify tags.
  • Programmatically define Tags using the free to use OASConfig component with the SetTagProperties method.
  • Programmatically define Tags with the OAS REST API.

Optionally define a secondary failover OPC Server if the primary OPC Servers fails under Configure-Options-OPC.

Step 3 – Save OPC DA Tags

Select the Save button on the toolbar at the top.

Load and Save

Enter a file name to be saved in C:\ProgramData\OpenAutomationSoftware\ConfigFiles directory on Windows or ConfigFiles subdirectory on Linux.

When prompted to set the file as the default configuration to load on startup select Yes.

Set Default Tag File

The tags defined are now ready for use in all OAS features like Data Logging, Data Route, and Open UIEngine.

Data Historian Performance Benchmarks

DB Engines Compared

In an effort to help you decide which database engine to choose in your implementation, and how you can boost performance with an existing OAS configuration, we’ve performed extensive testing. On each of the database engines listed, we configured our Data Historian to log Tag Data in 3 different ways.

Narrow
In this configuration, a single value is written per table along with a timestamp for the logged value. This means each OAS Tag logged will result in a single database table.

Wide 10
Each table contains 10 OAS Tags arranged in a single row for each given timestamp. In this test we logged 10 OAS Tag values in a single table.

Wide 990
Using the same configuration as Wide 10, but logging 990 OAS Tags per timestamp.

Conclusions

From our testing, we’ve determined that the fastest overall DB engine is Microsoft SQL Server, even though it performed only slightly slower in the Narrow table test than the next fastest engine Oracle. But because of its dramatically superior performance in all other tests (>2M values per second!), we recommend using MS SQL Server for data logging where possible. Oracle and mySQL are the next fastest engines, and have similar performance numbers to each other, but are also extremely quick when using a Wide logging format.

Efficiency is boosted with logging multiple values per table in the Wide formats, and the fastest speeds can be achieved when increasing the number of values per record. Yet, because we log to an open format, you can still perform post-processing or data archiving that transforms this wide format into a normalized configuration for your own internal usage, while still getting the benefits of high-speed logging.

Configuring OAS Web Services

To use the OAS REST API you must make sure that the OAS HTTP service is listening on the correct port. This is done within the OAS Configuration application.

Open the OAS Configuration application and select Configure > Options.

Menu Configure Options

NOTE: To configure remote OAS Engines enter the IP Address or node name in the Network Node field and click on Select.

Network Node

Under the Networking tab, locate the field for REST API/WebHMI Port Number. The default is 58725 but can be changed. If you are accessing the server from a remote client, you will also need to make sure your machine and/or company firewalls allow TCP traffic on the selected port.

Important: When using SSL we suggest using a different port number such as 58726 to avoid port conflicts.

Networking Options

Port:
This defaults to 58725, but you can set this to anything you prefer, as long as the computer and network firewalls will allow clients to reach this machine on that port.

Important: We also suggest using a different port number such as 58726 when switching to SSL to avoid port conflicts when testing different methods and configurations.

 

Using SSL with any OAS Web product as well as the REST API is fully supported.

Windows

You must first install an SSL Certificate on your server for the domain name(s) that you intend to use, for example “https://hmi.myserver.com:58726”. Once the certificate is installed properly on the server go to Configure-Options-Networking and check SSL for REST API/WebHMI and select the installed certificate from the dropdown menu. See below for how to obtain an SSL certificate and follow installation instructions from the issuer of the certificate.

SSL Certificate (host:issuer):
This dropdown will be populated with all certificates installed in the computer. The dropdown will contain information about the domain as well as the issuer, so you can be sure you’re choosing the correct certificate.

Linux

When checking the “REST API and Web HMI Use SSL” option, you will be presented with an input field and Browse button to locate a valid certificate file on the Linux machine. Select the certificate file and click Apply Changes.

Obtaining an SSL Certificate

Purchasing and installing an SSL certificate is outside of the scope of the OAS product. For more information on Windows and Certificates, see the following article.

During development, you may not have the final domain name that you will be using in production, but you would still like to test SSL communications. Many developers employ self-signed certificates. For more information, see this article.


NOTE: Making any changes to the port numbers, enabling/disabling SSL, or selecting a different SSL Certificate in this section of the configuration app will temporarily restart server processes and may cause a brief interruption in data processing when clicking Apply Changes.