Skip to main content
PI System
Troubleshooting
VBA
PI Web API

Reading PI Points Values with PI Web API and VBA

Learn how to efficiently access PI System data using PI Web API with VBA by understanding common troubleshooting techniques for connection issues.

Roshan Soni

4 min read

Reading PI Points Values with PI Web API and VBA

In the world of industrial data systems, OSIsoft PI is a powerful tool for real-time data management. However, interacting with the PI System programmatically can sometimes be challenging, especially when integrating with other tools like Excel via VBA (Visual Basic for Applications). One common method to achieve this integration is through the PI Web API. By leveraging this API, users can query and manipulate PI System data over HTTP, tapping into a broad range of functionalities.

Troubleshooting Common Errors

One error that users might encounter when using the PI Web API with VBA is a timeout error, specifically a "Request Timeout" accompanied by a message indicating that the server name or address could not be resolved. This typically happens due to issues with the URL being used to access the API.

A frequent mistake arises from incorrectly formatted URLs, as seen in an example where a user confronted a persistent request timeout error because they inadvertently used a malformed URL like https://https://esc0tafs01/piwebapi/assetservers. This issue stemmed from duplicating the scheme part of the URL (https://). Such errors will prevent the client from reaching the server, and consequently, the request times out without establishing a connection.

Resolving the Issue

To resolve this, ensure that the URL used in your GET request is properly formatted. You should have a singular https:// prefix, followed directly by the server address, as shown below:

GET https://esc0tafs01/piwebapi/assetservers

Once this adjustment is made, the client application (whether it be a browser or VBA in this case) should successfully communicate with the PI Web API. After correcting the URL, the user in the example was able to receive an HTTP 200 response, indicating a successful request.

Embracing the PI Web API with VBA

For those delving into using the PI Web API with VBA, it's essential to familiarize oneself with the basics of HTTP requests and responses. Understanding how HTTP status codes work, for instance, can greatly assist in troubleshooting issues. An HTTP 200 status means a successful call, while response codes like 404 or 408 indicate different issues such as "Not Found" or "Request Timeout", respectively.

Furthermore, when setting up your VBA environment to interact with the PI Web API, ensure you are using a robust HTTP library. In the example, 'VBA-Web v4.1.6', a popular choice for making HTTP requests via VBA, was employed. This library enables the simplicity of structuring requests and parsing responses, thereby accelerating the development process.

Conclusion

While working with the PI Web API in VBA can initially seem daunting, addressing minor errors in formatting or setup can significantly streamline the data retrieval process. With these tools and tips, you'll be better equipped to harness PI System data into Excel for further analysis, thereby unleashing the full potential of your PI environment. Always ensure correct URL syntax and consider using comprehensive documentation and community forums when troubleshooting unusual errors. Happy coding!

By sharing experiences and solutions through forums and blog posts, we can collectively improve our workflows and learn from one another’s experiences. Share your tips or queries in the comments!

Tags

#OSIsoft PI
#Data Integration
#PI Web API
#VBA
#HTTP errors

About Roshan Soni

Expert in PI System implementation, industrial automation, and data management. Passionate about helping organizations maximize the value of their process data through innovative solutions and best practices.

Sign in to comment

Join the conversation by signing in to your account.

Comments (0)

No comments yet

Be the first to share your thoughts on this article.

Related Articles

Enhancing PI ProcessBook Trends with Banding and Zones: User Needs, Workarounds, and the Road Ahead

A look at the user demand for trend banding/zoning in OSIsoft PI ProcessBook, current VBA workarounds, UI challenges, and how future PI Vision releases aim to address these visualization needs.

Roshan Soni

Migrating PIAdvCalcFilVal Uptime Calculations from PI DataLink to PI OLEDB

Learn how to translate PI DataLink's PIAdvCalcFilVal advanced calculations—like counting uptime based on conditions—into efficient PI OLEDB SQL queries. Explore three practical approaches using PIAVG, PIINTERP, and PICOunt tables, and get tips for validation and accuracy.

Roshan Soni

Understanding PI Web API WebID Encoding: Can You Generate WebIDs Client-Side?

Curious about how PI Web API generates WebIDs and whether you can encode them client-side using GUIDs or paths? This article explores the encoding mechanisms, current documentation, and best practices for handling WebIDs in your applications.

Roshan Soni