OSIsoft PI System is an industrial data management system that is widely used to capture, process, analyze, and store any form of real-time data. With the flexibility and powerful features of FRED, users can add more values to their current OSIsoft PI System. The new node-red-contrib-osisoft-web-api node from Sense Tecnic makes it possible for you to create your own data-flow application with an existing PI System in a few hours.
About OSIsoft PI System
To stay competitive, companies must continually innovate, improve and streamline their operations. But accurately identifying how and where to improve operations can be extraordinarily challenging if the data that holds the answers is scattered among different incompatible systems, formats and processes.
Enter the PI System and its ability to collect, analyze, visualize and share large amounts of high-fidelity, time-series data from multiple sources to people and systems across all operations. By accessing key data and insights, the PI System has helped leading companies deliver greater operational improvements and breakthroughs that lead ultimately to comprehensive business transformation.
That’s the essence – and the power – of PI System operational intelligence.
-From OSIsoft PI System product page.
About Sense Tecnic
Sense Tecnic Systems Inc have been building IoT applications and services since 2010. We provide FRED, cloud-hosted Node-RED as a service to the community. We also offer a commercial version to our customers, as well as professional services. Learn more.
Create a FRED Account
If you don’t already have an account on FRED (Cloud Node-RED), set one up now. It’s free for a demo account, which can be used for these tutorials and any other experiments you may have with Node-RED. Register for a free account at http://fred.sensetecnic.com.
After registering, make sure to activate your account via your email. You will not be able to log in until you validate your account.
So, here are the steps in the tutorial:
To use the node-red-contrib-osisoft-web-api node with OSIsofi PI system, you’ll need:
- A running PI Server (more notes below)
- An OSIsoft Web API server that is connected to your PI Server, and can be accessed on the Internet
- A PI user account that has the proper privileges to read/write data on your PI system
- PI System Explorer installed
- PI System Management Tool is installed
For using the node-red-contrib-osisoft-web-api node on FRED, our cloud-based platform, you will also need to add the node module into your bundle list. You can do that by searching ‘osisoft’ in ‘Add or remove nodes’ from the sidebar.
Setting up your PI Server
Setting up a PI server involves a learning curve and requires a number of steps. The PI System has multiple components integrated to deliver its functionality. You might find this PI System installation order for PI Server 2016 R2 useful in figuring out what you need to install, as well as this video series.
For setting up the demo in this tutorial, you will need to confirm that you have the PI System Explorer and PI System Management Tools installed on your PI System.
You will also need to install the PI Web API server on your PI server. This is an application that simplifies your setup procedures to allow REST requests to access the PI servers and databases. You can find more info in the PI Web API installation documentation, and you should also find this video helpful in configuring the Web API server.
If you are hosting your PI Server on a local server, you will want to generate a self-signed certificate for the Web API server. You will also need to configure your firewall settings to allow access to the server from the FRED cloud service.
If you are hosting the PI Server in a public cloud service such as AWS you can use this trick to avoid re-configuring the Web API server every time you get a new IP address:
- Add your hostname in your hosts file. On Windows Server 2016, it is located at C:\Windows\System32\drivers\etc\hosts. Just simply add the hostname near the end:
2# 127.0.0.1 localhost
EC2AMAZ-xxxxxxx localhost #EC2AMAZ-xxxxxxx is your hostname
- Then, when you configure your Web API server, set the server URL to
- Once you are set, you can just access the Web API server by accessing ‘https://<your-instance-ip>/piwebapi’
Setting up PI system security
In order to access the PI System successfully from your FRED instance, you need to also configure a PI user account with the proper READ/WRITE privileges on your PI System. Keep in mind that, the security configuration on your PI system is configured at different levels. They are:
- Server level,
- Databases level,
- Web API server level,
- PI Points level
Currently, the node-red-contrib-osisoft-web-api node module only works with ‘Basic‘(READ/WRITE) or ‘Anonymous‘(READ ONLY) authentication on your PI server. If you are not familiar with the PI System identities, mapping, and trusts(on some older version PI System), you can take a look at this video series.
For this tutorial we created a Windows user account called “piWebApiUser” in the domain ‘EC2AMAZ-xxxxxxx’. Then, on your PI Server, you need to create a PI Identities or a PI user and map it to your new Windows user account by using the PI System Management Tools. You can find more information on how to map PI identities from the video series.
You will also need to update the Database security for this new PI user account. You can do that by adding your new created PI user to the appropriate PI group or manually add the individual rules in the Database Security section.
Note: You don’t have to follow all the security rules we added in this table. You can modify only the databases that need to be updated, for example, PIPOINT.
Setting up AF servers on your PI System
For this tutorial, lets use FRED to gather weather data and upload the data to the PI System. FRED, although often used to gather and manipulate IIoT data, actually excels at integrating data from a myriad set of sources ranging from physical devices, through third party data sources and websites to social media sources. We will be using darksky as our weather data source. A potential use case would be ‘mashing up’ this weather data building or factory HVAC data to understand energy costs and their correlation to weather.
First, let’s use the point builder tool in the PI System Management Tools to create some PI Points. We first create a “summary” string data point.
Notice how we put down String as the point type.
For demonstration purposes, we will also turn off the compression feature.
Also, make sure that our ‘piWebApiUser’ user account has both READ/WRITE access as it is needed for this demo.
Once you save this point, you should see the status indicating that this PI Point is created.
We also want to create these other PI Points. Notice how the other point types are Float32 type.
Now, let’s go to the PI System explorer to create a new Asset Database named ‘weather’.
We will then head to the Library section in the left sidebar to create a new element template named “weather_template”.
Let’s go ahead to the “Attribute Templates” tab to add the attributes that are related to the PI Points that we created earlier.
We then create a new attribute by clicking the “new Attribute template”, we put down “summary” for the Name field, then String for the value Type. It is also important to select ‘PI Point’ for Data Reference field. We also need to set the correct PI Point reference values by clicking the “Settings” button.
As you can see, We find the correct values to the ‘Data Server’ and the ‘Tag name’ from the drop-down menu of this pop-up PI Point Data Reference window. In our case, since we are also writing to the PI server, we will need to uncheck the “Read only” flag near the bottom.
We also need to add new attributes for the other PI Points that we just created. Beware that we select “Double” as the value type for the other PI Points.
Don’t forget to check in your changes after you finish adding the Element Template.
Then, we can create an element to store incoming data. We go to the element tab, right click on the element icon to create a new element from a template.
Then, we name our new element ‘weather_from_fred’
And you should see the attributes in the Attributes tab:
Now we are ready to move onto FRED!
Setting up on FRED
On FRED, we will simply get the weather data using a Darksky node
And the configuration of the darksky node would be:
As you can see, we set the darksky node to receive a timestamp and check the weather data with the geo-coordinator of Vancouver, Canada. You will also need to enter your darksky developer API token in the credentials section.
Now if you deploy the flow and check the output of the darsky node, you should be able to see the weather data in the output!
Write data to PI
Now we can start writing data to the PI server. We start with dragging a web api write node onto the editor. We will also need a change node to:
- delete the msg.payload object to clear out unnecessary data
- move the current data from msg.data to msg.payload.Value
Inside the change node:
Since we had created the data point for ‘summary’ in the PI server, we can just post the value by path. This is how we set the web-api-write node:
Inside the Web API server configuration, we need to add the URL and the credentials:
Notice that we check ‘Enable secure (SSL/TLS) connection‘, but we unchecked the ‘verify certification‘ field inside the TLS configuration. This is because the OSIsoft Web API uses SSL connection by default.
When you deploy, you will be able to inject values into your PI Server. Normally if the node does not return error messages, then the data should be posted. We will talk about how you can query the values to confirm whether it’s updated or not in the next section, but let’s finish adding the web-api-write nodes for the rest of the PI Points.
Query data from PI
There are two ways to check the data on your PI System:
- Access the Web API server via a browser such as Chrome
- Query Web API server using the web-api-query node in FRED.
For the first method, it is pretty straightforward as you can find tutorials from the OSIsoft learning video series. After you log in to your Web API server, you should see the top level of your Web API server.
Then, you should see the PI Points you created in “DataServers -> Points”, in which the Web API server will return a list of the PI Points.
If you click the “Value” links of each PI Point item, you will be able to see the current values of these points.
And set the configuration:
Again, at this point, we are querying a specific PI Point in the Data Servers. After we trigger the query node, we should see something like this in the output.
In the web-api-query node, we can also choose to query for different types of information we want. For example, we can select “RecordedData” to query for all recorded data for this PI Point in the past.
As you can see, the “query by point paths in Data servers” and “query by Web ID for points in Data servers” features only work for PI Points in the Data servers. If you want to query items in the AF servers, for example, to list out all the Attributes we created in that ‘weather_from_fred’ element (located on the Asset Server), we can first find the element via browser:
and you can see the link for the “Value” item. We just need to copy down the relative link after
and copy it into the web-api-query node in the ‘query by custom URL’ mode:
and you should see the output message contains all the attribute values as you can find in the browser:
The “query by custom URL” mode allows you to query almost all endpoints on your PI Server. So in theory, you don’t even need to use a browser to find relative links and WebIDs!
You can also start your workflow with the query node in the ‘List‘ mode to obtain web-links, webIDs, databases or tags from the top level of your PI server to start your task. By doing this, You will not need to use a browser to manually copy down values, and you can design your workflow programmatically. The currently available ‘List’ features include:
- List all Assert servers: List all the assert servers from your PI Server
- List all DBs in Assert Servers: List all the databases from all assert servers
- List all Data Servers: List all the data servers from the PI Server
- List all points in Data Servers: List all points from all data servers.
Don’t forget that we can use the Node-RED dashboard nodes to generate graphs for our data in no time! You can import the sample flow from our sample code to see how we did that! From the graph below, we can tell that it is a beautiful day in Vancouver!
In this demo, we learned how to rapidly set up a PI System, and use the node-red-contrib-osisoft-web-api node to query and write data into the PI Server via the OSIsoft Web API server. We also see the different modes in querying and writing to the Pi Server where some common requests are built into the nodes for users already. We also see how we can use the query node and node-red-dashboard node to visualize the current values and historical data. If you have encountered any errors, you can refer to the following troubleshooting section for some common issues.
Unauthorized access denied by OSIsoft Web API:
There are multiple possible causes for this error. You can check the following settings:
- Did you set your OSIsoft Web API authentication method to “Basic” or “Anonymous”?
- Did you enter the correct credentials?
- Does your PI User have the proper READ/WRITE privileges?
- Did you set up the correct mapping plans in PI System Management tools?
- Did you set up the correct READ/WRITE privileges at PI Point level? and other security levels?
- If you are writing, did you enable writing access for the PI Point?
- If you are writing, did you set ‘disableWrite’ to false in PI Web API configuration in PI System Explorer?
Cannot find resource/path/element/point
There are multiple possible reasons why you see this error, this means that the path, Web ID or the custom URL you enter is not correct. You can check:
- Is your Web ID valid?
- If you are using path method, is the Data server name and the PI tag name correct? Do they exist in your PI Server? Do you have the right access to this PI Point?
- If you are using custom URL, is the URL correct? Beware that the custom URL should be relative to the base URL, which is “https://<your-pi-server>/piwebapi“, so your custom URL should look like “/points/<some-web-ID>/value” with the “/” at the beginning.
- If you are using path method, beware that the “path” feature only supports PI Points in the data servers. If you are trying to access an element on the AF server, then you should use the custom URL feature as the AF structure could be more complicated.
- Did you connect the query node to a debug node?
You post, but do not see the updated value
You can double check on the following fields:
- Is your Web API server URL correct?
- Do you have WRITE access to that specific PI Point and Database? Remember that you need to set your WRITE permission in:
- Web API server level
- Database level
- PI Point level
- Are you posting to the correct Web ID/path/custom URL? Are you checking the correct Web ID/path/custom URL?
- You might want to double check on your PI Server system configuration, such as your AF server, MySQL database, Web API server etc.
- You can check the logs in your Windows Event Log Viewer, where you will find the WebAPI logs under Applications
Any other questions:
You can start a technical support issue with OSIsoft, or send an email to us at email@example.com.