13 Replies Latest reply on Nov 12, 2015 11:27 AM by QasimGulzar

    Need to know more about using PI web api

    Flutura

      Hello everyone,

       

      In one of my previous posts in a different thread, someone had suggested me to use Rest api for my use case.

       

      So I am basically trying to simulate like a hundred random points sending data to the pi server which in turn should connect to this RESTful API from where data could be sent forward to my existing data pipeline in a format like JSON or similar.

       

      I am really new to PI and needed little clarity as to what way shall I approach this problem. Do I need to use the SDK tool to connect PI server to the REST API?

       

      My understanding is that I should be using ICU's "Random" interface to generate random 100 points, which would send data to the server. From there, I shall be connecting my REST API to fetch data and pass it in JSON format forward.

       

      Please correct me if I am wrong. Also, it would be great if anyone could share some example of this kind of implementation.

        • Re: Need to know more about using PI web api
          Marcos Vainer Loeff

          Hello Yogini,

           

          As I said on other posts, PI Web API is a RESTful web service on top of the PI System. This works the same way that all RESTful web services works. Hence, if you are not familiar with this type of web service, Google would be the best place for you to start learning.

           

          Once you have learning the basic concepts of RESTful web services, please download and install PI Web API beta. After PI Web API service is up and running, you will have access to the online help (whose address should be: https://webservername/piwebapi/help). It describes all the methods available for you.

           

          If you want to test if PI Web API is working, you can access a similar link like: https://marc-web-sql/piwebapi.

           

          You are supposed to receive an JSON answer like:

           
          {
          
            "Links": {
              "Self": "https://marc-web-sql/piwebapi/",
              "Asset Servers": "https://marc-web-sql/piwebapi/assetservers",
              "Data Servers": "https://marc-web-sql/piwebapi/dataservers",
              "Configuration": "https://marc-web-sql/piwebapi/configuration",
              "Version": "https://marc-web-sql/piwebapi/version"
            },
            "HtmlHelp": "https://marc-web-sql/piwebapi/help"
          }
          

          Hope it helps!

            • Re: Need to know more about using PI web api
              Flutura

              Hello,

               

              Is there some way where I can programatically fetch data from this REST api. I am trying to access it from a JAVA code with the NuGreen example.

               

              Any sample code would be of great help.

               

              Regards,

               

              Yogini

                • Re: Need to know more about using PI web api

                  Hello Yogini,

                   

                  Please have a look at Brad's blog post about PI Web API: Javascript Client.

                    • Re: Need to know more about using PI web api
                      Marcos Vainer Loeff

                      Hello Yonigi,

                       

                      Actually, we don't have an example using PI Web API with Java. But if you search for an example of a RESTful Java Client on the internet, I am sure you will find many examples. One of them would be this one.

                       

                      I recommend you to use the Apache libraries as well as JSON. You only need to reference those two types of libraries in order to make your Java client application work properly with PI Web API.

                       

                      Hope it helps!

                        • Re: Need to know more about using PI web api
                          Flutura

                          Hello folks,

                           

                          I have been able to get data in JSON format using the RESTful services. So far so good. Thanks for your help. One thing, though, is bothering me. I am developing this data pipeline for a system where the input will be from EMeters which might be sending values to the PI server with the frequency in milliseconds. I am worried if my "RESTful API to Java connection" would turn out to be a bottleneck for such a high frequency.

                           

                          Any experiences?

                           

                          Yogini, Flutura Solutions.

                            • Re: Need to know more about using PI web api
                              Marcos Vainer Loeff

                              Hello Yogini,

                               

                              According to the developer of the product, PI Web API isn’t built for this scenario yet, because we only support writing a single value at a time.

                               

                              Adding the ability to write multiple values at a time is in the plan for the next release. Once this feature is available, the client application will be able to buffer values and send them in batches at a more reasonable frequency.

                               

                              Hope it helps!

                                • Re: Need to know more about using PI web api
                                  Flutura

                                  Hello Marcos,

                                   

                                  Sorry, but I am not clear about what you mean by "a single value at a time". I am not looking for writing multiple values at a time. Suppose, I have a java code which is making calls to the Web API, do you think I would face issues if I am trying to fetch data at a very high frequency?

                                   

                                  As of now, I am able to get all the "recorded data" values, from the NuGreen example, using the Web API in one go. And I didn't face any issues. But, if the data is a continuous stream, would it not be possible?

                                    • Re: Need to know more about using PI web api
                                      mbrowning

                                      Hi Yogini,

                                       

                                      It sounded from your previous post like you were interested in writing values to PI with high frequency via the Web API. Marcos's reply addresses that situation.

                                       

                                      If you have some other process that is writing values to PI with high frequency and are only using the PI Web API to read those values, the situation is different. My first suggestion is to consider whether you really need to read with the same frequency that you're writing. For example, if the values are being read for use in a display, even if they're being written every millisecond, it may be acceptable to read them every few seconds.

                                       

                                      If you do need to make reads with very high frequency, then you will hit a limit when your application is adding requests to the PI Web API's queue faster than it can respond to them. In this case, the queue will grow until the server refuses to accept additional requests. Where this limit lies depends on several factors, including the complexity of the requests you're making, the latency between the Web API server and the AF and PI servers, and the specs of your server machines, and can only reliably be determined by profiling in your own environment. If you hit this limit with a single Web API server, you might explore scaling horizontally by using multiple Web API servers and load balancing between them.

                        • Re: Need to know more about using PI web api
                          QasimGulzar

                          Hey,

                          I am trying to to write a REST client for PI WEB SDK i am facing problem while authentication , my authentication type is basic. can any one guide me in this regard.