【问题标题】:Sending a specific entity to FIWARE QuantumLeap将特定实体发送到 FIWARE QuantumLeap
【发布时间】:2020-06-08 12:46:09
【问题描述】:

在我的应用程序中,我有一个非常具体的实体格式,其中一个属性的值是一个 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": {}
        }
    }
] 

如您所见,readings 属性中存储了一组值(在此示例中只有一个。

每当我尝试将 QuantumLeap 订阅到 Orion Context Broker 时,订阅都会成功,但 QuantumLeap 没有收到任何数据(即使查询 http://localhost:8668/v2/attrs 给我“没有找到此类查询的记录。”)。尝试在订阅时使用 attrFormat,但不成功。

同时,https://quantumleap.readthedocs.io/en/latest/user/ 暗示 QuantumLeap 需要一个特定的实体。 我的问题是,有什么办法可以让这个实体加入 QuantumLeap,或者我需要更改实体?

【问题讨论】:

  • @fgalan 也许你可以帮助我?

标签: json http fiware fiware-orion


【解决方案1】:

从 QuantumLeap Data Insertion 文档中可以清楚地看出,QuantumLeap 期望它收到的通知包含作为原生 JSON 类型传递的属性(如 Number

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

如果您的上下文代理以不同的方式保存属性,直接通知将始终失败,但没有什么能阻止您代理通知并以 QuantumLeap 喜欢的方式重新格式化。

创建一个简单的订阅监听器来读取当前订阅数据, 重新格式化您需要的位并转发到 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();
  });

}

【讨论】:

  • 感谢您的回复。是的,过了一段时间,除了这样的解决方案,我也想不出任何办法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多