Guide for Experimenters

4 IoT-Registry API for Advanced Experimenters

4.4 Queries

Whereas in the first four points we have covered various features to get data in a more guided way, with the use of SPARQL-based queries we offer the freedom to tailor the request as much as the experimenter wants.

  • Store. This works as a kind of catalogue through which we can offer a number of preconfigured queries to others. At the very same time, everyone is welcome to bring new SPARQL queries to the “store”, by just registering them (through a POST message). This way, non-skilled users could have illustrative examples of how to extract data from the meta-directory and find inspiration to create their own ones.
  • Execute. On the other hand, you can directly execute a query through these endpoints.



Queries IoT Registry Endpoint


Regarding this last part, we present int the following tables a number of well-known SPARQL queries that we encourage you to take a look before defining your own ones from scratch. They are the outcome of a compilation of most of the queries that all partners have been using in all our activities.

SPARQL 1 - FIesta-IoT Asset Summary

Request

GET https://platform.fiesta-iot.eu/iot-registry/api/queries/execute/global

URL Parameters

from=<starting_date>
to=
<ending_date>

HTTP Headers:

Content-Type: text/plain
iPlanetDirectoryPro: <ssoToken>

accept: text/tab-separated-values

SPARQL query

PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>
PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT  (COUNT(DISTINCT ?dep) AS ?deployments)
    (COUNT(DISTINCT ?dev) AS ?devices)
    (COUNT(DISTINCT ?sens) AS ?sensors)
    (COUNT(DISTINCT ?obs) AS ?observations)
    (COUNT(DISTINCT ?n) AS ?nodes)
WHERE {
  {?dep a ssn:Deployment}
UNION
  {?dev a ssn:Device}
UNION
  {?sens rdf:type/rdfs:subClassOf ssn:SensingDevice}
UNION
  {?obs a ssn:Observation}
}

Response

?deployments  ?devices      ?sensors      ?observations
4      1068   3465   13538026  

 

 

SPARQL 2 - Number of sensing devices per type (and testbed)

Request

GET https://platform.fiesta-iot.eu/iot-registry/api/queries/execute/global

URL Parameters

NONE

HTTP Headers:

Content-Type: text/plain
iPlanetDirectoryPro: <ssoToken>
accept: application/json

SPARQL query

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>
PREFIX iot-lite: <http://purl.oclc.org/NET/UNIS/fiware/iot-lite#>
SELECT   ?deployment (COUNT(DISTINCT ?sensor) AS ?sensors) ?qk ?type
WHERE {
       ?deployment a ssn:Deployment .
       {
              ?dev ssn:hasDeployment ?deployment .
              ?dev ssn:hasSubSystem ?sensor
       }
       UNION
       {
              ?sensor ssn:hasDeployment ?deployment
       }
       ?sensor iot-lite:hasQuantityKind ?qkr .
       ?qkr rdf:type ?qk .
       ?sensor a ?type
}
GROUP BY ?deployment ?qk ?type
ORDER BY ?deployment

Response

{
    "vars": [
        "deployment",
        "sensors",
        "qk",
        "type"
    ],
    "items": [
        {
            "deployment": "https://platform.fiesta-iot.eu/iot-registry/api/testbeds/a1yp9GcKEPw37Bx5rslgRI4QLSNCwEwBatCIOe_W0dHZCmzj2WmkExz3qoNuvWg1pueAXn1Li0JrNjvBiQwV3Q==",
            "qk": "http://purl.org/iot/vocab/m3-lite#ChemicalAgentAtmosphericConcentrationAirParticles",
            "type": "http://purl.org/iot/vocab/m3-lite#GaseousPollutantSensor",
            "sensors": "101^^http://www.w3.org/2001/XMLSchema#integer"
        },
        {
            "deployment": "https://platform.fiesta-iot.eu/iot-registry/api/testbeds/a1yp9GcKEPw37Bx5rslgRI4QLSNCwEwBatCIOe_W0dHZCmzj2WmkExz3qoNuvWg1pueAXn1Li0JrNjvBiQwV3Q==",
            "qk": "http://purl.org/iot/vocab/m3-lite#RelativeHumidity",
            "type": "http://purl.org/iot/vocab/m3-lite#HumiditySensor",
            "sensors": "20^^http://www.w3.org/2001/XMLSchema#integer"
        }, …
    ]
}

 

 

SPARQL 3 - Resource discovery (all nodes)

Request

GET https://platform.fiesta-iot.eu/iot-registry/api/queries/execute/global

URL Parameters

NONE

HTTP Headers:

Content-Type: text/plain
iPlanetDirectoryPro: <ssoToken>
accept: application/json

SPARQL query

PREFIX iot-lite: <http://purl.oclc.org/NET/UNIS/fiware/iot-lite#>

PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>

PREFIX geo:  <http://www.w3.org/2003/01/geo/wgs84_pos#>

PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

 

SELECT ?sensor ?qk ?deployment ?type ?unit ?lat ?long ?endp

WHERE {

      ?deployment a ssn:Deployment .

      {

             ?dev ssn:hasDeployment ?deployment .

             ?dev ssn:onPlatform ?platform.

             ?platform geo:location ?point .

             ?point geo:lat ?lat .

             ?point geo:long ?long .

             ?dev ssn:hasSubSystem ?sensor

      }

      UNION

      {

             ?sensor ssn:hasDeployment ?deployment .

             ?sensor ssn:onPlatform ?platform.

             ?platform geo:location ?point .

      ?point geo:lat ?lat .

      ?point geo:long ?long .

      }

             ?sensor iot-lite:hasQuantityKind ?qkr .

             ?qkr rdf:type ?qk .

             ?sensor iot-lite:hasUnit ?unitr .

      ?unitr rdf:type ?unit .

            

             ?sensor a ?type

              OPTIONAL {

             ?sensor iot-lite:exposedBy ?serv .

             ?serv iot-lite:endpoint ?endp .

      }

}

Response

{

    "vars": [

        "sensor",

        "qk",

        "deployment",

        "type",

        "unit",

        "lat",

        "long",

        "endp"

    ],

    "items": [

        {

            "endp": "https://platform.fiesta-iot.eu/iot-registry/api/endpoints/ETV6cJzgIY6ADaxMe-V_ccxE2ObNgEqPdayROKWuEaWw4bfl5T2gBR-EgEqQUKa5lWCZwfVk4ShkyZS15-uae9aZ6Fy-KqiLJtBfJi3CZl3VXANSGgaLGdw0ztjw2hE_S6IvqBWTlV_JVOx4t16ISy21LovqdEUfGZYU0EWWL7b94SWfWnSjJqNUWi2qdaKb^^http://www.w3.org/2001/XMLSchema#anyURI",

            "type": "http://purl.org/iot/vocab/m3-lite#ElectricalSensor",

            "unit": "http://purl.org/iot/vocab/m3-lite#Percent",

            "qk": "http://purl.org/iot/vocab/m3-lite#BatteryLevel",

            "sensor": "https://platform.fiesta-iot.eu/iot-registry/api/resources/W_68NYKZCkpFspcj2U0yxSyfvgv6TK4jRemmB9ajOw3sAWsJJz4rJnm-F-CH4eEkRTjN233Bx8w5fZliZw7rGE1tCxVLLLRaGt_0SbJhijysWfmUFhEAXGnawnyUslbRR4aiYGpOV3q7yW5_kqgYYA==",

            "long": "-3.80649^^http://www.w3.org/2001/XMLSchema#double",

            "lat": "43.46104^^http://www.w3.org/2001/XMLSchema#double",

            "deployment": "https://platform.fiesta-iot.eu/iot-registry/api/testbeds/a1yp9GcKEPw37Bx5rslgRI4QLSNCwEwBatCIOe_W0dHZCmzj2WmkExz3qoNuvWg1pueAXn1Li0JrNjvBiQwV3Q=="

        }, ...

      ]

   

 

 

SPARQL 4 - Resource discovery (phenomena + location filters)

Request

GET https://platform.fiesta-iot.eu/iot-registry/api/queries/execute/global

URL Parameters

NONE

HTTP Headers:

Content-Type: text/plain
iPlanetDirectoryPro: <ssoToken>

accept: text/tab-separated-values

SPARQL query

PREFIX iot-lite: <http://purl.oclc.org/NET/UNIS/fiware/iot-lite#>

PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>

PREFIX geo:  <http://www.w3.org/2003/01/geo/wgs84_pos#>

PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

Prefix m3-lite: <http://purl.org/iot/vocab/m3-lite#>

 

SELECT ?dev ?sensor ?qk ?unit ?endp ?lat ?long

WHERE {

    ?dev a ssn:Device .

 

    ?dev ssn:onPlatform ?platform .

    ?platform geo:location ?point .

    ?point geo:lat ?lat .

    ?point geo:long ?long .

    ?dev ssn:hasSubSystem ?sensor .

    ?sensor iot-lite:hasQuantityKind ?qkr .

    ?qkr rdf:type ?qk .

    ?sensor iot-lite:hasUnit ?unitr .

    ?unitr rdf:type ?unit .

    OPTIONAL {

        ?sensor iot-lite:exposedBy ?serv .

        ?serv iot-lite:endpoint ?endp .

    }

    VALUES ?qk {m3-lite:AirTemperature

        m3-lite:TemperatureSoil

        m3-lite:Illuminance

        m3-lite:AtmosphericPressure

        m3-lite:RelativeHumidity

        m3-lite:WindSpeed

        m3-lite:SoundPressureLevel

        m3-lite:SoundPressureLevelAmbient

        m3-lite:Sound

        m3-lite:SolarRadiation

        m3-lite:ChemicalAgentAtmosphericConcentrationCO

        m3-lite:chemicalAgentAtmosphericConcentrationO3

        }.

} order by asc(UCASE(str(?qk))) LIMIT 10

Response

{

    "vars": [

        "dev",

        "sensor",

        "qk",

        "unit",

        "endp",

        "lat",

        "long"

    ],

    "items": [

        {

            "qk": "http://purl.org/iot/vocab/m3-lite#AirTemperature",

            "endp": "https://platform.fiesta-iot.eu/iot-registry/api/endpoints/hwY7kOlDdwluzg7c7VfQgJ5s6hwpkqPXIzkHMlJYgq6drrQlLqor9vFkRVkOl6IHkOFbPnW2XhJDMnwFXWkdsuzYnC0eI1NbSu1HaCk1SdWSfsfsdW-xBkDoxLautQqvOMjBEF0R44FPapaawuS98cmKOIsFEral7nfcuNOaKE-26_fBxQ8fZVzZMZok0dW2yhuPpUwK1BzzZe1eXVdVVA==^^http://www.w3.org/2001/XMLSchema#anyURI",

            "unit": "http://purl.org/iot/vocab/m3-lite#DegreeCelsius",

            "sensor": "https://platform.fiesta-iot.eu/iot-registry/api/resources/9Ww6ZciSwY6B-Iv_gQafrL1cYcvkif3P4ZfTaYP0kC5Xh7PlicakkcSefMICw5Godss8sBuDPYsBWxwYaE8-vT_7Asmd3F9ai1Y9jQpvMeuiFDaLQJTuw7MNeyZ1Q4fB87HpKAu_vEhUNlJkA4vKEQ==",

            "long": "-3.80429^^http://www.w3.org/2001/XMLSchema#double",

            "lat": "43.46346^^http://www.w3.org/2001/XMLSchema#double",

            "dev": "https://platform.fiesta-iot.eu/iot-registry/api/resources/-58RQD27b6aKsU46_YG7yg3Dt7KZHIAHI57K6OPA0_kqOexdipyqLEjLO3r3Hd7XxCR2B4qGftmCx4xucduHILJhq5jFqVqKpYm_hlnlLyv6jKzMmbmKojx6R4_X1Ep9"

        }, …

    ]

}     

 

 

SPARQL 5 - Last observation (phenomena+location filters)

Request

GET https://platform.fiesta-iot.eu/iot-registry/api/queries/execute/global

URL Parameters

from=<starting_date>
to=<ending_date>

HTTP Headers:

Content-Type: text/plain
iPlanetDirectoryPro: <ssoToken>

accept: application/json

SPARQL query

Prefix ssn: <http://purl.oclc.org/NET/ssnx/ssn#>

Prefix iotlite: <http://purl.oclc.org/NET/UNIS/fiware/iot-lite#>

Prefix dul: <http://www.loa.istc.cnr.it/ontologies/DUL.owl#>

Prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>

Prefix time: <http://www.w3.org/2006/time#>

PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

Prefix m3-lite: <http://purl.org/iot/vocab/m3-lite#>

Prefix xsd: <http://www.w3.org/2001/XMLSchema#>

select ?sensorID (max(?ti) as ?time) ?value ?latitude ?longitude ?qk

where {

    ?o a ssn:Observation.

    ?o ssn:observedBy ?sensorID.  

    ?o ssn:observedProperty ?qkr.

    ?qkr rdf:type ?qk.

    Values ?qk {m3-lite:Sound m3-lite:SoundPressureLevelAmbient m3-lite:AirTemperature}

    ?o ssn:observationSamplingTime ?t.

    ?o geo:location ?point.

    ?point geo:lat ?latitude.

    ?point geo:long ?longitude.

    ?t time:inXSDDateTime ?ti.

    ?o ssn:observationResult ?or.

    ?or  ssn:hasValue ?v.

    ?v dul:hasDataValue ?value.

    {

        select  (max(?dt)as ?ti) ?sensorID        

        where {

            ?o a ssn:Observation.

            ?o ssn:observedBy ?sensorID.  

            ?o ssn:observedProperty ?qkr.

            ?qkr rdf:type ?qk .

            Values ?qk {m3-lite:Sound m3-lite:SoundPressureLevelAmbient m3-lite:AirTemperature}

            ?o ssn:observationSamplingTime ?t.

            ?t time:inXSDDateTime ?dt.

        }group by (?sensorID)

    }

    FILTER (

       (xsd:double(?latitude) >= "-90"^^xsd:double)

    && (xsd:double(?latitude) <= "90"^^xsd:double)

    && ( xsd:double(?longitude) >= "-180"^^xsd:double) 

    && ( xsd:double(?longitude) <= "180"^^xsd:double)

    ) 

} group by ?sensorID ?time ?value ?latitude ?longitude ?qk

Response

{

    "vars": [

        "sensorID",

        "time",

        "value",

        "latitude",

        "longitude",

        "qk"

    ],

    "items": [

        {

            "longitude": "-5.868359516962779E-1^^http://www.w3.org/2001/XMLSchema#double",

            "qk": "http://purl.org/iot/vocab/m3-lite#AirTemperature",

            "value": "17.1578786035^^http://www.w3.org/2001/XMLSchema#float",

            "sensorID": "https://platform.fiesta-iot.eu/iot-registry/api/resources/CEjjXic0G1A-N4qCyRy-jxBL4H3HorsFQ49UB9MaKK54vkN15o_Ycq4oNIxBwfnyiMgQC6sTk73J21rsIal2CFSiqSEq5HpRZDAk8oJuUpLNMfGOtOdaWluFBsvAaTWgQADCRbPGBJ-MvTe9NIhnEQ==",

            "latitude": "5.124193338767561E1^^http://www.w3.org/2001/XMLSchema#double",

            "time": "2017-09-13T15:21:39.766370+00:00^^http://www.w3.org/2001/XMLSchema#dateTime"

        },...
     ]
}   
 

 

 

SPARQL 6 - Last observation (from a sensor ID)

Request

GET 1

URL Parameters

NONE

HTTP Headers:

Content-Type: text/plain
iPlanetDirectoryPro: <ssoToken>

accept: text/tab-separated-values

SPARQL query

Prefix ssn: <http://purl.oclc.org/NET/ssnx/ssn#>

Prefix iotlite: <http://purl.oclc.org/NET/UNIS/fiware/iot-lite#>

Prefix dul: <http://www.loa.istc.cnr.it/ontologies/DUL.owl#>

Prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>

Prefix time: <http://www.w3.org/2006/time#>

PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

Prefix m3-lite: <http://purl.org/iot/vocab/m3-lite#>

Prefix xsd: <http://www.w3.org/2001/XMLSchema#>

select ?sensorID (max(?ti) as ?time) ?value ?latitude ?longitude ?qk

where {

    ?o a ssn:Observation.

    ?o ssn:observedBy ?sensorID.  

    ?o ssn:observedProperty ?qkr.

    ?qkr rdf:type ?qk.

    Values ?qk {m3-lite:Sound m3-lite:SoundPressureLevelAmbient m3-lite:AirTemperature}

    VALUES ?sensorID {<https://platform.fiesta-iot.eu/iot-registry/api/resources/0wM31oVlhH7JC8Kg0BRcFXxpDXwefGiJbx8FYgIaBx5x0JQMhS7W2ra8B7b6tAqnl2tvHV7CZh1t1DnMfTmn9Q==>    }

    ?o ssn:observationSamplingTime ?t.

    ?o geo:location ?point.

    ?point geo:lat ?latitude.

    ?point geo:long ?longitude.

    ?t time:inXSDDateTime ?ti.

    ?o ssn:observationResult ?or.

    ?or  ssn:hasValue ?v.

    ?v dul:hasDataValue ?value.

    {

        select  (max(?dt)as ?ti) ?sensorID        

        where {

            ?o a ssn:Observation.

            ?o ssn:observedBy ?sensorID.  

            ?o ssn:observedProperty ?qkr.

            ?qkr rdf:type ?qk .

            Values ?qk {m3-lite:Sound m3-lite:SoundPressureLevelAmbient m3-lite:AirTemperature}

            ?o ssn:observationSamplingTime ?t.

            ?t time:inXSDDateTime ?dt.

        }group by (?sensorID)

    }  

} group by ?sensorID ?time ?value ?latitude ?longitude ?qk

Response

{

    "vars": [

        "sensorID",

        "time",

        "value",

        "latitude",

        "longitude",

        "qk"

    ],

    "items": [

        {

            "longitude": "-3.12E0^^http://www.w3.org/2001/XMLSchema#double",

            "qk": "http://purl.org/iot/vocab/m3-lite#AirTemperature",

            "value": "19.5295470384^^http://www.w3.org/2001/XMLSchema#float",

            "sensorID": "https://platform.fiesta-iot.eu/iot-registry/api/resources/0wM31oVlhH7JC8Kg0BRcFXxpDXwefGiJbx8FYgIaBx5x0JQMhS7W2ra8B7b6tAqnl2tvHV7CZh1t1DnMfTmn9Q==",

            "latitude": "3.989E1^^http://www.w3.org/2001/XMLSchema#double",

            "time": "2017-09-13T15:19:28.919959+00:00^^http://www.w3.org/2001/XMLSchema#dateTime"

        }

    ]

   

 

 

SPARQL 7 - Observations within a time window

Request

GET https://platform.fiesta-iot.eu/iot-registry/api/queries/execute/global

URL Parameters

NONE

HTTP Headers:

Content-Type: text/plain
iPlanetDirectoryPro: <ssoToken>

accept: text/tab-separated-values

SPARQL query

Prefix ssn: <http://purl.oclc.org/NET/ssnx/ssn#>

Prefix iot-lite: <http://purl.oclc.org/NET/UNIS/fiware/iot-lite#>

Prefix dul: <http://www.loa.istc.cnr.it/ontologies/DUL.owl#>

Prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>

Prefix time: <http://www.w3.org/2006/time#>

Prefix m3-lite: <http://purl.org/iot/vocab/m3-lite#>

Prefix xsd: <http://www.w3.org/2001/XMLSchema#>

Prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

select ?s ?ti ?value ?lat ?lon ?qk ?u

where {

    ?o a ssn:Observation.

    ?o ssn:observedBy ?s.

    ?s iot-lite:hasUnit ?unit.

    ?unit rdf:type ?u .   

    ?o geo:location ?point.

    ?o ssn:observedProperty ?qkr.

    ?qkr rdf:type ?qk.

    ?point geo:lat ?lat.

    ?point geo:long ?lon.    

    ?o ssn:observationResult ?or.

    ?or  ssn:hasValue ?v.    

    ?v dul:hasDataValue ?value.    

    ?o ssn:observationSamplingTime ?t.

    ?t time:inXSDDateTime ?ti.

    FILTER((xsd:dateTime(?ti) > "2017-09-12T00:00:00.000Z"^^xsd:dateTime) && (xsd:dateTime(?ti) < "2017-09-13T00:00:00.000Z"^^xsd:dateTime))

   

} group by ?s ?ti ?value ?lat ?lon ?qk ?u

order by ?s desc(?ti)

Response

{

    "vars": [

        "s",

        "ti",

        "value",

        "lat",

        "lon",

        "qk",

        "u"

    ],

    "items": [

        {

            "lat": "5.1242957667395444E1^^http://www.w3.org/2001/XMLSchema#double",

            "lon": "-5.88064433794546E-1^^http://www.w3.org/2001/XMLSchema#double",

            "qk": "http://purl.org/iot/vocab/m3-lite#SolarRadiation",

            "ti": "2017-09-13T15:24:52.900773+00:00^^http://www.w3.org/2001/XMLSchema#dateTime",

            "value": "1848.88523785^^http://www.w3.org/2001/XMLSchema#float",

            "u": "http://purl.org/iot/vocab/m3-lite#WattPerSquareMetre",

            "s": "https://playground.fiesta-iot.eu/iot-registry/api/resources/-6bRByQeMiw8AnpjWf-htvUZwCmgI_Bm_QVba0aXULczKX0LNZR6i0nNFQy04x8-2eNU7yHehLih2qTOYFcxyA3OrlG013eJrAqJ7pwa0plxAETgyc60Xe63ZzJiUZmcAFZnU68qcAeR8oT5M8F7ZA=="

        }, ...

    ]
}
     

Aside from this handbook, we have also published them in: http://moodle.fiesta-iot.eu/mod/page/view.php?id=146\cf0\par