82
Co-funded by the Horizon 2020 Framework Programme of the European Union Co-funded by the Horizon 2020 Framework Programme of the European Union NGSI V2 API

NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Co-funded by the Horizon 2020 Framework Programme of the European Union

Co-funded by the Horizon 2020 Framework Programme of the European Union

NGSI V2 API

Page 2: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Co-funded by the Horizon 2020 Framework Programme of the European Union

Orion Context Broker

Page 3: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Co-funded by the Horizon 2020 Framework Programme of the European Union

Context Broker Operations

Page 4: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

4

FIWARE NGSI

Page 5: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

5

Context Data

Page 6: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

6

MIME Types The API response payloads in this specification

are based on application/json and (for attribute value type operation) text/plainMIME types. Clients issuing HTTP requests with accept types different than those will get a 406 Not Acceptable error.

Page 7: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

7

Entity Representation The entity id is specified by the object's id property,

whose value is a string containing the entity id. The entity type is specified by the object's type

property, whose value is a string containing the entity's type name.

Entity attributes are specified by additional properties, whose names are the name of the attribute and whose representation is described in the "JSON Attribute Representation" section below. Obviously, id and typeare not allowed to be used as attribute names.

Page 8: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

8

Entity Representation

Page 9: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

9

JSON Attribute Representation The attribute value is specified by the value property,

whose value may be any JSON datatype. The attribute NGSI type is specified by the type

property, whose value is a string containing the NGSI type.

The attribute metadata is specified by the metadataproperty. Its value is another JSON object which contains a property per metadata element defined (the name of the property is the name of the metadata element)

Page 10: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

10

JSON Attribute Representation

Page 11: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

11

Simplified Entity Representation keyValues mode. This mode represents the

entity attributes by their values only, leaving out the information about type and metadata. See example below.

Page 12: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

12

Simplified Entity Representation values mode. This mode represents the entity

as an array of attribute values.

Page 13: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

13

Special Attribute Types DateTime: identifies dates, in ISO8601 format.

These attributes can be used with the query operators greater-than, less-than, greater-or-equal, less-or-equal and range. For instance (only the referred entity attribute is shown):

Page 14: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

14

Virtual Attributes inside of options:

dateCreated (type:DateTime) ISO 8601. dateModified (type:DateTime) ISO 8601.

Like regular attributes, the can be used in attrs, q filters and order by.

Page 15: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Common Operations

Page 16: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Common Operations

Page 17: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Follow the steps at

https://codeshare.io/5X8egM

Page 18: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Check Health

Page 19: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Create Entities

Page 20: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Add Entity

Page 21: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Get Entity

Page 22: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Update Entities

Page 23: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Update Entity

Page 24: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Update Entity

Page 25: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Update Entity – text/plain

Page 26: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Create Room

Page 27: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Metadata

Page 28: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Update Room

Page 29: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Query Room

Page 30: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Query Room

Page 31: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Query Room

Page 32: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Filter Room

Page 33: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Filter Room

Page 34: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Exercise Create the entities using the global

instance.

Page 35: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Hands on – Create Entities

Page 36: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz
Page 37: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Hands on – Update Entities

Page 38: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Exercise Updates Locked attribute of Frontdoor

entity using a valid input. Queries the entity and check the result.

Page 39: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Query Language

Page 40: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

40

Query Language inside of options:

dateCreated (type:DateTime) ISO 8601. dateModified (type:DateTime) ISO 8601.

Like regular attributes, the can be used in attrs, q filters and order by.

Page 41: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

41

Query Filters

Page 42: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

42

Query Filters

Page 43: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

43

Page 44: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Hands on – Query Entities

Page 45: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Exercise Obtain all attributes of Bedroom1 entity. Obtain only the Temperature attribute of

Kitchen entity. Obtain all attributes of Kitchen and

Bedroom2 entities in one query. Obtain all attributes of entities that match

the pattern Bedroom.*

Page 46: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Exercise - Finally Find out whether the doors are closed

using the pattern .*door and the Closedattribute

Page 47: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Suscriptions

Page 48: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Hands on – Update Entities

Page 49: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Exercise Updates the Temperature attribute of

Beedroom1 and Bedroom2 entities using that input with a single update operation.

Queries the entities and check the result.

Page 50: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Hands on – Create Entities (Again)

Page 51: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Exercise

Page 52: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Hands on – List Entity Types

Page 53: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Exercise Lists all entity types Provides detailed information of type

Door

Page 54: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Geo Localization

Page 55: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Geo-location

Page 56: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

More geo-relationships Apart from near, the following georel can

be used georel=coveredBy georel=intersects georel=equals georel=disjoint

Page 57: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Example Let consider the next elementos:

Page 58: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Example Let´s consider a query whose scope is the

internal area to the square defined by coordinates (0,0) , (0,6) , (6,6) and (6,0)

Page 59: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

The result of the query isA and B

Page 60: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Example Let´s consider a query whose scope is the

internal area to the rectangle defined by coordinates (3,3) , (3,8) , (11,8) and (11,3)

Page 61: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

The result of the query isB and C

Page 62: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Example if we consider the query to the external

area to that rectangle, the result of the query would be A. To specify that, we refer to the area external to the polygon we include the inverted element set to “true”

Page 63: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz
Page 64: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Example Let´s consider a query whose scope is the

internal area to the triangle defined by coordinates (0,0), (0,6), (6,0).

Page 65: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz
Page 66: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Example However, if we consider the query to the

external area to that triangle (using the inverted element set to “true”), the result of the query would be B and C.

Page 67: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz
Page 68: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Real Use Case Three entities (representing the cities of

Madrid, Alcobendas and Leganes) have been created in Orion Context Broker.

The coordinates for Madrid are (40.418889, -3.691944); the coordinates for Alcobendas are (40.533333, -3.633333) and the coordinates for Leganes are (40.316667, -3.75).

Page 69: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Real Use Case Let's consider a query whose scope is

inside a radius of 13.5 km (13500 meters) centred in Madrid.

Page 70: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Geo-location- Max distance

Page 71: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

The query is:

Page 72: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Geo-location- Inverted

Page 73: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Geo-location- Min distance

Page 74: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Hands on – Geo Location

Page 75: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Batch Operations

Page 76: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Batch Operations

Page 77: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Pagination

Page 78: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Elements limit: Number of elements per page (default:

20, max: 1000) offset: Number of elements to skip (default: 0) count (optional): Returns total elements

(default: not return)

Page 79: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Example

GET <orion_host>:1026/v2/entities?limit=5 GET <orion_host>:1026/v2/entities?offset=5&limit=5 GET <orion_host>:1026/v2/entities?offset=10&limit=5 GET <orion_host>:1026/v2/entities?offset=15&limit=5

Page 80: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Considerations: By default, results are ordered by entity

creation date This behavior can be overridden using

orderBy URI parameter Example: get the first 10 entities ordered

by temp in ascending order, then humidity in descending order

GET <orion_host>:1026/v2/entities?limit=20&offset=0&orderBy=temp,!humidity

Page 81: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

Considerations (Continues..) dateCreated and dateModified can be

used to ordering by entity creation and modification date, respectively

Page 82: NGSI V2 API - CUDI. Context... · inverted element set to “true”), the result of the query would be . B. and . C. ... Presentación de PowerPoint Author: Erik Valdivieso Díaz

The end