Skip to content

Commit d3d7cb1

Browse files
authored
Merge branch 'master' into fix/attribute-loss-when-updating-a-device
2 parents ced44b0 + 6bf855f commit d3d7cb1

File tree

69 files changed

+2589
-1077
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2589
-1077
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ jobs:
4545
runs-on: ubuntu-latest
4646
services:
4747
mongodb:
48-
image: mongo:6.0
48+
image: mongo:8.0
4949
ports:
5050
- 27017:27017
5151
strategy:
5252
matrix:
5353
node-version:
54-
- 14.x
5554
- 16.x
5655
- 18.x
5756
steps:
@@ -72,7 +71,7 @@ jobs:
7271
needs: unit-test
7372
services:
7473
mongodb:
75-
image: mongo:6.0
74+
image: mongo:8.0
7675
ports:
7776
- 27017:27017
7877
steps:

Changelog

Lines changed: 797 additions & 0 deletions
Large diffs are not rendered by default.

config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ var config = {
7777
providerUrl: 'http://192.168.56.1:4041',
7878
deviceRegistrationDuration: 'P1M',
7979
defaultType: 'Thing',
80-
expressLimit: '1Mb'
80+
expressLimit: '1Mb',
81+
useCBflowControl: false,
82+
storeLastMeasure: false
8183
};
8284

8385
module.exports = config;

doc/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Administration manual](admin.md)
88
- [Deprecated features](deprecated.md)
99
- [Roadmap](roadmap.md)
10+
- [Data models](models/models.md)
1011

1112
## Development documentation
1213

doc/admin.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ allowing the computer to interpret the rest of the data with more clarity and de
125125
```
126126

127127
Under mixed mode, **NGSI v2** payloads are used for context broker communications by default, but this payload may also
128-
be switched to **NGSI LD** at group or device provisioning time using the `ngsiVersion` field in the
129-
provisioning API. The `ngsiVersion` field switch may be added at either group or device level, with the device level
130-
overriding the group setting.
128+
be switched to **NGSI LD** at group or device provisioning time using the `ngsiVersion` field in the provisioning API.
129+
The `ngsiVersion` field switch may be added at either group or device level, with the device level overriding the group
130+
setting.
131131

132132
#### `server`
133133

@@ -306,7 +306,8 @@ added `agentPath`:
306306

307307
#### `types`
308308

309-
This parameter includes additional groups configuration as described into the [Config group API](api.md#config-group-api) section.
309+
This parameter includes additional groups configuration as described into the
310+
[Config group API](api.md#config-group-api) section.
310311

311312
#### `service`
312313

@@ -415,7 +416,38 @@ IotAgents, as all Express applications that use the body-parser middleware, have
415416
size that the application will handle. This default limit for ioiotagnets are 1Mb. So, if your IotAgent receives a
416417
request with a body that exceeds this limit, the application will throw a “Error: Request entity too large”.
417418

418-
The 1Mb default can be changed setting the `expressLimit` configuration parameter (or equivalente `IOTA_EXPRESS_LIMIT` environment variable).
419+
The 1Mb default can be changed setting the `expressLimit` configuration parameter (or equivalente `IOTA_EXPRESS_LIMIT`
420+
environment variable).
421+
422+
#### `storeLastMeasure`
423+
424+
If this flag is activated, last measure arrived to Device IoTAgent without be processed will be stored in Device under
425+
`lastMeasure` field (composed of sub-fields `timestamp` and `measure` for the measure itself, in multi-measure format).
426+
This flag is overwritten by `storeLastMeasure` flag in group or device. This flag is disabled by default.
427+
428+
For example in a device document stored in MongoDB will be extended with a subdocument named lastMeasure like this:
429+
430+
```json
431+
{
432+
"lastMeasure": {
433+
"timestamp": "2025-01-09T10:35:33.079Z",
434+
"measure": [
435+
[
436+
{
437+
"name": "level",
438+
"type": "Text",
439+
"value": 33
440+
}
441+
]
442+
]
443+
}
444+
}
445+
```
446+
447+
#### `useCBflowControl`
448+
449+
If this flag is activated, when iotAgent invokes Context Broker will use [flowControl option](https://github.com/telefonicaid/fiware-orion/blob/master/doc/manuals/admin/perf_tuning.md#updates-flow-control-mechanism). This flag is overwritten by
450+
`useCBflowControl` flag in group or device. This flag is disabled by default.
419451

420452
### Configuration using environment variables
421453

@@ -479,6 +511,8 @@ overrides.
479511
| IOTA_DEFAULT_ENTITY_NAME_CONJUNCTION | `defaultEntityNameConjunction` |
480512
| IOTA_RELAX_TEMPLATE_VALIDATION | `relaxTemplateValidation` |
481513
| IOTA_EXPRESS_LIMIT | `expressLimit` |
514+
| IOTA_STORE_LAST_MEASURE | `storeLastMeasure` |
515+
| IOTA_CB_FLOW_CONTROL | `useCBflowControl` |
482516

483517
Note:
484518

doc/api.md

Lines changed: 14 additions & 4 deletions
Large diffs are not rendered by default.

doc/devel/northboundinteractions.md

Lines changed: 122 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,8 @@ The registration of the commands is performed once in the lifetime of the Device
775775

776776
#### Command Execution
777777

778+
##### Based in update (classic way)
779+
778780
Scenario 3 begins with the request for a command from the User to the Context Broker (P1):
779781

780782
```bash
@@ -825,21 +827,8 @@ Fiware-Correlator: 9cae9496-8ec7-11e6-80fc-fa163e734aab
825827
}
826828
```
827829

828-
The IoT Agent detects the selected attribute is a command, and replies to the Context Broker with the following payload
829-
(200 OK):
830-
831-
```json
832-
[
833-
{
834-
"type": "device",
835-
"id": "Dev0001",
836-
"switch": {
837-
"type": "command",
838-
"value": ""
839-
}
840-
}
841-
]
842-
```
830+
The IoT Agent detects the selected attribute is a command, and replies to the Context Broker with a 204 OK (without
831+
payload).
843832

844833
This response just indicates that the IoT Agent has received the command successfully, and gives no information about
845834
the requested information or command execution.
@@ -862,6 +851,100 @@ The Context Broker, forwards the same response to the user, thus replying the or
862851
At this point, the command has been issued to the IoTAgent and the User doesn't still know what the result of its
863852
request will be.
864853

854+
##### Based in notification (new way)
855+
856+
A new way to ContextBroker provides a command to a IoTAgent is through notifications. In this case CB notify the command
857+
to the IotAgent with a request like the following:
858+
859+
```bash
860+
POST /notify HTTP/1.1
861+
Host: <target-host>:<northbound_port>
862+
fiware-service: workshop
863+
Fiware-ServicePath: /iota2ngsi
864+
Accept: application/json
865+
Content-length: 290
866+
Content-type: application/json; charset=utf-8
867+
Fiware-Correlator: 9cae9496-8ec7-11e6-80fc-fa163e734aab
868+
869+
{
870+
"subscriptionId": "60b0cedd497e8b681d40b58e",
871+
"data": [{
872+
"id": "123456abcdefg",
873+
"type": "switchOnOffExecution",
874+
"targetEntityId": {
875+
"type": "Text",
876+
"value": "Dev0001",
877+
"metadata": {}
878+
},
879+
"targetEntityType": {
880+
"type": "Text",
881+
"value": "device",
882+
"metadata": {}
883+
},
884+
"execTs": {
885+
"type": "DateTime",
886+
"value": "2020-05-27T00:00:00.000Z",
887+
"metadata": {}
888+
},
889+
"cmd": {
890+
"type": "Text",
891+
"value": "switch",
892+
"metadata": {}
893+
},
894+
"params": {
895+
"type": "Text",
896+
"value": "54, 12",
897+
"metadata": {}
898+
},
899+
"status": {
900+
"type": "Text",
901+
"value": "FORWARDED",
902+
"metadata": {}
903+
},
904+
"info": {
905+
"type": "Text",
906+
"value": null,
907+
"metadata": {}
908+
},
909+
"onDelivered": {
910+
"type": "Request",
911+
"value": {
912+
}
913+
},
914+
"onOk": {
915+
"type": "Request",
916+
"value": {
917+
}
918+
},
919+
"onError": {
920+
"type": "Request",
921+
"value": {
922+
}
923+
},
924+
"onInfo": {
925+
"type": "Request",
926+
"value": {
927+
}
928+
},
929+
"cmdExecution": {
930+
"type": "value",
931+
"value": true,
932+
"metadata": {}
933+
},
934+
"dateExpiration": {
935+
"type": "DateTime",
936+
"value": "2020-05-27T20:00:00.000Z",
937+
"metadata": {}
938+
}
939+
}]
940+
}
941+
```
942+
943+
In this case relevant fields are just `targetEntityId`, `targetEntityType`, `cmd` and `params`.
944+
945+
The IoT Agent detects the selected attribute is a command, and replies to the Context Broker with a 204 OK (without
946+
payload).
947+
865948
#### Result reporting
866949

867950
Once the IoT Agent has executed the command or retrieved the information from the device, it reports the results to the
@@ -955,6 +1038,30 @@ The Context Broker replies with all the desired data, in R2 format (200 OK):
9551038
]
9561039
```
9571040

1041+
#### Differences regarding the new commands mode
1042+
1043+
A new commands flow has been defined (involving also modifications at ContextBroker). As part of that design, commands
1044+
are not sent to IOTAs using NGSIv2 notifications, but the current implementation has some differences regarding the
1045+
desired behaviour, which are described next:
1046+
1047+
- Fields others than `targetEntityId`, `targetEntityType`, `cmd` and `params` (i.e. `execTs`, `status`, `info`,
1048+
`onDelivered`, `onOk`, `onError`, `onInfo`, `cmdExecution` and `dataExpiration`), are not actually used. By the
1049+
moment they are stored in the commands model (commands collection) but nothing is done with them appart from
1050+
storing.
1051+
- The "Result reporting" should not be a "hardwired" behaviour updating the entity associated to the device, but using
1052+
the corresponding `on*` attribute in the notificaiton (e.g. `onOk` in the case of success). That attribute would
1053+
typically be a [HATEOAS](https://en.wikipedia.org/wiki/HATEOAS) object like this
1054+
`"onOk": { "href": "/v2/entities/123456abcdefg/attrs/status?type=switchExecution", "method": "PUT" }`. Moreover, the
1055+
entity to be updated in that HATEOAS would be the transient entity corresponding to command execuion, not the entity
1056+
associated to the device.
1057+
1058+
```
1059+
PUT /v2/entities/123456abcdefg/attrs/status?type=switchExecution
1060+
content-type: text/plain
1061+
1062+
OK
1063+
```
1064+
9581065
### Scenario 3: commands (error)
9591066

9601067
In Scenario 3, errors can happen asynchronously, out of the main interactions. When the IoTAgent detects an error

0 commit comments

Comments
 (0)