historic_api_subscribe_to_flower_bed_carouge.sh 2.04 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
#!/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}"

# API NOTES:
# "condition": { "attrs": [] } -> means monitor all the attributes in the entity



# example of a FlowerBed (keyValues)
#        "id": "urn:ngsi-ld:FlowerBed:FlowerBed-3",
#        "type": "FlowerBed",
#        "category": [],
#        "dateLastWatering": "1970-01-01T01:00:00.00Z",
#        "depth": 0,
#        "flowerType": null,
#        "height": 0,
#        "location": [
#            "46.18777345077501, 6.141221902014418",
#            "46.18776394428967,6.1412558085139075",
#            "46.187460562531,6.141082986525166",
#            "46.18747273747444,6.141046425800975",
#            "46.18777345077501,6.141221902014418"
#        ],
#        "nextWateringAmountRecommendation": "1970-01-01T01:00:00.00Z",
#        "nextWateringDeadline": "1970-01-01T01:00:00.00Z",
#        "refDevice": "0018b20000020a7d",
#        "soilMoisture": 0,
#        "sunExposure": null,
#        "taxon": null,
#        "width": 0


curl --location --request POST \
    "http://$ORION_HOST:1026/v2/subscriptions/" \
    --header "Fiware-Service: carouge" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data '{
      "description": "Notify QuantumLeap, the historic API, of all FlowerBed changes",
      "subject": {
        "entities": [
          {
            "idPattern": ".*",
            "type": "FlowerBed"
          }
        ],
        "condition": {
          "attrs": ["category","dateLastWatering","nextWateringAmountRecommendation","nextWateringDeadline","refDevice","soilMoisture","taxon"]
        }
      },
      "notification": {
        "http": {
          "url": "http://172.18.1.7:8668/v2/notify"
        },
        "attrs": ["category","dateLastWatering","nextWateringAmountRecommendation","nextWateringDeadline","refDevice","soilMoisture","taxon"],
        "attrsFormat": "normalized",
        "metadata": ["dateModified"]
      }
}'