25 Replies Latest reply on Nov 2, 2012 3:26 PM by spilon

    Need Ideas for my vCampus Windows 8 Presentation!!

    Lonnie Bowling

      Hi Everyone,

       

      I have started on my windows 8 table application for my vCampus Live presentation.  I'm looking for ideas or suggestions on what to include.  Below is a screenshot of what I have.  It is a really simple tag search and charting app, which is pretty boring in my opinion.  I'm using my On-Prim PI Server to Azure to ASP.Net for a data feed, which is working really well, you can't see the speed, but there is almost no lag when a new tag is selected to when the chart is updated.

       

      So, some of the things I was thinking about including is authentication to this app, using Azure claims-based security.  I have not seen that done. But again, that might be pretty boring and maybe a bit too advanced.  I'm targeting devs that have not done any Azure or Windows 8 development.

       

      Some ideas that have been floating around in my head:  Adding data logging, doing notifications, doing AF asset mapping (you have 10 generators with the same template and query and look at a common dashboard).  I would like focus on taking advantage of the mobile nature of a tablet if possible and not just rehash things you find in a typical desktop application.  So please help me out and give me some ideas!!!  If I use your idea, I will be sure and give you credit.

       

      Thanks,

       

       

       

      Lonnie

       

       

       

      5086.Screen-Shot-2012_2D00_10_2D00_11-at-7.19.59-AM.png

        • Re: Need Ideas for my vCampus Windows 8 Presentation!!

          Hey Lonnie.

           

          Braindump...

           

          Use GPS/Location Services to identify position of the mobile user.  Interact with some Azure hosted asset location service (basically obtains GPS coordinates of assets from AF) and display those assets as they come within "range".  We've touched on this in the past...you walk/drive from one plant to the next, as you enter the plant your mobile device pops up "Welcome to Plant A.  Here are the assets available for you".  Click on an asset to get some information, maybe an image of the asset stored in an Attribute as a File data type.  Geo fencing

           

          Then you could follow on the above with allowing the user to tag event frames.  So the mobile user enters the plant, is presented with an asset of interest, physically locates that asset, performs some maintenance (maybe for 1 hour), then they pull out their Windows 8 device and using multi touch mark the start & end time of the maintenance period on the trend of data, which clearly shows the interference in data caused by the maintenance.  After marking the period they select a reason for marking the data (a lookup of Event Frame Templates) and the Event Frame is generated with the asset automatically referenced.

           

          They could even take an image of their handy work and add it to the Event Frame.

           

          When you finish the above you could use the mobile camera to look around the plant and have those assets retrieved earlier marked on the camera's image/view.

           

          Give me a shout if you need some help, you only have a few weeks to finish the above application.

            • Re: Need Ideas for my vCampus Windows 8 Presentation!!
              Asle Frantzen

              Lonnie, do you have NFC on your device?

               

              If so, you should simulate location services using NFC tags placed in different places on the stage. It's difficult to demonstrate this indoors with the little space you have up on stage using GPS, so you should prepare a few NFC tags so that you can walk around and "enter" the different facilities, whether it'd be "Plant A", "Plant B", "Office" or "Home".

               

              Print those words on one sheet each, attach an NFC tag to each of them, and you have the perfect small-scale, demonstration environment.

                • Re: Need Ideas for my vCampus Windows 8 Presentation!!
                  Lonnie Bowling

                  Hi Rhys and Asle,

                   

                  I'm really liking these ideas, thanks for offering them!  I have not purchased the tablet yet and the one I want to get (ThinkPad Tablet 2) has NFC built in and Windows 8 will support it.  I spent a lot of time Sunday looking into the current state of Event Frames and this looks like good timing.  I also played around with location features and it can't be any easier.  So I think I will go with both ideas!  We will have a great tool for our fictitious service or maintenance tech.

                   

                  I could use some help with event frame creation and display, so if you guys have any code or want to do some programming let me know.  I'm planning on sharing the entire project with the community so you would be adding to our body of knowledge here.

                   

                  My first few task are to do the following:

                  • Create an AF demo database
                  • Create an Event Frame downtime template
                  • Write code to generate event frames using the template
                  • Port that code to my Azure PI Service
                  • Write code to search AF Assets based on location
                  • Query event frames and display in a list and on a chart overlay (the query will be through my Azure PI Service)

                  I think the part that is going to take me the longest time is the event frames and maybe some AF searching.  Mostly on the AF SDK side as I'm not really knowledgeable in some areas.  I'm not too concerned about Azure and Windows 8, as it is going pretty fast and I'm stronger in that area.  I have to get a working app finished by the end of the month and I will be doing it on nights and weekends.  So if you want to help (open to any vCampus members) let me know.

                   

                   

                   

                  Thanks,

                   

                   

                   

                  Lonnie

                    • Re: Need Ideas for my vCampus Windows 8 Presentation!!

                      I'm in.  In fact I started an iOS app with MonoTouch.  It will use location services for nearby asset recognition.

                       

                      I can help out with the AF & Event frame stuff on the backend.  For EF generation there is the beta Event Frame generator that you could use.  I feel another hackathon coming on...

                        • Re: Need Ideas for my vCampus Windows 8 Presentation!!

                          Although...I think you should also have the ability to create Event Frames from the tablet device, not just read them.

                            • Re: Need Ideas for my vCampus Windows 8 Presentation!!
                              Lonnie Bowling

                              Cool, I think I will set up a Github project where we can work on the project together.  The event frame is going to be created from the tablet (via the Azure service).  It will be wrapped in the web api call going back to the connector service (where the SDK lives).  Like you outlined above, the user will tag the asset with a downtime reason when they start the work and then when they finish they will close the event.

                                • Re: Need Ideas for my vCampus Windows 8 Presentation!!

                                  Lonnie,

                                   

                                  I was inspired so had a play last night on iOS.  Took me less than 3 hours to create a MonoTouch iPhone that mapped assets based on GPS - although when you simulate the app, the device's location services defaults to San Francisco.

                                   

                                  Anyway, I quickly stored an Asset in AF used SOAP to call a web service to give me assets local to the passed location and voila, I mapped that asset.  Just seen some cool ways to give the mobile user the quickest route (car or walk) from their position to the asset, but I'll save that one for later.  

                                   

                                  scanoverride.jpg_2D00_480x320.jpg

                                   

                                  What I will be able to do (later tonight) is be able to pull up an Asset, list all Attributes that use the PI Point Data Reference where data is coming from an interface (marked by Categories), and then be able to switch a PI Point to scan off & enter a temporary value, like a digital error state of "maintenance".  When finished turn it back to scan on and wait for the data to show up again.  There will be a trend for the data point so you have visual confirmation the switch back to scan on worked.  Should also  have time to shoehorn in Event Frame generation too for the period of scan off.

                                   

                                  Just looking at custom pins on the Apple mapping control so I can show different icons where an asset is undergoing maintenance and a count of how many PI Points have been switched off temporarily for that asset.  Also, how long they have been switched off (info from the Event Frame) just in case some maintenance engineer is taking longer than they should be.

                                   

                                  I'm hooked, thanks for that, now I have no free time.  I'll blog the complete solution when it is finished.

                                   

                                  (By the way, thanks for the TeeChart pointer in your blog.  Works great with MonoTouch.)

                                   

                                  Just seen prices released for the Microsoft Surface...once I have one of those I'll start on Win8 dev.

                                   

                                   

                                    • Re: Need Ideas for my vCampus Windows 8 Presentation!!
                                      Lonnie Bowling

                                      @Rhys  That is pretty awesome!!  I worked on learning event frames last night so my progress was not nearly as good.  I want to extend EventFrames to the Web API service as a first goal.  Creating them and searching from them are going to be required. I also need to figure out a simple way to search for assets.  How are you handling the location data in AF?  Are you accessing the PI system via PI web services then?  And doing WCF/SOAP calls from iOS?

                                        • Re: Need Ideas for my vCampus Windows 8 Presentation!!

                                          I quickly wrote my own couple of web services because I wanted to specific search logic to be in the Web Service and not on the device.  

                                           

                                          Searching for Assets is actually quite straightforward for the basic setup I had.  For the example I have an Element Template "GPS Asset" with an Attribute Template "GPS Coordinates", which has 2 child attribute templates of "Latitude" and "Longitude".  The GPS Coordinates attribute also acts as a flag to indicate if the GPS Coordinates are available for the asset.  

                                           

                                          At this point I have the GPS coordinates of my device, and AF has all my assets with GPS coordinates.  I only want those within a certain radius.  I decided to use the Haversine formula to calculate the distance between a pair of GPS coordinates.  

                                           

                                          Which looks like this:

                                           

                                           

                                           
                                          private double _eQuatorialEarthRadius = 6378.1370D;
                                                  private double _d2r = (Math.PI / 180D);
                                          
                                                  private int HaversineInM(double lat1, double long1, double lat2, double long2)
                                                  {
                                                      return (int)(1000D * HaversineInKM(lat1, long1, lat2, long2));
                                                  }
                                          
                                                  private double HaversineInKM(double lat1, double long1, double lat2, double long2)
                                                  {
                                                      double dlong = (long2 - long1) * _d2r;
                                                      double dlat = (lat2 - lat1) * _d2r;
                                                      double a = Math.Pow(Math.Sin(dlat / 2D), 2D) + Math.Cos(lat1 * _d2r) * Math.Cos(lat2 * _d2r) * Math.Pow(Math.Sin(dlong / 2D), 2D);
                                                      double c = 2D * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1D - a));
                                                      double d = _eQuatorialEarthRadius * c;
                                          
                                                      return d;
                                                  }
                                          

                                           

                                           

                                           

                                           

                                           

                                           

                                          Then I just needed to search AF for assets and then filter.  I could have done this another way by using the AFAttributeValueQuery parameter to filter on the value of the lat & long but decided not to for now, or maybe I will just have an option for both in the end.

                                           

                                          Then it is as easy as PI (haha, see what I did there...)

                                           

                                           

                                           
                                          private class AssetCoord
                                                  {
                                                      public string name { get; set; }
                                                      public double longitude { get; set; }
                                                      public double latitude { get; set; }
                                                  }
                                          
                                          ...
                                          
                                          PISystem af = new PISystems()["myPISystem"];
                                                      if (!af.ConnectionInfo.IsConnected) af.Connect();
                                          
                                                      AFDatabase db = af.Databases["GPSAssetsDB"];
                                          
                                                      AFAttributeValueQuery[] GPSIsSet = new AFAttributeValueQuery[1];
                                                      GPSIsSet[0].AttributeValue = 1;
                                                      GPSIsSet[0].AttributeTemplate = db.ElementTemplates["GPS Asset"].AttributeTemplates["GPS Coordinates"];
                                                      GPSIsSet[0].Operator = OSIsoft.AF.Search.AFSearchOperator.Equal;
                                          
                                                      var AssetsFound = AFElement.FindElementsByAttribute(db.Elements["Assets"], "*", GPSIsSet, true, AFSortField.Name, AFSortOrder.Ascending, 10000);
                                                      var AssetsCoords = (from eachAsset in AssetsFound select new AssetCoord() { name = eachAsset.Name, longitude = (double)eachAsset.Attributes["GPS Coordinates"].Attributes["Longitude"].GetValue().Value, latitude = (double)eachAsset.Attributes["GPS Coordinates"].Attributes["Latitude"].GetValue().Value });
                                          
                                                      double radiusInKM = 10.0;
                                                      var assetWithinRadius = from eachAsset in AssetsCoords
                                                                              where (HaversineInKM(10, 10, eachAsset.latitude, eachAsset.longitude) <= radiusInKM)
                                                                              select eachAsset;
                                          
                                                      foreach (AssetCoord assetCoord in assetWithinRadius)
                                                      {
                                                          // Do something here...
                                                      }
                                          

                                           

                                           

                                           

                                           

                                           

                                            • Re: Need Ideas for my vCampus Windows 8 Presentation!!

                                              Rhys @ Wipro

                                              I quickly wrote my own couple of web services
                                              I can't help it, every time I read something like this it makes me cringe: that means you did not have what you needed readily available from one of our products, and you had to write your own stuff. The good news here, is that this AF Search functionality is coming up in PI Web Services 2012. Granted, it is currently only available as a CTP and you couldn't use it today in a Production environment... but I was wondering if you had a try (or would be willing to try) the PI Web Services 2012 CTP, to validate whether it addresses your needs.

                                               

                                              If you do so, keep in mind this is a CTP and parts of it will have changed by the time it releases; the functionality you'll exercise will still be there, but some of the wrapping around it (i.e. the user experience, the method and objects signatures) will have changed, and new functionality will have been added.

                                               

                                              Cheers!

                                                • Re: Need Ideas for my vCampus Windows 8 Presentation!!

                                                  Steve,  I was being lazy in writing my own code.  Sounds strange that writing code is lazy but I guess I could get a proof of concept up and running quicker that way.  About 30 seconds ago I clicked on download for the PI WS 2012 CTP  Will let you know how it goes.

                                                    • Re: Need Ideas for my vCampus Windows 8 Presentation!!
                                                      Lonnie Bowling

                                                      Hi Rhys,

                                                       

                                                      I'm trying to get your code to work but I'm not getting any results back from the attribute query.  I am not seeing what I am doing wrong, could you take a quic look?

                                                       

                                                      Here is the code:

                                                       

                                                       

                                                       
                                                                  PISystem af = new PISystems()["eng-dev03"];
                                                                  if (!af.ConnectionInfo.IsConnected) af.Connect();
                                                      
                                                                  AFDatabase db = af.Databases["AFTest"];
                                                      
                                                                  AFAttributeValueQuery[] GPSIsSet = new AFAttributeValueQuery[1];
                                                                  GPSIsSet[0].AttributeValue = 1;
                                                                  GPSIsSet[0].AttributeTemplate = db.ElementTemplates["Tank"].AttributeTemplates["GPS Coordinates"];
                                                                  GPSIsSet[0].Operator = OSIsoft.AF.Search.AFSearchOperator.Equal;
                                                      
                                                                  var AssetsFound = AFElement.FindElementsByAttribute(null, "*",  GPSIsSet, true, AFSortField.Name, AFSortOrder.Ascending, 10000);
                                                      

                                                       

                                                       

                                                      Here is what my AF Template and Assets look like:

                                                       

                                                      3225.10_2D00_18_2D00_2012-9_2D00_14_2D00_02-PM.png

                                                       

                                                      And here is my template:

                                                       

                                                      3833.10_2D00_18_2D00_2012-9_2D00_16_2D00_43-PM.png

                                                       

                                                      @ Steve: I looked at PI Web Services CTP documentation and it looks like it does not support attribute template searching at this point.  It looks like with the way that Rhys is approaching this is to look for any asset that has a GPS attribute regardless of where the parent element is located on the tree.

                                                        • Re: Need Ideas for my vCampus Windows 8 Presentation!!

                                                          Lonnie, your "GPS Coordinates" Attribute itself needs a value of 1, or 0 for invalid/no latitude & longitude.  Having a value here is a good way to flag Assets with a valid GPS coordinate if for example your GPS coordinates are coming from an external system.  You may want to have a formula at the GPS Coordinates level that checks the Latitude and Longitude for validity.  It will restrict the checking of coordinates from occurring on the mobile device and minimise data exchange with AF.

                                                          • Re: Need Ideas for my vCampus Windows 8 Presentation!!

                                                            Lonnie Bowling

                                                            @ Steve: I looked at PI Web Services CTP documentation and it looks like it does not support attribute template searching at this point.  It looks like with the way that Rhys is approaching this is to look for any asset that has a GPS attribute regardless of where the parent element is located on the tree.
                                                            In fact you could search for Elements based on the "GPS Asset" template, and then loop through the Attributes. This is supported in the CTP. Direct Attribute searching will be supported in the Released version.

                                                              • Re: Need Ideas for my vCampus Windows 8 Presentation!!
                                                                Lonnie Bowling

                                                                OK, that was it, thanks for the help Rhys and clarification!  I'm going to port this to the Azure PI service this weekend and get the UI functionality working.  I'm also hoping to get to generating event frames.  Not only is this going to be great for the presentation, but I learned about attribute templates, something I never really consider using before, I like them!

                                                                 

                                                                @Steve, I'm not going to be basing my asset organization on having GPS functionally or not, my base elements area going to be regions.  GPS is just an attribute that an asset may or my not have.  So I don't think searching based on element template is not going to help for this particular situation.

                                                                  • Re: Need Ideas for my vCampus Windows 8 Presentation!!
                                                                    pcombellick

                                                                    To improve search performance, consider setting IsIndexed = true on the AttributeTemplates that are frequently searched via AFElement.FindElementsByAttribute().   To find assets via GPS coordinates, you can specify a bounding "rectangle" in the argument list for this search.

                                                                      • Re: Need Ideas for my vCampus Windows 8 Presentation!!
                                                                        Lonnie Bowling

                                                                        Hi Paul,

                                                                         

                                                                        Thanks for the tip.  I have checked the box.  I'm not quite following you on the bounding rectangle, could you give me a bit more detail?

                                                                         

                                                                        Thanks,

                                                                         

                                                                        Lonnie

                                                                          • Re: Need Ideas for my vCampus Windows 8 Presentation!!

                                                                            Lonnie, assume here Paul is referring to passing an array of AFAttributeValueQuery that essentially draws a rectangle of GPS coordinates from your given location when searching the Attribute Templates Longitude and Latitude.

                                                                             

                                                                            Your web service needs to know your GPS + asset radius search; you could use the radius to find assets within a rectangular boundary direct from AF instead of returning all GPS assets & filtering on a spherical boundary.

                                                                              • Re: Need Ideas for my vCampus Windows 8 Presentation!!
                                                                                Lonnie Bowling

                                                                                @Rhys I will have to work on this when I get a bit more time.  I'm not really clear on how to use the AFAttributeValueQuery effectively.  I was trying to set up an array this weekend without success. (searching two different element templates with GPS attributes).  I will post the code at some point, when I can get back to it.

                                                                                 

                                                                                The good news is that I was able to get the basic query wrapped and delivered via the Azure ASP.Net Web API.  I spent quite a bit of time learning more about Web API, it is really powerful and has some very nice "auto building" of rest calls.   Here is the URI I created, give it a try, my server is up and running.  The radius is in km.

                                                                                 

                                                                                giant.cloudapp.net/.../assets

                                                                                 

                                                                                One note, I got my longitude and latitude swapped, need to fix that!

                                                                                 

                                                                                Here are a couple of screen shots, the red dots are assets, the black circle is my location.

                                                                                 

                                                                                 

                                                                                 

                                                                                This is in Florida, near Orlando (out in the country):

                                                                                 

                                                                                8463.screenshot_5F00_10222012_5F00_064511.png

                                                                                 

                                                                                This is in California, in Napa where I live:

                                                                                 

                                                                                3343.screenshot_5F00_10222012_5F00_065106.png

                                                                                 

                                                                                Based on my progress, I don't think I'm going to have time to go any further with adding EF and NFS.  I need to get  the app looking more finished then onto drafting the presentation.  If I have more time later next month, I might try to squeeze in a surprise, we will see.   I have to say, that doing this really brings home the value of location.  I can see how much easier it is for someone to locate the right asset when they are spread out.

                                                                                 

                                                                                 

                                                                                 

                                                                                Lonnie

                                                                                  • Re: Need Ideas for my vCampus Windows 8 Presentation!!

                                                                                    Nice...really is cool to have location services as part of an application, especially for users on the move.  I'm going to show a map trail next for how to get from asset A to asset B, and store that suggestion & the actual journey taken as event frames.  Make sure the user doesn't take an hours detour to the local coffee shop

                                                                                     

                                                                                    Imagine if you have something like hailocab backed by a PI System.  Kind of gets me thinking about the vCampus day 0 hackathon

                                                                                     

                                                                                    If you want me to add some additional functionality to your Web API whilst you finish off the GUI then give me a shout.  You could then add to the GUI as you get time.  We should probably roll these efforts in to a community project eventually??

                                                                                      • Re: Need Ideas for my vCampus Windows 8 Presentation!!
                                                                                        Lonnie Bowling

                                                                                        All right Rhys! I can't turn down the chance to collaborate on a project with you.  I have created a git repository on GitHub that is public.  Which means anyone can pull the source code and use it freely in accordance with the open source licensing.  Anyone is also able to submit changes that can be reviewed and incorporated into the project.  Also, for those that want to contribute regularly to the project can let me know and I can add you to the list of contributors, which means you can add features, fix bugs, and just be a great coder for a cause.  If you have never used Git, this is a great chance to see what is it about.  It allows us to develop without messing each other up and breaking the project and at the same time to share with others.

                                                                                         

                                                                                        Here is the link.  I was able to pull the code and compile without any issues, but I think that might not be a good test, as my system has everything required to start.  At a minimum I think that you will need the following:

                                                                                        • Windows Azure SDK (latest available)
                                                                                        • AF SDK 2.4 (2012 beta 3)
                                                                                        • ASP.Net MVC 4
                                                                                        • PI SDK (latest release)

                                                                                        I will also post this in the repository where we can added additional installation instructions.

                                                                                         

                                                                                        Lonnie

                                                                                         

                                                                                         

                                                                                         

                                                                                        Almost forgot, here is the link:

                                                                                         

                                                                                        saltyPI