sensor thingsapi webinar-#3-rest-for-iot-api-20151210

Post on 08-Jan-2017

427 Views

Category:

Internet

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

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

sensorup.com@sensorup

Agenda

• Recap: OGC SensorThings Data Model

• IoT API RESTful Pattern

• Many Examples

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)

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

5

Data Model

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/

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

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…*

Common Control Information

9

IoT API URL Patterns based on SensorThings

10

URI

version

11

#1 Root URL

12

#2 Address to an entity set

13

one of the eight entities, e.g., Things, Datastreams

#3 Address to an individual entity

14

#4 Address to a property of an entity

15

#5 Address to the value of a property of an entity

16

#6 Address to a navigation property (navigationLink)

17

#7 Address to an association link

18

#8 Nested Resource Path

19

Query Options

20

Evaluating System Query Options

21

• Prior to applying any server-driven paging:

• $filter

• $orderby

• $skip

• $top

• After applying any server-driven paging:

• $expand

• $select

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

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.

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.

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.

$orderby

• Example 1: http://examples.com/v1.0/Observations?$orderby=result returns all Observations ordered by the result property in ascending order.

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

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

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

Service-driven Paging• @iot.nextLink

Connect Your Arduino

• Instruction and Source Code:

• https://sensorup.atlassian.net/wiki/display/SPS/2015/12/02/SensorThings+API+-+Arduino+101

Useful Resources

• SensorThings API Playground

• http://pg.sensorup.com

• API Documentation

• http://www.sensorup.com/docs

sensorup.com@sensorup

Any Questions?

See You Next Week!

top related