Skip to content

Latest commit

 

History

History
95 lines (76 loc) · 3.13 KB

File metadata and controls

95 lines (76 loc) · 3.13 KB

Location Sensor Example

This example demonstrates how to create a location sensor entity and subscribe to its updates.

Subscription Template for Location Sensor

Create a new subscription template for the location sensor entity with the following minimal settings:

General Settings

Field Value
Name Location Alert
Connection select the FIWARE Connection for your broker (an administrator creates these, see broker_connections.md)

Subscription Settings

Field Value
Entities [{ "idPattern": ".*", "type": "LocationSensor" }]
Area select Within the project boundary (the project needs a boundary drawn in its GTT settings)

Issue Settings

Field Value
Subject Location Alert
Description The location sensor ${id} entered the project area.
Issue geometry { "type": "Feature", "geometry": "${location}" }
Create issues as api_user (the member the created issues are authored as)

Create the subscription template and publish it.

Note: When authentication is required, provide the Authorization header with

  -H "Authorization: Bearer ${BROKER_TOKEN}" \

Creating an Entity with Location

curl -iX POST "${BROKER_URL}/v2/entities" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ${BROKER_TOKEN}" \
  -H "Fiware-Service: ${FIWARE_SERVICE}" \
  -H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}" \
  -d '{
    "id": "urn:ngsi-ld:LocationSensor:001",
    "type": "LocationSensor",
    "location": {
      "value": {
        "type": "Point",
        "coordinates": [135.27666, 34.72483]
      },
      "type": "geo:json"
    }
  }'

Update Location

curl -iX PATCH \
  "${BROKER_URL}/v2/entities/urn%3Angsi-ld%3ALocationSensor%3A001/attrs" \
  -H "Authorization: Bearer ${BROKER_TOKEN}" \
  -H "Fiware-Service: ${FIWARE_SERVICE}" \
  -H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}" \
  -H "Content-Type: application/json" \
  -d '{
    "location": {
      "value": {
        "type": "Point",
        "coordinates": [139.75032, 35.67087]
      },
      "type": "geo:json"
    }
  }'

Note: The location coordinates are for Tokyo and Kobe, Japan. In order to trigger the subscription in this example, the location must be updated to be within the project boundary.

Delete Entities

curl -iX DELETE \
  "${BROKER_URL}/v2/entities/urn%3Angsi-ld%3ALocationSensor%3A001" \
  -H "Authorization: Bearer ${BROKER_TOKEN}" \
  -H "Fiware-Service: ${FIWARE_SERVICE}" \
  -H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}"