Skip to content

Commit

Permalink
Merge pull request #48 from gtt-project/dkastl/issue46
Browse files Browse the repository at this point in the history
Improve examples and documentation
  • Loading branch information
dkastl authored Jun 14, 2024
2 parents 548d3ab + 1cc444c commit 48851f0
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.env
4 changes: 2 additions & 2 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ de:
Suchmaske für die Subscription verwendet'
gtt_fiware_subscription_template_variable_hint: 'Attributwerte können als <code>${Variable}</code>
eingebettet werden.'
field_subscription_template_expression_coords: 'Koordinaten'
field_subscription_template_expression_coords: 'Koordinaten (lat, lon)'
field_subscription_template_standard: 'NGSI-Standard'
field_subscription_template_attachments_string: 'Anlagen (Array)'
field_subscription_template_fiware_servicepath_placeholder: '/environment'
field_subscription_template_expression_coords_placeholder: '40.419,-3.691;40.429,-3.691;40.429,-3.701'
field_subscription_template_expression_coords_placeholder: "lat1, lon1; lat2, lon2; lat3, lon3; lat1, lon1"
field_subscription_template_fiware_service_placeholder: 'smartcity'
field_subscription_template_attachments_placeholder: '[{"filename": "image.jpg",
"url": "https://example.com/image.jpg"}]'
Expand Down
4 changes: 2 additions & 2 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ en:
field_subscription_template_expression_georel_placeholder: "near;maxDistance:1000"
field_subscription_template_expression_geometry: "Geometry"
field_subscription_template_expression_geometry_placeholder: "Select a geometry"
field_subscription_template_expression_coords: "Coordinates"
field_subscription_template_expression_coords_placeholder: "40.419,-3.691;40.429,-3.691;40.429,-3.701"
field_subscription_template_expression_coords: "Coordinates (lat, lon)"
field_subscription_template_expression_coords_placeholder: "lat1, lon1; lat2, lon2; lat3, lon3; lat1, lon1"
field_subscription_template_alteration_types: "Alteration types"
field_subscription_template_notify_on_metadata_change: "Notify on metadata change"

Expand Down
4 changes: 2 additions & 2 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ en:
field_subscription_template_expression_georel_placeholder: "near;maxDistance:1000"
field_subscription_template_expression_geometry: "Geometry"
field_subscription_template_expression_geometry_placeholder: "Select a geometry"
field_subscription_template_expression_coords: "Coordinates"
field_subscription_template_expression_coords_placeholder: "40.419,-3.691;40.429,-3.691;40.429,-3.701"
field_subscription_template_expression_coords: "Coordinates (lat, lon)"
field_subscription_template_expression_coords_placeholder: "lat1, lon1; lat2, lon2; lat3, lon3; lat1, lon1"
field_subscription_template_alteration_types: "Alteration types"
field_subscription_template_notify_on_metadata_change: "Notify on metadata change"

Expand Down
4 changes: 4 additions & 0 deletions doc/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BROKER_URL=http://your_broker:1026
BROKER_TOKEN=your_token
FIWARE_SERVICE=your_service
FIWARE_SERVICEPATH=your_servicepath
4 changes: 4 additions & 0 deletions doc/broker_scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ URL specified in the header for each subscription.
`http://app.local:1026` if not set.
- `BROKER_TOKEN`: The bearer token for authentication. If provided, it will be
used in the `Authorization` header for the requests.
- `FIWARE_SERVICE`: The FIWARE service for the subscriptions (optional).
- `FIWARE_SERVICEPATH`: The FIWARE service path for the subscriptions (optional).

**Note:** Make sure to set the `BROKER_URL` and `BROKER_TOKEN` (optional) environment
variables to your context broker URL and authentication token respectively
Expand Down Expand Up @@ -71,6 +73,8 @@ subscriptions, and then makes DELETE requests to the
`http://app.local:1026` if not set.
- `BROKER_TOKEN`: The bearer token for authentication. If provided, it will be
used in the `Authorization` header for the requests.
- `FIWARE_SERVICE`: The FIWARE service for the subscriptions (optional).
- `FIWARE_SERVICEPATH`: The FIWARE service path for the subscriptions (optional).

**Note:** This script does not require any arguments. Make sure to set the
`BROKER_URL` and `BROKER_TOKEN` (optional) environment variables to your context
Expand Down
8 changes: 7 additions & 1 deletion doc/examples/camera_sensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Create the subscription template and publish it.
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:SpeedCameraSensor:001",
"type": "SpeedCameraSensor",
Expand Down Expand Up @@ -78,6 +80,8 @@ curl -iX PATCH \
"${BROKER_URL}/v2/entities/urn:ngsi-ld:SpeedCameraSensor:001/attrs" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${BROKER_TOKEN}" \
-H "Fiware-Service: ${FIWARE_SERVICE}" \
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}" \
-d '{
"speed": {
"value": 90.0,
Expand All @@ -91,5 +95,7 @@ curl -iX PATCH \
```bash
curl -iX DELETE \
"${BROKER_URL}/v2/entities/urn:ngsi-ld:SpeedCameraSensor:001" \
-H "Authorization: Bearer ${BROKER_TOKEN}"
-H "Authorization: Bearer ${BROKER_TOKEN}" \
-H "Fiware-Service: ${FIWARE_SERVICE}" \
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}"
```
8 changes: 7 additions & 1 deletion doc/examples/location_sensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Create the subscription template and publish it.
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",
Expand All @@ -64,6 +66,8 @@ curl -iX POST "${BROKER_URL}/v2/entities" \
curl -iX PATCH \
"${BROKER_URL}/v2/entities/urn:ngsi-ld:LocationSensor:001/attrs" \
-H "Authorization: Bearer ${BROKER_TOKEN}" \
-H "Fiware-Service: ${FIWARE_SERVICE}" \
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}" \
-H "Content-Type: application/json" \
-d '{
"location": {
Expand All @@ -85,5 +89,7 @@ within the project boundary.
```bash
curl -iX DELETE \
"${BROKER_URL}/v2/entities/urn:ngsi-ld:LocationSensor:001" \
-H "Authorization: Bearer ${BROKER_TOKEN}"
-H "Authorization: Bearer ${BROKER_TOKEN}" \
-H "Fiware-Service: ${FIWARE_SERVICE}" \
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}"
```
17 changes: 14 additions & 3 deletions doc/examples/temperature_sensor.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Create the subscription template and publish it.
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:TemperatureSensor:001",
"type": "TemperatureSensor",
Expand All @@ -58,6 +60,8 @@ curl -iX POST "${BROKER_URL}/v2/entities" \
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:TemperatureSensor:002",
"type": "TemperatureSensor",
Expand All @@ -75,9 +79,11 @@ curl -iX PATCH \
"${BROKER_URL}/v2/entities/urn:ngsi-ld:TemperatureSensor:001/attrs" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${BROKER_TOKEN}" \
-H "Fiware-Service: ${FIWARE_SERVICE}" \
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}" \
-d '{
"temperature": {
"value": 28.0,
"value": 38.5,
"type": "Number"
}
}'
Expand All @@ -88,8 +94,13 @@ curl -iX PATCH \
```bash
curl -iX DELETE \
"${BROKER_URL}/v2/entities/urn:ngsi-ld:TemperatureSensor:001" \
-H "Authorization: Bearer ${BROKER_TOKEN}"
-H "Authorization: Bearer ${BROKER_TOKEN}" \
-H "Fiware-Service: ${FIWARE_SERVICE}" \
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}"

curl -iX DELETE \
"${BROKER_URL}/v2/entities/urn:ngsi-ld:TemperatureSensor:002" \
-H "Authorization: Bearer ${BROKER_TOKEN}"
-H "Authorization: Bearer ${BROKER_TOKEN}" \
-H "Fiware-Service: ${FIWARE_SERVICE}" \
-H "Fiware-ServicePath: ${FIWARE_SERVICEPATH}"
```
11 changes: 7 additions & 4 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ To allow **public** access to NGSI-LD context documents, it's necessary to grant
For all examples, the following environment variables are used:

```bash
export BROKER_URL="http://your_broker:1026"
export BROKER_URL=http://your_broker:1026
export BROKER_TOKEN=your_token
export FIWARE_SERVICE=your_service
export FIWARE_SERVICEPATH=your_servicepath
```

Replace `your_broker_url` with the actual URL of your FIWARE broker. After
running this command, the BROKER_URL environment variable will be
available to all subsequent commands in the same terminal session.
Alternatively, you can use `.env` files to set these variables.
Copy the `.env.example` file to `.env` and set the values accordingly.
Then run `source .env` to load the environment variables.

### General FIWARE Broker Commands

Expand Down
9 changes: 9 additions & 0 deletions doc/scripts/delete_all_subscriptions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ if [ -n "$BROKER_TOKEN" ]; then
HEADERS+=(-H "Authorization: Bearer $BROKER_TOKEN")
fi

# Check if FIWARE_SERVICE and FIWARE_SERVICEPATH are provided
if [ -z "$FIWARE_SERVICE" ]; then
HEADERS+=(-H "Fiware-Service: $FIWARE_SERVICE")
fi

if [ -z "$FIWARE_SERVICEPATH" ]; then
HEADERS+=(-H "Fiware-ServicePath: $FIWARE_SERVICEPATH")
fi

# Fetch all subscription IDs using a GET request
response=$(curl -s -o /dev/null -w "%{http_code}" -X GET "${BROKER_URL}/v2/subscriptions" "${HEADERS[@]}")
http_code="$response"
Expand Down
9 changes: 9 additions & 0 deletions doc/scripts/register_all_subscriptions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ if [ -n "$BROKER_TOKEN" ]; then
HEADERS+=(-H "Authorization: Bearer $BROKER_TOKEN")
fi

# Check if FIWARE_SERVICE and FIWARE_SERVICEPATH are provided
if [ -z "$FIWARE_SERVICE" ]; then
HEADERS+=(-H "Fiware-Service: $FIWARE_SERVICE")
fi

if [ -z "$FIWARE_SERVICEPATH" ]; then
HEADERS+=(-H "Fiware-ServicePath: $FIWARE_SERVICEPATH")
fi

# Fetch all subscriptions using a GET request
response=$(curl -s -o /dev/null -w "%{http_code}" -X GET "${BROKER_URL}/v2/subscriptions" "${HEADERS[@]}")
http_code="$response"
Expand Down
3 changes: 2 additions & 1 deletion doc/subscription_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ subscription, including entities, attributes, and (geospatial) queries.
all or none of the following fields:
- **Georel**: Set the geospatial relationship (e.g., `near;maxDistance:1000`).
- **Geometry**: Choose the geometry type (e.g., `Point`).
- **Coordinates**: Enter the coordinates for the geospatial query.
- **Coordinates**: Enter the coordinates (`latitude`,
`longitude`) for the geospatial query (e.g. `34.751,135.22;34.67,135.221;34.671,135.345;34.752,135.344;34.751,135.22`).
- **Insert project boundary**: Automatically insert the project boundary as
valid geospatial query.

Expand Down

0 comments on commit 48851f0

Please sign in to comment.