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
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
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.
No comments yet
Be the first to share your thoughts on this article.
Related Articles
Developing Expertise in PI System and Related Technologies: A Comprehensive Training Roadmap
This blog outlines a comprehensive training roadmap for developing expertise in the PI System and related technologies. Structured over four weeks, the program covers essential technologies like the PI System, Asset Framework, and various APIs, providing a strong foundation for data management and analytics.
Roshan Soni
Traversing an AF Database Hierarchy to Count All Elements Using OSIsoft AF SDK
Learn how to use the OSIsoft AF SDK in C# to traverse an AF database and count all elements within its hierarchy. This blog post provides a comprehensive guide with code examples for connecting, traversing, and counting AF elements.
Roshan Soni
A Beginner's Guide to Learning the OSIsoft PI System
Unlock the power of real-time data management and analytics with OSIsoft PI System. This beginner's guide provides a structured learning path and key resources to help you effectively learn the PI System.
Roshan Soni