Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add metadata to ngsild payload measure + doc #780

Merged
merged 18 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/usermanual.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ Example of these `ngsild` payloads are the following ones:
}
```

Note that array of entities are handled as a multiple measure, each entity is a measure.
Some additional considerations to take into account:

- In the case of array of entities, they are handled as a multiple measure, i.e. each entity is a measure.
- In the case of NGSI-LD, fields different from `type` or `value` (e.g. `observedAt` in the examples above) are include as NGSI-v2 metadata in the entity corresponding to the measure at Context Broker.

##### SOAP-XML Measure reporting

Expand Down
9 changes: 9 additions & 0 deletions lib/commonBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ function extractAttributes(device, current, payloadType) {
ent.value = entity[k].object;
}
}
// Add other stuff as metadata
for (let key in entity[k]) {
if (!['type', 'value', 'object'].includes(key.toLowerCase())) {
AlvaroVega marked this conversation as resolved.
Show resolved Hide resolved
if (!ent.metadata) {
ent.metadata = {};
}
ent.metadata[key] = entity[k][key];
}
}
}
valuesEntity.push(ent);
}
Expand Down
5 changes: 4 additions & 1 deletion test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"type": "AnMQTTDevice",
"status": {
"type": "Property",
"value": "free"
"value": "free",
"metadata": {
"observedAt":"2018-09-21T12:00:00Z"
}
},
"category": {
"type": "Property",
Expand Down
5 changes: 4 additions & 1 deletion test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure2.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
"type": "AnMQTTDevice",
"status": {
"type": "Property",
"value": "free"
"value": "free",
"metadata": {
"observedAt":"2012-09-21T12:00:00Z"
}
AlvaroVega marked this conversation as resolved.
Show resolved Hide resolved
},
"category": {
"type": "Property",
Expand Down
Loading