Skip to content

Commit

Permalink
Merge branch 'master' into task/set_default_notification_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega authored Feb 5, 2024
2 parents efd09df + e0d9fa0 commit 49e94aa
Show file tree
Hide file tree
Showing 17 changed files with 71 additions and 34 deletions.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- allow receive command notifications from CB (iotagent-node-lib#1455)
- Fix: default attribute type changed from 'string' to 'Text' (#810)
45 changes: 41 additions & 4 deletions docs/usermanual.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,47 @@ tools available online like [this one](https://string-functions.com/string-hex.a

It is possible report as a measure a NGSI-v2 or NGSI-LD payload when related device/group is configured with
`payloadType` `ngsiv2` or `ngsild`. In these cases payload is ingested as measure where entity attributes are measure
attributes and `id` and `type` are ignored, since `id` and `type` from device/group configuration provisioned are used,
as well as `actionType`.
attributes.

Examples of these `ngsiv2` payloads are the following ones:
Note that the entity ID and type in the measure are also include as attributes `measure_id` and `measure_type` as described
[here](https://github.dev/telefonicaid/iotagent-node-lib/doc/api.md#special-measures-and-attributes-names) (both using
attribute type `Text`). The ID and type of the entity updated at Context Broker is taken from device/group configuration or provision,

However, it is possible to use the same entity ID that the original one by using `entityNameExp`
at [device group provision](https://github.com/telefonicaid/iotagent-node-lib/blob/master/doc/api.md#config-group-datamodel), this way:

```
"entityNameExp": "measure_id"
```

The `actionType` used in the update sent to Context Broker is taken from the measure in the case that measure corresponds to
a NGSI-v2 batch update. In other cases (i.e. NGSI-LD or NGSI-v2 non-batch update), the `actionType` is the default one (`append`).

For instance, given an incoming **measure** as the follwing one:

```json
{
"id": "MyEntityId1",
"type": "MyEntityType1",
"attr1": { "type": "Text", "value": "MyAttr1Value"}
}
```

It would persist an entity into the Context Broker like the following one:

```json
{
"id":"MyProvisionID",
"type":"MyProvisionType",
"attr1": { "type": "Text", "value": "MyAttr1Value"},
"measure_id": {"type": "Text","value": "MyEntityId1"},
"measure_type":{"type": "Text","value": "MyEntityType1"}
}
```

The IoTA is able to ingest different types of `NGSI-V2` and `NGSI-LD` payloads like the following ones:

**NGSI-V2**

(1) NGSI-v2 batch update format:

Expand Down Expand Up @@ -171,7 +208,7 @@ Examples of these `ngsiv2` payloads are the following ones:
}
```

Example of these `ngsild` payloads are the following ones:
**NGSI-LD**

(1) NGSI-LD entities array format:

Expand Down
2 changes: 1 addition & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
TIMESTAMP_ATTRIBUTE: 'TimeInstant',
TIMESTAMP_TYPE_NGSI2: 'DateTime',

DEFAULT_ATTRIBUTE_TYPE: 'string',
DEFAULT_ATTRIBUTE_TYPE: 'Text',

COMMAND_STATUS_PENDING: 'PENDING',
COMMAND_STATUS_ERROR: 'ERROR',
Expand Down
5 changes: 2 additions & 3 deletions test/unit/ngsiv2/contextRequests/ngsildMeasure.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "AnMQTTDevice",
"actionType": {
"value": "APPEND",
"type": "string"
"type": "Text"
},
"entities": {
"value": [
Expand Down Expand Up @@ -45,7 +45,6 @@
]
}
],
"type": "string"
"type": "Text"
}
}

4 changes: 2 additions & 2 deletions test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"id": "Second MQTT Device",
"type": "AnMQTTDevice",
"measure_id": {
"type": "string",
"type": "Text",
"value": "urn:ngsi-ld:ParkingSpot:santander:daoiz_velarde_1_5:3"
},
"measure_type": {
"type": "string",
"type": "Text",
"value": "ParkingSpot"
},
"status": {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/ngsiv2/contextRequests/ngsildPayloadMeasure2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"id": "Second MQTT Device",
"type": "AnMQTTDevice",
"measure_id": {
"type": "string",
"type": "Text",
"value": "urn:ngsi-ld:ParkingSpot:santander:reyes_magos_1_1:1"
},
"measure_type": {
"type": "string",
"type": "Text",
"value": "ParkingSpot"
},
"status": {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/ngsiv2/contextRequests/ngsiv2Measure.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type":"AnMQTTDevice",
"actionType": {
"value": "APPEND",
"type": "string"
"type": "Text"
},
"entities": {
"value": [
Expand Down Expand Up @@ -56,6 +56,6 @@
}
}
],
"type": "string"
"type": "Text"
}
}
4 changes: 2 additions & 2 deletions test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"id":"Second MQTT Device",
"type":"AnMQTTDevice",
"measure_id": {
"type": "string",
"type": "Text",
"value": "urn:ngsiv2:Streetlight:Streetlight-Mylightpoint-2"
},
"measure_type": {
"type": "string",
"type": "Text",
"value": "Streetlight"
},
"name": {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/ngsiv2/contextRequests/ngsiv2PayloadMeasure2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"id": "Second MQTT Device",
"type": "AnMQTTDevice",
"measure_id": {
"type": "string",
"type": "Text",
"value": "urn:ngsiv2:Streetlight:Streetlight-Mylightpoint-3"
},
"measure_type": {
"type": "string",
"type": "Text",
"value": "Streetlight"
},
"name": {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ngsiv2/contextRequests/pollingMeasure.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id":"Second MQTT Device",
"type":"AnMQTTDevice",
"a": {
"type": "string",
"type": "Text",
"value": 23
}
}
2 changes: 1 addition & 1 deletion test/unit/ngsiv2/contextRequests/timeInstantMeasures3.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"value": "111222"
},
"pressure":{
"type": "string",
"type": "Text",
"value": "20"
},
"TimeInstant":{
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ngsiv2/contextRequests/unknownMeasures.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"value": "32"
},
"weight":{
"type": "string",
"type": "Text",
"value": "87"
}
}
2 changes: 1 addition & 1 deletion test/unit/ngsiv2/contextRequests/unknownMeasures2.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"value": "33"
},
"weight":{
"type": "string",
"type": "Text",
"value": "89"
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit/ngsiv2/contextRequests/unprovisionedDevice.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"id":"TheLightType:JSON_UNPROVISIONED",
"type":"TheLightType",
"humidity":{
"type": "string",
"type": "Text",
"value": "32"
},
"temperature":{
"type": "string",
"type": "Text",
"value": "87"
}
}
4 changes: 2 additions & 2 deletions test/unit/ngsiv2/contextRequests/unprovisionedDevice2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"id":"TheLightType:JSON_UNPROVISIONED",
"type":"TheLightType",
"humidity":{
"type": "string",
"type": "Text",
"value": "33"
},
"temperature":{
"type": "string",
"type": "Text",
"value": "89"
}
}
2 changes: 1 addition & 1 deletion test/unit/ngsiv2/contextRequests/unprovisionedDevice3.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "TheLightType:JSON_UNPROVISIONED",
"type": "TheLightType",
"h":{
"type": "string",
"type": "Text",
"value": "33"
}
}
14 changes: 7 additions & 7 deletions test/unit/ngsiv2/explicit_attributes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ describe('explicitAttrs tests', function () {
.post('/v2/entities?options=upsert', {
id: 'Sensor:Temperature:JSON_UNPROVISIONED',
type: 'Sensor:Temperature',
h: { type: 'string', value: '33' },
h: { type: 'Text', value: '33' },
temperature: { type: 'Number', value: '89' }
})
.reply(204);
Expand Down Expand Up @@ -434,7 +434,7 @@ describe('explicitAttrs tests', function () {
.post('/v2/entities?options=upsert', {
id: 'Sensor:Temperature:JSON_UNPROVISIONED',
type: 'Sensor:Temperature',
h: { type: 'string', value: '33' },
h: { type: 'Text', value: '33' },
temperature: { type: 'Number', value: '89' }
})
.reply(204);
Expand Down Expand Up @@ -506,7 +506,7 @@ describe('explicitAttrs tests', function () {
.post('/v2/entities?options=upsert', {
id: 'Sensor:Temperature:JSON_UNPROVISIONED',
type: 'Sensor:Temperature',
h: { type: 'string', value: '33' },
h: { type: 'Text', value: '33' },
temperature: { type: 'Number', value: '89' }
})
.reply(204);
Expand Down Expand Up @@ -652,7 +652,7 @@ describe('explicitAttrs tests', function () {
.post('/v2/entities?options=upsert', {
id: 'Sensor:Temperature:JSON_UNPROVISIONED',
type: 'Sensor:Temperature',
h: { type: 'string', value: '33' },
h: { type: 'Text', value: '33' },
temperature: { type: 'Number', value: '89' }
})
.reply(204);
Expand Down Expand Up @@ -699,7 +699,7 @@ describe('explicitAttrs tests', function () {
.post('/v2/entities?options=upsert', {
id: 'Sensor:Temperature:JSON_UNPROVISIONED',
type: 'Sensor:Temperature',
h: { type: 'string', value: '33' },
h: { type: 'Text', value: '33' },
temperature: { type: 'Number', value: '89' }
})
.reply(204);
Expand Down Expand Up @@ -771,7 +771,7 @@ describe('explicitAttrs tests', function () {
.post('/v2/entities?options=upsert', {
id: 'Sensor:Temperature:JSON_UNPROVISIONED',
type: 'Sensor:Temperature',
h: { type: 'string', value: '33' },
h: { type: 'Text', value: '33' },
temperature: { type: 'Number', value: '89' }
})
.reply(204);
Expand Down Expand Up @@ -917,7 +917,7 @@ describe('explicitAttrs tests', function () {
.post('/v2/entities?options=upsert', {
id: 'Sensor:Temperature:JSON_UNPROVISIONED',
type: 'Sensor:Temperature',
h: { type: 'string', value: '33' },
h: { type: 'Text', value: '33' },
temperature: { type: 'Number', value: '89' }
})
.reply(204);
Expand Down

0 comments on commit 49e94aa

Please sign in to comment.