简体   繁体   中英

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.

    {
        "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.

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.'). Tried using attrFormat on subscription, but unsuccessful.

At the same time, this https://quantumleap.readthedocs.io/en/latest/user/ suggests that the QuantumLeap expects a specific entity. 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?

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 )

"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.

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.

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();
  });

}

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