简体   繁体   English

将特定实体发送到 FIWARE QuantumLeap

[英]Sending a specific entity to FIWARE QuantumLeap

In my application I have a very specific entity format, where one of the attributes' values is a json array of values.在我的应用程序中,我有一个非常具体的实体格式,其中一个属性的值是一个 json 值数组。

    {
        "id": "Proximity3",
        "type": "SensorAgent",
        "measurementType": {
            "type": "string",
            "value": "boolean",
            "metadata": {}
        },
        "modifiedTime": {
            "type": "string",
            "value": "2020-06-08T12:30:11.091506Z",
            "metadata": {}
        },
        "readings": {
            "type": "array",
            "value": [
                {
                    "type": "SensorReading",
                    "value": {
                        "reading": {
                            "type": "boolean",
                            "value": false
                        }
                    }
                }
            ],
            "metadata": {}
        },
        "sanID": {
            "type": "string",
            "value": "SAN_3",
            "metadata": {}
        },
        "sensorID": {
            "type": "string",
            "value": "Proximity3",
            "metadata": {}
        },
        "sensorManufacturer": {
            "type": "string",
            "value": "Unknown",
            "metadata": {}
        },
        "sensorType": {
            "type": "string",
            "value": "ON_OFF_SENSOR",
            "metadata": {}
        }
    }
] 

As you can see, readings attribute has an array of values stored in it (in this example only one.如您所见, readings属性有一个存储在其中的值数组(在此示例中只有一个。

Whenever I try to subscribe QuantumLeap to Orion Context Broker, subscription is successful, but there is no data received by QuantumLeap (even querying http://localhost:8668/v2/attrs gives me 'No records were found for such query.').每当我尝试将 QuantumLeap 订阅到 Orion Context Broker 时,订阅都是成功的,但 QuantumLeap 没有收到任何数据(即使查询http://localhost:8668/v2/attrs 也会给我“没有找到此类查询的记录。”) . Tried using attrFormat on subscription, but unsuccessful.尝试在订阅时使用 attrFormat,但不成功。

At the same time, this https://quantumleap.readthedocs.io/en/latest/user/ suggests that the QuantumLeap expects a specific entity.同时,这个https://quantumleap.readthedocs.io/en/latest/user/表明 QuantumLeap 需要一个特定的实体。 My question is, is there anything possible to do in order to get this entity to QuantumLeap, or I would need to change the entity?我的问题是,为了让这个实体进入 QuantumLeap,有什么可能做的,或者我需要更改实体?

It is clear from the QuantumLeap Data Insertion documentation that QuantumLeap expects the notification it receives to contain attributes passed as Native JSON types (like Number )从 QuantumLeap 数据插入文档中可以清楚地看出,QuantumLeap 期望它收到的通知包含作为原生 JSON 类型(如Number )传递的属性

"temperature": {
    "value": 24.2,
    "type": "Number",
    "metadata": {}
}

If your context broker holds attributes in a different way, direct notification will always fail, but there is nothing stopping you from proxying the notification and reformatting it in the manner that QuantumLeap prefers.如果您的上下文代理以不同的方式保存属性,直接通知将始终失败,但没有什么能阻止您代理通知并以 QuantumLeap 喜欢的方式重新格式化它。

Create a simple subscription listener to read the current subscription data, reformat the bits you need and forward to Quantum Leap and return the received HTTP success/failure back to the context broker.创建一个简单的订阅侦听器以读取当前订阅数据,重新格式化您需要的位并转发给 Quantum Leap,并将收到的 HTTP 成功/失败返回给上下文代理。

const request = require('request');

function receiver(req, res) {
  let data = [];

  // Manipulate the data
  req.body.data.readings.value.forEach((reading) => {
        data.push[reading.value]
  });
  // Copy the rest of data from the original subscription
  // Then Forward to QuantumLeap - replace with real values
  const options = {
      url: '/subscription/to/quantum/leap',
      method: 'POST',
      json: data,
      headers: 
    };

  // Respond back to context broker with response from QL
  request(options, (error, response, body) => {
      return error ? res.send(error) :  res.status(204).send();
  });

}

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

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