Skip to content

Enabling Data Access from Web Services via OPC UA

    If you are familiar with the OmniServer, you probably already know that it can be used to retrieve information from devices that use ‘non-standard’ protocols to communicate – typically these are your weigh scales, barcode readers, and printers. However, did you know that the OmniServer can also retrieve data that is exposed via web services, or even websites?

    With the push towards the edge in integration of all of the various devices and data sources out there, it’s not a stretch at all that the web itself is a valuable source of data that you could use in conjunction with your other data sources to make informed decisions in your enterprises. Coupled with OmniServer’s native OPC UA (DA Profile) client side interface, having this ability makes it possible for your OPC UA capable client application to integrate web services data into your control system.

    You may be asking why you would need this capability.  You may or may not be aware that many of today’s instruments are now displaying data on self-hosted web pages in addition to exposing the data through a communication port via the “normal” means you may be familiar with.  Doing this allows any user with a browser to access and retrieve the information, and allows OmniServer to do the same anywhere from the same network.

    There are now also many web sites that may hold valuable information for your application that will be exposed via web APIs, such as current weather information and forecasts, commodities pricing, energy pricing, and so on. Instead of hard-coding the information into your application or having to manually enter it periodically, why not have OmniServer retrieve the values for you automatically?

    In order to best explain how to easily expose web services data using OmniServer, in the following example, we will be retrieving the current weather information for Charlotte North Carolina, using the free API that GeoNames.org exposes at http://api.geonames.org.


    1. In the OmniServer Configuration, create a new “Ethernet” device, and set the address to be the base URL we will be retrieving data from, and set the port to be 80:
    2. Create a new Protocol named “WEATHER” with the following parameters:
      1. A new item named “testString” of data type String
      2. A new Command/Response Message of Type Read:
        1. Request Message (you can copy/paste):
          GET /weatherIcaoJSON?ICAO=KCLT&username=demo HTTP=1.1{$CR}{$LF}{$CR}{$LF}
        2. Response Message (copy/paste):
          {testString}{$CR}

    This protocol will request the current weather information and allow us to view the structure of the response in the OmniServer’s IO monitor.

    1. Create a new Topic that links your “WEATHER” protocol to the Ethernet device created in Step 1.
    2. At this point we can connect an OPC UA Client application and request the testString item. This will result in our request being sent to the web service, allowing us to see what the response will look like in OmniServer’s diagnostic tool the I/O Monitor:
    3. From here the rest of the response message can be written based on the response we received on our first poll.Download the completed protocol below to take a look in your OmniServer. And, if you don’t have OmniServer, you can download the free trial version.
    4. Finally, update your UA client application to read the new protocol items, and see what values are returned:

    Unlike the vast majority of devices, web services do not contain static content. That is, it is in their very nature to change on a daily (sometimes real-time) basis.

    The OmniServer protocol used must also take this into consideration. Creating a single Host message to process all data assumes that the format of the data returned will never change (i.e. fields will never be added or removed, and the order that fields are return in will always be static, etc.).

    An easy solution might be to configure any data fields as unsolicited messages, to allow some variance in the message structure, as was done with the sample protocol above.


    As always, you can email us at support@softwaretoolbox.com with your questions and subscribe to our blog for more quick and easy OmniServer tutorials and tips.  And, as mentioned earlier, download the sample protocol from this blog and download your free trial of OmniServer to access weather in your own client.