简体   繁体   中英

Orion-QL subscription configuration

I have devices with many IoT-sensors. I want to batch read from these devices and batch write this data to CrateDB . 100 data is obtained from the sensors every 1 second.

How can I take, for example, 5 seconds of batch data (500 data) at once with the Quantum Leap agent and write it to CrateDB?Should I do this configuration in Orion-QL subscription (throttling etc)?

With NGSI-v2 batch update is achieved using the /v2/op/update endpoint eg :

curl -L -X POST 'http://localhost:1026/v2/op/update' \
-H 'Content-Type: application/json' \
--data-raw '{
  "actionType":"update",
  "entities":[
    {
      "id":"urn:ngsi-ld:Product:001", "type":"Product",
      "price":{"type":"Integer", "value": 1199}
    },
    {
      "id":"urn:ngsi-ld:Product:002", "type":"Product",
      "price":{"type":"Integer", "value": 1199},
      "size": {"type":"Text", "value": "L"}
    }
  ]
}'

With NGSI-LD you can use /ngsi-ld/v1/entityOperations/upsert :

curl -L -X POST 'http://localhost:1026/ngsi-ld/v1/entityOperations/upsert' \
-H 'Content-Type: application/json' \
-H 'Link: <http://path-to-context/ngsi-context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
-H 'Accept: application/ld+json' \
--data-raw '[
    {
      "id": "urn:ngsi-ld:TemperatureSensor:002",
      "type": "TemperatureSensor",
      "category": {
            "type": "Property",
            "value": "sensor"
      },
      "temperature": {
            "type": "Property",
            "value": 21,
            "unitCode": "CEL"
      }
    },
    {
      "id": "urn:ngsi-ld:TemperatureSensor:003",
      "type": "TemperatureSensor",
      "category": {
            "type": "Property",
            "value": "sensor"
      },
      "temperature": {
            "type": "Property",
            "value": 27,
            "unitCode": "CEL"
      }
    }
]'

You didn't state if your multisensor was capable of sending NGSI calls - if it can't send NGSI, but able to send batch readings in some other format, then you just need a microservice to do the conversion for you - an example can be found here on GitHub - commentary on the code can be found in the Video Tutorials from FIWARE Foundation.

Once you have safely send your device data in NGSI format, you can tackle the second half of your question. There are QuantumLeap tutorials for both NGSI-v2 and NGSI-LD , the key to them both is creating a subscription notifying of any changes.

NGSI-v2

curl -iX POST \
  'http://localhost:1026/v2/subscriptions/' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
  "description": "Notify QuantumLeap of count changes of any Motion Sensor",
  "subject": {
    "entities": [
      {
        "idPattern": "Motion.*"
      }
    ],
    "condition": {
      "attrs": [
        "count"
      ]
    }
  },
  "notification": {
    "http": {
      "url": "http://quantumleap:8668/v2/notify"
    },
    "attrs": [
      "count"
    ],
    "metadata": ["dateCreated", "dateModified"]
  }
}'

NGSI-LD

curl -L -X POST 'http://localhost:1026/ngsi-ld/v1/subscriptions/' \
-H 'Content-Type: application/ld+json' \
-H 'NGSILD-Tenant: openiot' \
--data-raw '{
  "description": "Notify me of all feedstock changes",
  "type": "Subscription",
  "entities": [{"type": "FillingLevelSensor"}],
  "watchedAttributes": ["filling"],
  "notification": {
    "attributes": ["filling", "location"],
    "format": "normalized",
    "endpoint": {
      "uri": "http://quantumleap:8668/v2/notify",
      "accept": "application/json"
    }
  },
   "@context": "http://path-to-context/ngsi-context.jsonld"
}'

The throttling parameter is not necessary unless you only want to sample the incoming data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM