Developing Windows 8 Mobile Apps for the PI System - OSIsoft
Developing Windows 8 Mobile Apps for the PI System - OSIsoft
Developing Windows 8 Mobile Apps for the PI System - OSIsoft
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Developing</strong> <strong>Windows</strong> 8 <strong>Mobile</strong><br />
<strong>Apps</strong> <strong>for</strong> <strong>the</strong> <strong>PI</strong> <strong>System</strong><br />
Presented by<br />
Lonnie A. Bowling, DST Controls<br />
© Copyri g h t 2012 OSIso f t , LLC.
© C opyri g h t 2012 OSIso f t , LLC. 2
Introduction<br />
Objectives<br />
• Extend a <strong>PI</strong> <strong>System</strong> to Azure<br />
• Create a REST type Service<br />
• Create <strong>Windows</strong> 8 Store App <strong>for</strong> a Tablet<br />
• Getting motivated to start writing your own<br />
applications<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
3
<strong>System</strong> Architecture<br />
<strong>PI</strong> <strong>System</strong><br />
On-Premise<br />
Server<br />
Connect<br />
Service<br />
Service<br />
Bus<br />
Azure<br />
Cloud<br />
Service<br />
REST Service (HTTP)<br />
© C opyri g h t 2012 OSIso f t , LLC. 4
<strong>Mobile</strong> += Cloud<br />
• Want a HTTP REST service<br />
• Cross-Plat<strong>for</strong>m capabilities<br />
• Keep our <strong>PI</strong> <strong>System</strong> secure<br />
• Remove client-server dependencies<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
5
On Premise Server<br />
<strong>PI</strong> <strong>System</strong><br />
On-Premise<br />
Server<br />
Connect<br />
Service<br />
Service<br />
Bus<br />
Azure<br />
Cloud<br />
Service<br />
REST Service (HTTP)<br />
© C opyri g h t 2012 OSIso f t , LLC. 6
Connector Service Steps<br />
• Get an Azure account, install SDK<br />
• Create <strong>PI</strong> AF Templates and Assets<br />
• Create a service using WCF and <strong>the</strong> <strong>PI</strong> AF<br />
SDK<br />
• Connect service to an Azure service bus<br />
• See my vCampus Blog <strong>for</strong> more details<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
7
Location <strong>PI</strong> AF Template<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
8
<strong>PI</strong> AF GPS Attribute<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
9
Code… <strong>PI</strong>Service Interface<br />
[ServiceContract(Namespace="<strong>PI</strong>Service")]<br />
interface I<strong>PI</strong>Service<br />
{<br />
[OperationContract]<br />
List GetPlotValues(string Tag, DateTime StartTime,<br />
DateTime EndTime, int Interval);<br />
[OperationContract]<br />
List GetAssetsByLocation(double Latitude,<br />
double Longitude, double Radius);<br />
.<br />
.<br />
.<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
10
Code… <strong>PI</strong>Service Implementation<br />
<strong>PI</strong>Values PVS = Srv.<strong>PI</strong>Points[Tag].Data.PlotValues(StartTime,<br />
EndTime, Interval);<br />
List PlotValues = new List();<br />
<strong>for</strong>each (<strong>PI</strong>SDK.<strong>PI</strong>Value pp in PVS)<br />
{<br />
if (pp.IsGood())<br />
{<br />
<strong>PI</strong>Value oValue = new <strong>PI</strong>Value();<br />
oValue.Value = pp.Value;<br />
oValue.TimeStamp = pp.TimeStamp.LocalDate.ToUniversalTime();<br />
PlotValues.Add(oValue);<br />
}<br />
}<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
11
Code… <strong>PI</strong>Service Implementation<br />
AFAttributeValueQuery[] GPSIsSet = new AFAttributeValueQuery[1];<br />
GPSIsSet[0].AttributeValue = 1;<br />
GPSIsSet[0].AttributeTemplate = db.ElementTemplates["Tank"]<br />
.AttributeTemplates["GPS Coordinates"];<br />
GPSIsSet[0].Operator = <strong>OSIsoft</strong>.AF.Search.AFSearchOperator.Equal;<br />
var AssetsFound = AFElement.FindElementsByAttribute(null, "*",<br />
GPSIsSet, true,<br />
AFSortField.Name,<br />
AFSortOrder.Ascending, 10000);<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
12
Code… connecting to a service bus<br />
ServiceHost sh = new ServiceHost(typeof(<strong>PI</strong>Service));<br />
sh.AddServiceEndpoint(<br />
typeof(I<strong>PI</strong>Service), new NetTcpRelayBinding(),<br />
ServiceBusEnvironment.CreateServiceUri("sb", "<strong>PI</strong>Spark", "service"))<br />
.Behaviors.Add(new TransportClientEndpointBehavior<br />
{<br />
TokenProvider = TokenProvider.CreateSharedSecretTokenProvider<br />
("owner", "Pz4nCcvg4obB9TSNL…")<br />
});<br />
sh.Open();<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
13
Azure Cloud Service<br />
<strong>PI</strong> <strong>System</strong><br />
On-Premise<br />
Server<br />
Connect<br />
Service<br />
Service<br />
Bus<br />
Azure<br />
Cloud<br />
Service<br />
REST Service (HTTP)<br />
© C opyri g h t 2012 OSIso f t , LLC. 14
Azure as a cloud plat<strong>for</strong>m<br />
Plat<strong>for</strong>m <strong>for</strong> developing cloud based solutions<br />
– Web and Worker Roles<br />
– Services Buses<br />
– Access Control (ACS)<br />
– Blob Storage and Table Space<br />
– SQL Database<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
15
Cloud Service Steps<br />
• Create an Azure Cloud Service Project<br />
• Connect to our Service Bus<br />
• Use ASP.Net Web A<strong>PI</strong> <strong>for</strong> REST calls<br />
• Deploy to Azure!<br />
• (see my vCampus Blog <strong>for</strong> details)<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
16
© C opyri g h t 2012 OSIso f t , LLC. 17
<strong>Windows</strong> Store <strong>Apps</strong><br />
<strong>PI</strong> <strong>System</strong><br />
On-Premise<br />
Server<br />
Connect<br />
Service<br />
Service<br />
Bus<br />
Azure<br />
Cloud<br />
Service<br />
REST Service (HTTP)<br />
© C opyri g h t 2012 OSIso f t , LLC. 18
Programming <strong>Windows</strong> 8<br />
• You can build off of what you know<br />
– XAML (WPF, Silverlight, <strong>Windows</strong> Phone)<br />
– C# (<strong>the</strong> worlds greatest programming lang)<br />
– Javascript/HTML, even C++<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
19
What is a <strong>Windows</strong> Store App?<br />
• Designed <strong>for</strong> <strong>the</strong> “Metro” side<br />
• Aimed at tablet and o<strong>the</strong>r touch UI<br />
devices<br />
• Can be side-loaded or delivered via <strong>the</strong><br />
Store<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
20
What our App will do:<br />
• Use our Web A<strong>PI</strong> REST service<br />
• Get assets by location<br />
• Show assets on a map<br />
• Show a trend <strong>for</strong> a given asset value<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
21
© C opyri g h t 2012 OSIso f t , LLC. 22
Review<br />
• Create a connector service<br />
– WCF, <strong>PI</strong> <strong>System</strong> SDKs, Azure Service Bus<br />
• Deployed a ASP.Net Web A<strong>PI</strong> service<br />
– Web Role, RESTful Service<br />
• Created a <strong>Windows</strong> 8 Tablet<br />
– Location based search and trending<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
23
Let <strong>OSIsoft</strong> know our needs…<br />
• This REST service is not production Ready<br />
– Lacks security<br />
– Is not versatile<br />
• <strong>OSIsoft</strong> and OData solution in <strong>the</strong> works<br />
• Helpful to provide feedback<br />
• See Steve Pilon’s OData lab, tomorrow<br />
10am<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
24
What next?<br />
• Data logging<br />
• Event Frames<br />
• Near Field Communications<br />
• Give feedback to <strong>OSIsoft</strong><br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
25
Lonnie A. Bowling<br />
Software Developer<br />
DST Controls, Benicia Cali<strong>for</strong>nia<br />
lbowling@dstcontrols.com<br />
Twitter: lonniebowling<br />
Blog: vCampus, lonniebgood.com<br />
© C opyri g h t 2012 OSIso f t , LLC.<br />
26
THANK YOU<br />
© Copyri g h t 2012 OSIso f t , LLC.
THANK YOU<br />
© Copyri g h t 2012 OSIso f t , LLC.
THANK YOU<br />
© Copyri g h t 2012 OSIso f t , LLC.