简体   繁体   English

Orion-QL 订阅配置

[英]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 .我想从这些设备批量读取并将这些数据批量写入CrateDB 100 data is obtained from the sensors every 1 second.每 1 秒从传感器获取 100 个数据。

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)?例如,如何使用 Quantum Leap 代理一次获取5 秒的批处理数据(500 个数据)并将其写入 CrateDB?我应该在Orion-QL 订阅(节流等)中进行此配置吗?

With NGSI-v2 batch update is achieved using the /v2/op/update endpoint eg : NGSI-v2 批量更新是使用/v2/op/update端点实现的,例如:

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 :使用 NGSI-LD,您可以使用/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.您没有说明您的多传感器是否能够发送 NGSI 调用 - 如果它不能发送 NGSI,但能够以其他格式发送批量读数,那么您只需要一个微服务来为您进行转换 - 一个例子可以可在GitHub找到- 可以在 FIWARE Foundation 的视频教程中找到对代码的评论。

Once you have safely send your device data in NGSI format, you can tackle the second half of your question.一旦您以 NGSI 格式安全地发送设备数据,您就可以解决问题的后半部分。 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-v2NGSI-LD都有 QuantumLeap 教程,它们的关键是创建订阅通知任何更改。

NGSI-v2 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 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.除非您只想对传入数据进行采样,否则不需要throttling参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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