-
Notifications
You must be signed in to change notification settings - Fork 1
Test integrated resource
After our resource have been shared with Core we can test if we can find and access it properly.
To search for resource we need to create a query to the symbIoTe Core. In our example we use https://core.symbiote.eu:8100/coreInterface/v1/query endpoint and provide parameters for querying. Requests need properly generated security headers. More on topic of secure access to symbIoTe component can be read on SymbIoTeSecurity project page.
All possible query parameters can be seen below:
Query parameters {
platform_id: String
platform_name: String
owner: String
name: String
id: String
description: String
location_name: String
location_lat: Double
location_long: Double
max_distance: Integer
observed_property: List<String>
resource_type: String
}
NOTE 1: To query using geospatial properties, all 3 properties need to be set: location_lat (latitude), location_long (longitude) and max_distance (distance from specified point in meters).
NOTE 2: Text parameters allow substring searches using '*' character which can be placed at the beginning and/or end of the word to search for. For example querying for name "Sensor*" finds all resources with name starting with Sensor, and search for name "*12*" will find all resources containing string "12" in its name. Using substring search can be done for the following fields:
- name
- platform_name
- owner
- description
- location_name
- observed_property
For our example lets search for resources with name Stationary 1. We do it by sending a HTTP GET request on symbIoTe Core Interface ( https://core.symbiote.eu:8100/coreInterface/v1/query?name=Stationary 1). Response contains a list of resources fulfilling the criteria:
{
"resources": [
{
"platformId": "test1Plat",
"platformName": "Test 1 Plat",
"owner": null,
"name": "Stationary 1",
"id": "591ae23eb80b283c012fdf26",
"description": "This is stationary 1",
"locationName": "SomeLocation",
"locationLatitude": 25.864716,
"locationLongitude": 5.349014,
"locationAltitude": 35,
"observedProperties": [
"temperature",
"humidity"
],
"resourceType": [
"http://www.symbiote-h2020.eu/ontology/core#StationarySensor"
],
"ranking": 0.5
}
]
}
Starting with Release 0.2.1, an additional endpoint was created to allow sending SPARQL queries to symbIoTe Core. To send SPARQL requests we need to send request by using HTTP POST to the url: https://core.symbiote.eu:8100/coreInterface/v1/sparqlQuery
The endpoint accepts the following payload:
{
"sparqlQuery" : "<sparql>",
"outputFormat" : "<format>"
}
Possible output formats include: SRX, XML , JSON , SRJ, SRT, THRIFT, SSE, CSV , TSV, SRB, TEXT , COUNT, TUPLES, NONE, RDF, RDF_N3, RDF_XML, N3, TTL , TURTLE **, GRAPH, NT, N_TRIPLES, TRIG
SPARQL allows for powerful access to all the meta information stored within symbIoTe Core. Below you can find few example queries
- Query all resources of the core
{
"sparqlQuery" : "PREFIX cim: <http://www.symbiote-h2020.eu/ontology/core#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?res ?resourceName WHERE { ?res a cim:Resource. ?res rdfs:label ?resourceName . }",
"outputFormat" : "TEXT"
}
returns the following output:
------------------------------------------------------------------------------------------------------
| res | resourceName |
======================================================================================================
| <http://www.symbiote-h2020.eu/ontology/resources/591ae23eb80b283c012fdf26> | "Stationary 1" |
| <http://www.symbiote-h2020.eu/ontology/resources/591ae5edb80b283c012fdf29> | "Actuating Service 1" |
------------------------------------------------------------------------------------------------------
- Query for Services and display information about input they are requiring: name and datatype
{
"sparqlQuery" : "PREFIX cim: <http://www.symbiote-h2020.eu/ontology/core#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?res ?resourceName ?inputName ?inputDatatype WHERE { ?res a cim:Service. ?res rdfs:label ?resourceName . ?res cim:hasInputParameter ?input . ?input cim:name ?inputName . ?input cim:datatype ?inputDatatype }",
"outputFormat" : "TEXT"
}
returns the following output:
--------------------------------------------------------------------------------------------------------------------------------------
| res | resourceName | inputName | inputDatatype |
======================================================================================================================================
| <http://www.symbiote-h2020.eu/ontology/resources/591af131b80b2847be1d62eb> | "Actuating Service 1" | "inputParam1" | "xsd:string" |
--------------------------------------------------------------------------------------------------------------------------------------
To access the resource we need to ask symbIoTe Core for the access link. To do so we need to send HTTP GET request on https://core.symbiote.eu/coreInterface/v1/resourceUrls, with ids of the resources as parameters. For our example, we want urls of 2 resources, so request looks like: https://core.symbiote.eu/coreInterface/v1/resourceUrls?id=589dc62a9bdddb2d2a7ggab8,589dc62a9bdddb2d2a7ggab9. To access the endpoint we need to specify security headers, as described in SymbIoTeSecurity
If we provide correct ids of the resources along with a valid security credentials in the header, we will get a response containing URLs to access the resources:
{
"589dc62a9bdddb2d2a7ggab8": "https://myplatform.eu:8102/rap/Sensor('589dc62a9bdddb2d2a7ggab8')",
"589dc62a9bdddb2d2a7ggab9": "https://myplatform.eu:8102/rap/Sensor('589dc62a9bdddb2d2a7ggab9')"
}
In order to access the resources, you need to create a valid Security Request. For that, you can either integrate the Security Handler offered by the symbIoTe framework (implemented in Java) or develop a custom implementation for creating the Security Request. More information can be found in SymbIoTeSecurity repository.
As stated previously, RAP can be configured to support different interfaces for accessing the data:
- OData
- REST
The applications can:
- Read current value from resource
- Read history values from resource
- Write value into resource
-
GET https://myplatform.eu:8102/rap/{Model}s('symbioteId')/Observations?$top=1
-
GET https://myplatform.eu:8102/rap/{Model}s('symbioteId')/Observations Historical readings can be filtered, using the option $filter. Operators supported:
- Equals
- Not Equals
- Less Than
- Greater Than
- And
- Or
-
PUT https://myplatform.eu:8102/__rap/{Model}s('serviceId')
Request body:{ "capability": [ { "restriction1": “value1", }, { "restriction2": “value2", }, … ] }
The keyword {Model} depends on the Information Model used to register devices: can be Sensor, Actuator, Light, Curtain, etc.. The same reasoning applies for capability, restriction and value.
-
GET https://myplatform.eu:8102/rap/Sensor/{symbioteId}/history
-
POST https://myplatform.eu:8102/rap/Service('symbioteId')
Request body:{ "capability": [ { "restriction1": “value1", }, { "restriction2": “value2", }, … ] }
Applications can receive notifications from resources, through SymbIoTe RAP WebSocket. `` Client shall open a WebSocket connection towards a Server at
ws://IP:PORT/notification
, where IP and PORT are the Interworking Interface parameters.
To subscribe (or unsubscribe) to resources you have to send a message to the WebSocket specifying:
{
"action": "SUBSCRIBE" / "UNSUBSCRIBE"
"ids": ["id1", "id2", "id3", ...]
}
Afterwards notifications will be automatically received by the application from the WebSocket.