watering_07_subscribe_to_entity.sh 1.09 KB
Newer Older
1 2 3 4 5 6 7 8
#!/usr/bin/env bash

[[ -z "$ORION_HOST" ]] && echo "Please set ORION_HOST env var. E.g. export ORION_HOST=127.0.0.1" && exit
echo "Querying context broker at: ${ORION_HOST}"

[[ -z "$SUBSCRIPTION_URL" ]] && echo "Please set SUBSCRIPTION_URL env var. E.g. export SUBSCRIPTION_URL=http://172.18.1.11:5000/on_change_soilMoistureVwc" && exit
echo "Callback URL for subscriptions is: ${SUBSCRIPTION_URL}"

9
#doc: https://fiware-tutorials.readthedocs.io/en/latest/ld-subscriptions-registrations/index.html
10
curl --location --request POST \
11
    "http://$ORION_HOST:1026/ngsi-ld/v1/subscriptions/" \
12 13 14 15 16
    --header "Fiware-Service: carouge" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data '{
      "description": "A subscription to subscribe to FlowerBed.soilMoistureVwc",
17 18
      "type": "Subscription",
      "entities": [{"type": "FlowerBed"}],
19
      "notification": {
20
        "attributes": ["soilMoistureVwc"],
21
        "format": "normalized",
22 23 24 25 26
        "endpoint": {
          "uri": "'${SUBSCRIPTION_URL}'",
          "accept": "application/json"
        }
      }
27 28
    }'