Sensor thingsapi webinar-#3-rest-for-iot-api-20151210
Transcript of Sensor thingsapi webinar-#3-rest-for-iot-api-20151210
![Page 1: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/1.jpg)
OGC SensorThings API
Tutorial #3 - RESTful Pattern for IoT API
0.23 litre/minute
0.25 litre/minute0.27 litre/minuteRH: 85 %
Temp: 18 Celsius
Dr. Steve Liang Chair, OGC SensorThings API Standard Working Group Founder and CEO, SensorUp Inc. Associate Professor, University of Calgary
![Page 2: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/2.jpg)
sensorup.com@sensorup
Agenda
• Recap: OGC SensorThings Data Model
• IoT API RESTful Pattern
• Many Examples
![Page 3: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/3.jpg)
sensorup.com@sensorup
About Dr. Steve Liang• Associate Professor, Geomatics Engineering, Uni. Calgary
• AITF-Microsoft Industry Chair on Open Sensor Web
• Chair OGC SensorThings API Standard Working Group
• Co-Chair OGC Sensor Web Enablement Domain Working Group
• N.A. Chair, OGC University Domain Working Group
• Rapporteur, ITU-T SG12/11 on Internet of Things Test Specifications
• Founder and CEO, SensorUp Inc, a University of Calgary startup (http://www.sensorup.com)
![Page 4: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/4.jpg)
sensorup.com@sensorup
About SensorUp• We are a world leader in OGC Sensor Web and IoT
• We are leading several international IoT standard development efforts (OGC and ITU-T)
• We developed world’s first OGC SensorThings API implementation
![Page 5: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/5.jpg)
5
Data Model
![Page 6: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/6.jpg)
Prerequisites
• Basic knowledge of REST (REpresentational State Transfer)
• https://en.wikipedia.org/wiki/Representational_state_transfer
• Basic knowledge of JSON (JavaScript Object Notation)
• http://www.json.org/
![Page 7: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/7.jpg)
Before We Start• It’s all about LINKS!
• great discoverability
• great for dynamic use cases
• efficient and great developer experiences
• big data analytics friendly
• Uniform and Consistent Pattern
![Page 8: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/8.jpg)
SensorThings Entities Common Control Information
8
Annotation Definition Data type Multiplicity
@iot.id system generated identifier Any 1
@iot.selfLink absolute URL of an entity URL 1
@iot.navigationLink link leading to related entities URL 1…*
![Page 9: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/9.jpg)
Common Control Information
9
![Page 10: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/10.jpg)
IoT API URL Patterns based on SensorThings
10
![Page 11: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/11.jpg)
URI
version
11
![Page 12: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/12.jpg)
#1 Root URL
12
![Page 13: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/13.jpg)
#2 Address to an entity set
13
one of the eight entities, e.g., Things, Datastreams
![Page 14: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/14.jpg)
#3 Address to an individual entity
14
![Page 15: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/15.jpg)
#4 Address to a property of an entity
15
![Page 16: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/16.jpg)
#5 Address to the value of a property of an entity
16
![Page 17: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/17.jpg)
#6 Address to a navigation property (navigationLink)
17
![Page 18: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/18.jpg)
#7 Address to an association link
18
![Page 19: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/19.jpg)
#8 Nested Resource Path
19
![Page 20: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/20.jpg)
Query Options
20
![Page 21: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/21.jpg)
Evaluating System Query Options
21
• Prior to applying any server-driven paging:
• $filter
• $orderby
• $skip
• $top
• After applying any server-driven paging:
• $expand
• $select
![Page 22: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/22.jpg)
The $expand system query option indicates the related entities to be represented inline.
Über flexibility!
Example 1: http://example.org/v1.0/Things?$expand=Datastreams returns the entity set of Things as well as each of the Datastreams associated with each Thing entity
$expand
![Page 23: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/23.jpg)
E x a m p l e 2 : http://example.org/v1.0/Things?$expand=Datastreams/ObservedProperty r e t u r n s t h e collection of Things, the Datastreams associated with each Thing, and the ObservedProperty associated with each Datastream.
Example 3: http://example.org/v1.0/Datastreams(1)?$expand=Observations,ObservedProperty returns the Datastream whose id is 1 as well as the Observations and ObservedProperty associated with this Datastream.
![Page 24: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/24.jpg)
The $select system query option requests that the service to return only the properties explicitly requested by the client.
E x a m p l e 1 : http://example.org/v1.0/Observations?$select=result,resultTime
$select
Great for performance! Reduce response time and data size.
![Page 25: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/25.jpg)
E x a m p l e 1 : http://example.org/v1.0/Observations?$resultFormat=dataArray
$resultFormat=dataArray
Great for performance! Reduce response time and data size.
![Page 26: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/26.jpg)
$orderby
• Example 1: http://examples.com/v1.0/Observations?$orderby=result returns all Observations ordered by the result property in ascending order.
![Page 27: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/27.jpg)
Example 1: http://example.org/v1.0/Things?$top=5 returns only the first five entities in the Things collection.Example 2: http://example.org/v1.0/Observations?$top=5&$orderby=phenomenonTime desc re tu rns the fi rs t five Observation entries after sorted by the phenomenonTime property in descending order.
Note: if the $top value exceeds the service-driven pagination limitation (i.e., the largest number of entities the service can return in a single response), the $top query option should be discarded and the pagination limitation shall be imposed.
$top
![Page 28: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/28.jpg)
The $skip system query option specifies a non-negative integer n that excludes the first n items of the queried collection from the result. The service returns items starting at position n+1.Example 1: http://example.org/v1.0/Things?$skip=5 returns Thing entities starting with the sixth Thing entity in the Things collection.Where $top and $skip are used together, $skip SHALL be applied before $top, regardless of the order in which they appear in the request.If no unique ordering is imposed through an $orderby query option, the service SHALL impose a stable ordering across requests that include $skip.
$skip
![Page 29: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/29.jpg)
A URI with a $filter query option identifies a subset of the entries from the collection of entries identified by the resource path of the URI. The subset is determined by selecting only the entries that satisfy the predicate expression specified by the $filter. The value of the $filter option is a Boolean expression.
The expression language that is used in $filter operators supports references to properties and literals. The literal values can be strings enclosed in single quotes, numbers and boolean values (true or false) or datetime values represented as ISO 8601 time string.
$filter
![Page 30: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/30.jpg)
![Page 31: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/31.jpg)
Service-driven Paging• @iot.nextLink
![Page 32: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/32.jpg)
Connect Your Arduino
• Instruction and Source Code:
• https://sensorup.atlassian.net/wiki/display/SPS/2015/12/02/SensorThings+API+-+Arduino+101
![Page 33: Sensor thingsapi webinar-#3-rest-for-iot-api-20151210](https://reader031.fdocuments.us/reader031/viewer/2022021813/58715c691a28ab8e5b8b6927/html5/thumbnails/33.jpg)
Useful Resources
• SensorThings API Playground
• http://pg.sensorup.com
• API Documentation
• http://www.sensorup.com/docs