coding for ocs - osisoft · 2018. 4. 30. · #osisoftuc #piworld ©2018 osisoft, llc planned agenda...
TRANSCRIPT
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Coding for OCSDerek Endres
Software Developer – Research
1
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Planned Agenda
• Intro (~20 min)• Presentation formalities
• Intro to OCS
• Detail of what I am going to do
• Building the app (~55 min)
• Ending (~15)• Wrap-up
• Questions
2
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Who am I
• 6+ years at OSI
• Role • Research Software Developer
• Previous Roles• AF UI developer
• Tech Support Escalation Engineer
• Tech Support Engineer/Field Service Engineer
• Mechanical Engineer by degree
• Numerous programming languages
3
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Who I am not
• Not an OCS Software Developer/Product Manager• I am knowledgeable on OCS
• I might defer to other people with specific questions
• Not connected or related to Google at all
4
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Questions?
• Will have time at the end
• Reach out to me: [email protected]
5
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Comments on OCS
• http://feedback.osisoft.com• There is an area for OSIsoft Cloud Services
6
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Want OCS?
• https://cloud.osisoft.com/• Request to join preview
7
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
OCS Introduction
8
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Edge Data
Edge Data
Enterprise Data
PI Server
On Premises
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 10
OSIsoft Cloud Services
Ingress
Context
Ad
min
istr
ati
on
Community
Storage REST A
PIs
OSIsoft Messaging Format (OMF)
Visualization
OMF
ApplicationsOpen
Source
Edge Data
Store
PI
ConnectorsPI
Systems
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Remote Operations Monitoring
Connected Community
Data Science Enablement
OSIsoft Cloud Services (OCS)
11
Initial Customer Scenarios
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 12
OSIsoft Cloud Services (OCS) Overview
• Managed, secure, data platform• Multi-tenant
• PaaS & SaaS
• High speed, scalable, elastic
• Flexible, resilient, data storage
• Modern, secure REST APIs
• Security based on Windows Azure Active Directory (WAAD)
• Operated & maintained by OSIsoft
• Built and deployed in Microsoft Azure public cloud
• …
OSIsoft Cloud Services
https://cloud.osisoft.com/
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Ingress Overview
• RESTful ingress
• OSIsoft Message Format• OMF v1.0
• High throughput
• Low maintenance
• Distributed storage layer• CRUD
• “Open Access”• Almost any language
• Security based on WAAD
• Redundancy
• High fidelity
• Scalable & elastic
13
Storage Overview
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
OCS Data Storageis a (Time) Series Database
14
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Ingress & Storage: How to Represent Data?
{ "temperature":"30.43","timestamp":"2016-04-..." }
{ "pressure":"101.5","timestamp":"2016-04-..." }
{ "heart-rate":"143","timestamp":"2016-04-..." }
{ "latitude":"29.7817","timestamp":"2016-04-..." }
{ "longitude":"-95.6112","timestamp":"2016-04-..." }
{ "heading":"42","timestamp":"2016-04-..." }
{ "latitude":"29.7817","longitude":"-95.6112","heading":"42","heart-rate":"143","temperature":"30.43","pressure":"101.5","timestamp":"2016-04-..." }
Individual sensors “Fitness band”
If you like… You might also enjoy…
15
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Organizing data… Namespaces / Types / Streams / Events
16
Account: Annual Analytics
Namespace: Drilling Data Namespace: Meters
Type: Simple measurement
Stream: Platform 432-NStream: Platform 432-N
Stream: Platform 432-N
New eventNew eventNew eventNew eventNew event
Type Type
Type Type
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Data Structure: Types – Simple Cases
17
Type: Simple Double
Timestamp: DateTime
Value: Double
Quality info: Boolean
Type: Simple Integer
Timestamp: DateTime
Value: Integer
Quality info: Boolean
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Data Structure: Types – Complex Cases
18
Type: Platform pressure
Timestamp: DateTime
Pressure: Double
Edited: DateTime?
Depth: Double
Area code: Integer
Quality info: String
Type: Batch measurement
Lot number: Integer
pH: Single
Tested: DateTime?
Color: String
Weight: Double
Quality info: String
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Stream: Platform 434-E
Type: Complex type
Name: Platform 432-N
Description: Fronts…
Tags: Drilling, EU,…
Indexes: Depth, Time…
Stream: Platform 433-S
Type: Complex type
Name: Platform 432-N
Description: Fronts…
Tags: Drilling, EU,…
Indexes: Depth, Time…
Data Storage: Streams (instances of a Type)
19
Type: Platform pressure
Timestamp: DateTime
Pressure: Double
Edited: DateTime?
Depth: Double
Area code: Integer
Quality info: String
Stream: Platform 432-N
Type: Platform pressure
Name: Platform 432-N
Description: Fronts…
Tags: Drilling, EU,…
Indexes: Depth, Time…
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
End of High level OCS Overview
• More detailed questions? Contact me and I can help get you to the right person
20
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
What we are going to do Today
• Explore the OCS APIs for retrieving and sending data
21
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Goals:
• I want get data from OCS• I need to understand and be able to interact with namespaces and
streams to get to the data.
• I want to send data to OCS• I need to be able to create the type and streams to be able to send
data
22
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Assumptions
• Already Have:• Tenant
• Client Key
• Namespace
23
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Details
• In this session we use Google Sheets as our way to view and get the data
24
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Coding in Google Scripts
• .GS file – Javascript run Server side (Google Cloud)• Once saved it works automatically
• Functions can be called directly in spreadsheet • Can be made private and can add some help to function pop up in spreadsheet
• Can put in .HTML files • Run client side (local browser)
• Must refresh spreadsheet if you add or update these files
• Not being used in this
25
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Coding in Google Scripts pt 2
• UrlFetchApp(url, options) – Easiest way to interact with a URL• Options includes: post/put/get, headers
• A Cell reference in function call brings the values into the function like sending it in via double quotes
• Output of function goes to cells. • Array of strings (ints, doubles) goes in a column
• 2-D array gives you rows and columns
• Console.log sends to Stackdriver Logs
26
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Code Time
• Auth
• Namespaces
• Streams
• Data
• Send Data
• Send Stream
• Send Type
27
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
First Need to get OAuth Bearer Token
• Given in samples (Next Slide)
• Headers• Authorization
• Bearer {token}
28
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 29
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 30
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 31
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Now we can get Namespaces
32
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 33
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 34
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 35
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Streams
36
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 37
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 38
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 39
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 40
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Time For Data!!!
• Will do First Data first.
41
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 42
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 43
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 44
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 45
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Get Last Value
• Follows the same format as get first value
46
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Not too bad, lets move on to a harder one
• Get Range Values
47
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 48
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 49
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 50
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 51
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 52
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 53
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Awesome we have more data in Sheets
• Can extrapolate what I have out to the other data reading functions pretty easily
• Just add the function call
• Create the URL
• Add the parameters if they are entered and then let the magic work
54
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Possible calls for data
• Get Value
• Get First Value
• Get Last Value
• Get Distinct Value
• Find Distinct Value
• Get Values
• Get Range Values
• Get Window Values
• Get Intervals
55
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Now lets send data back into OCS
• Note these examples show the function quoted out because if you keep the function running in Google Sheets it sends it multiple times
• It also becomes Hidden because Sheets just displays the result of the function call
56
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 57
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 58
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 59
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 60
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 61
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 62
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Awesome we have data going to OCS
• Note sending the data is interesting this way
• You have to be careful it gets called every time the page refreshes (OCS gives an “error” if you try to insert a value at an index that already has values, so it doesn’t overwrite it or put another one there).
63
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Next Thing?
• Create a Stream
64
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 65
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 66
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 67
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 68
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Next Thing??
• Ok, we can create a Type
69
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 70
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 71
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 72
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 73
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 74
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 75
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 76
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Recap
• Can send • Data
• Stream
• Type
• Data and type both need a table in order to form the data, can we send all together?
77
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC 78
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Awesome
79
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Final Thoughts
• This is just an introduction• For more details try it and let us know and we can build a deeper dive
• Get OCS• Help shape the data APIs with the calls you need to get the data you
need
80
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Questions
Please wait for the
microphone before asking
your questions
State your
name & company
Please remember to…
Complete the Online Survey
for this session
81
#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC#OSIsoftUC #PIWorld ©2018 OSIsoft, LLC
Thank You
Merci
Grazie
82