10 Replies Latest reply on Jan 30, 2018 12:29 AM by jyi

    PI json interface

    qgc

      Hello all

       

      I have a php web service that returns json as follows.

       
      {"time":1382509126,"temp0":29.25,"temp1":29.312}

      Ignore the time (unix time) as it is the time the php script is executed.

       

      I wish to historise the temp0 and temp1 values in two PI tags.

       

      I have wrapped the php up in some html, and used the PI HTML interface to get the data into PI tags.

       

      But this got me thinking, how can I get the data directly from the json web service.

       

      Any ideas?

       

       

       

      Thanks

       

      Cheers MG

        • Re: PI json interface
          Marcos Vainer Loeff

          Hello Mark,

           

          You can develop your own console application which should behave like an interface.

           

          This console application developed is Visual Studio receives the reponse (a string) from the web service and using JSON.NET, you can deserialize and convert it to a C# object.

           

          Then, you just need to you PI AF SDK in order to send the values to your PI System.

           

          Hope this helps!

            • Re: PI json interface
              qgc

              Thanks Marcos

               

              Yes, that is an option - but I was curious if there is a way without having to develop anything.

               

              The html wrapper is very simple, and I have access to the server where the original php script executes, I think that is the easiest solution.

               

              Since there are other consumers of the php/json I need to leave it in that format.

               

              Are there any other options?

               

              Cheers MG

                • Re: PI json interface
                  Lonnie Bowling

                  Have you looked at PI Webservices? I'm not sure if it can write data, but I think they are going to a rest type based api where you could have JSON data exchanged. There is also an ODATA webservice that is very close to preview that might be interesting, this is a good use case for needing write capabilities. At least that way you could get rid of the HTML interface and not have dependency on the SDK and C#. It might be a bit early for what you really want, but OSIsoft seems to be listening.

                   

                  Lonnie

                    • Re: PI json interface
                      xwang

                      Hi Mark,

                       

                      As Lonnie mentioned, PI Web Services has one function called "InsertPIData".  This could be used to insert or replace data into PI point.  You could find the detail explanation on PI Web Services user Guide from page 77.  However, I am not sure if it could be sued in JSON.  You could try.

                       

                      Xi Wang

                       

                      v-Campus team

                        • Re: PI json interface
                          Marcos Vainer Loeff

                          Hello Mark,

                           

                          Another way is to try to export the JSON response to a text file and use the PI UFL interface to send data to two PI Points from your PI Server. I am not sure if this works, but probably yes.

                           

                          However, I personally prefer to the solution using JSON.NET/PI Web Services, as the code involved is quite simple.

                  • Re: PI json interface
                    MaxStrueverWipro

                    Hi All,

                    Just curious, is there any more direct way to consume a web API outputting JSON data as an interface to a PI system?

                    Between this post and this other one I found Get public JSON data into PI using the PI Connector for UFL it seems we still need to have a custom script intermediary.

                    Is it possible now, for example, the PI HTML interface to handle JSON data? Or any other simpler way to do this?