This example demonstrates how to create a location sensor entity and subscribe to its updates.
Create a new subscription template for the location sensor entity with the following minimal settings:
| Field | Value |
|---|---|
| Name | Location Alert |
| Connection | select the FIWARE Connection for your broker (an administrator creates these, see broker_connections.md) |
| Field | Value |
|---|---|
| Entities | [{ "idPattern": ".*", "type": "LocationSensor" }] |
| Area | select Within the project boundary (the project needs a boundary drawn in its GTT 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}" \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"
}
}'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.
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}"