能否在Fiware中创建包含数组类型属性的实体?
pressure property of a Fiware Room entity to an array type? Absolutely, you can adjust your Fiware Room entity to use an array for the pressure property to capture readings from multiple sensors in a single update. This is fully supported by Fiware's NGSI specifications, and here's how you can implement it:
1. Updated Entity Structure
You can redefine the pressure property to have a type of Array, with its value being an array of sensor readings. You can either keep a consistent structure with your original single-value property, or add metadata to distinguish which reading comes from which sensor:
Basic Array Implementation
{ "id": "Room1", "type": "Room", "temperature": {"value": 23, "type": "Float"}, "pressure": { "value": [ {"value": 720, "type": "Integer"}, {"value": 722, "type": "Integer"}, {"value": 719, "type": "Integer"} ], "type": "Array" } }
Array with Sensor Metadata (Recommended)
To make the readings more actionable, include metadata like the sensor ID for each pressure value:
{ "id": "Room1", "type": "Room", "temperature": {"value": 23, "type": "Float"}, "pressure": { "value": [ { "value": 720, "type": "Integer", "metadata": {"sensorId": {"value": "PressureSensor_001", "type": "String"}} }, { "value": 722, "type": "Integer", "metadata": {"sensorId": {"value": "PressureSensor_002", "type": "String"}} } ], "type": "Array" } }
2. Key Considerations
- Consumer Compatibility: Make sure any applications consuming this entity data are updated to handle an array instead of a single
pressurevalue—your original setup used a scalar, so downstream logic will need adjustment. - NGSI Version Support: This approach works for both NGSI-v2 and NGSI-LD (the structure will be slightly different for LD, but array types are still fully supported).
- Consistency: Stick to a consistent structure for array elements to avoid parsing issues across your system.
This setup perfectly fits your use case of sending all pressure sensor data in one update message while adhering to Fiware's standards.
内容的提问来源于stack exchange,提问作者Peter Detzner

