Skip to content

Commit 9ed5a09

Browse files
authored
Merge branch 'telefonicaid:master' into fix/attribute-loss-when-updating-a-device
2 parents d9e6fdf + 6088e84 commit 9ed5a09

File tree

56 files changed

+929
-671
lines changed

Some content is hidden

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

56 files changed

+929
-671
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ jobs:
5151
strategy:
5252
matrix:
5353
node-version:
54-
- 14.x
5554
- 16.x
5655
- 18.x
5756
steps:

CHANGES_NEXT_RELEASE

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
- Upgrade express de from 4.19.2 to 4.20.0
1+
- Fix: set polling and transport for autoprovisioned devices
2+
- Add: option to force to use CB flow control with new API field useCBflowControl at group and device device level (#1420)
3+
- Add: useCBflowControl config setting (IOTA_CB_FLOW_CONTROL env var) to set CB flow control behaviour at instance level (#1420)
4+
- Add: allow remove last measure in device
5+
- Add: store last measure in device (by id, apikey, service and subservice) and new API field storeLastMeasure at group and device levels (#1669)
6+
- Add: storeLastMeasure config setting (IOTA_STORE_LAST_MEASURE env var) to set default store last measure behaviour at instance level (#1669)
7+
- Upgrade express dep from 4.19.2 to 4.21.2
8+
- Upgrade mongodb devdep from 4.17.1 to 4.17.2
9+
- Upgrade mongoose dep from 5.13.20 to 8.9.5 (solving vulnerabilies CVE-2024-53900 and CVE-2025-23061) (#1674)

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/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: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,8 @@ Config group is represented by a JSON object with the following fields:
17771777
| `payloadType` || string | | optional string value used to switch between **IoTAgent**, **NGSI-v2** and **NGSI-LD** measure payloads types. Possible values are: `iotagent`, `ngsiv2` or `ngsild`. The default is `iotagent`. |
17781778
| `transport` || `string` | | Transport protocol used by the group of devices to send updates, for the IoT Agents with multiple transport protocols. |
17791779
| `endpoint` || `string` | | Endpoint where the group of device is going to receive commands, if any. |
1780+
| `storeLastMeasure` || `boolean` | | Store in device last measure received. See more info [in this section](admin.md#storelastmeasure). False by default |
1781+
| `useCBflowControl` || `boolean` | | Use Context Broker flow control. See more info [in this section](admin.md#useCBflowControl). False by default |
17801782

17811783
### Config group operations
17821784

@@ -1996,8 +1998,10 @@ the API resource fields and the same fields in the database model.
19961998
| `internal_attributes` || `array` | | List of internal attributes with free format for specific IoT Agent configuration. |
19971999
| `explicitAttrs` || `boolean` || Field to support selective ignore of measures so that IOTA doesn’t progress. See details in [specific section](#explicitly-defined-attributes-explicitattrs) |
19982000
| `ngsiVersion` || `string` | | string value used in mixed mode to switch between **NGSI-v2** and **NGSI-LD** payloads. The default is `v2`. When not running in mixed mode, this field is ignored. |
1999-
| `payloadType` || `string` | | optional string value used to switch between **IoTAgent**, **NGSI-v2** and **NGSI-LD** measure payloads types. Possible values are: `iotagent`, `ngsiv2` or `ngsild`. The default is `iotagent`. |
2000-
2001+
| `payloadType` || `string` | | optional string value used to switch between **IoTAgent**, **NGSI-v2** and **NGSI-LD** measure payloads types. Possible values are: `iotagent`, `ngsiv2` or `ngsild`. The default is `iotagent`. |
2002+
| `storeLastMeasure` || `boolean` | | Store in device last measure received. See more info [in this section](admin.md#storelastmeasure). False by default. |
2003+
| `lastMeasure` || `object` | | last measure stored on device when `storeLastMeasure` is enabled. See more info [in this section](admin.md#storelastmeasure). This field can be cleared using `{}` in a device update request. In that case, `lastMeasure` is removed from device (until a next measure is received and `lastMesuare` gets created again). |
2004+
| `useCBflowControl` || `boolean` | | Use Context Broker flow control. See more info [in this section](admin.md#useCBflowControl). False by default. |
20012005
### Device operations
20022006

20032007
#### Retrieve devices /iot/devices `GET /iot/devices`

doc/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
mkdocs==1.2.4
22
Pygments==2.15.0
33
Markdown==3.3.4
4-
jinja2==3.1.4
4+
jinja2==3.1.5

lib/commonConfig.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ function processEnvironmentVariables() {
157157
'IOTA_FALLBACK_PATH',
158158
'IOTA_LD_SUPPORT_NULL',
159159
'IOTA_LD_SUPPORT_DATASET_ID',
160-
'IOTA_EXPRESS_LIMIT'
160+
'IOTA_EXPRESS_LIMIT',
161+
'IOTA_USE_CB_FLOW_CONTROL',
162+
'IOTA_STORE_LAST_MEASURE'
161163
];
162164
const iotamVariables = [
163165
'IOTA_IOTAM_URL',
@@ -350,6 +352,11 @@ function processEnvironmentVariables() {
350352
config.defaultResource = process.env.IOTA_DEFAULT_RESOURCE;
351353
}
352354

355+
// Default transport
356+
if (process.env.IOTA_DEFAULT_TRANSPORT !== undefined) {
357+
config.defaultTransport = process.env.IOTA_DEFAULT_TRANSPORT;
358+
}
359+
353360
// Default explicitAttrs
354361
if (process.env.IOTA_EXPLICIT_ATTRS !== undefined) {
355362
config.explicitAttrs = process.env.IOTA_EXPLICIT_ATTRS;
@@ -474,6 +481,16 @@ function processEnvironmentVariables() {
474481
} else {
475482
config.expressLimit = config.expressLimit ? config.expressLimit : '1mb';
476483
}
484+
if (process.env.IOTA_USE_CB_FLOW_CONTROL) {
485+
config.useCBflowControl = process.env.IOTA_USE_CB_FLOW_CONTROL === 'true';
486+
} else {
487+
config.useCBflowControl = config.useCBflowControl === true;
488+
}
489+
if (process.env.IOTA_STORE_LAST_MEASURE) {
490+
config.storeLastMeasure = process.env.IOTA_STORE_LAST_MEASURE === 'true';
491+
} else {
492+
config.storeLastMeasure = config.storeLastMeasure === true;
493+
}
477494
}
478495

479496
function setConfig(newConfig) {
@@ -503,7 +520,9 @@ function getConfigForTypeInformation() {
503520
multiCore: config.multiCore,
504521
relaxTemplateValidation: config.relaxTemplateValidation,
505522
defaultEntityNameConjunction: config.defaultEntityNameConjunction,
506-
defaultType: config.defaultType
523+
defaultType: config.defaultType,
524+
useCBflowControl: config.useCBflowControl,
525+
storeLastMeasure: config.storeLastMeasure
507526
};
508527
return conf;
509528
}

lib/model/Command.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ const Command = new Schema({
3434
creationDate: { type: Date, default: Date.now }
3535
});
3636

37-
function load(db) {
38-
module.exports.model = db.model('Command', Command);
37+
function load() {
38+
module.exports.model = mongoose.model('Command', Command);
3939
module.exports.internalSchema = Command;
4040
}
4141

lib/model/Device.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ const Device = new Schema({
5353
autoprovision: Boolean,
5454
explicitAttrs: Group.ExplicitAttrsType,
5555
ngsiVersion: String,
56-
payloadType: String
56+
payloadType: String,
57+
useCBflowControl: Boolean,
58+
storeLastMeasure: Boolean,
59+
lastMeasure: Object
5760
});
5861

59-
function load(db) {
60-
module.exports.model = db.model('Device', Device);
62+
function load() {
63+
module.exports.model = mongoose.model('Device', Device);
6164
module.exports.internalSchema = Device;
6265
}
6366

lib/model/Group.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ const Group = new Schema({
6565
defaultEntityNameConjunction: String,
6666
ngsiVersion: String,
6767
entityNameExp: String,
68-
payloadType: String
68+
payloadType: String,
69+
useCBflowControl: Boolean,
70+
storeLastMeasure: Boolean
6971
});
7072

71-
function load(db) {
73+
function load() {
7274
Group.index({ apikey: 1, resource: 1 }, { unique: true });
73-
module.exports.model = db.model('Group', Group);
75+
module.exports.model = mongoose.model('Group', Group);
7476
module.exports.internalSchema = Group;
7577
}
7678

0 commit comments

Comments
 (0)