iotagent-node-lib 4.5.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +67 -272
- package/doc/README.md +1 -1
- package/doc/admin.md +3 -15
- package/doc/api.md +469 -134
- package/doc/deprecated.md +4 -0
- package/doc/devel/architecture.md +5 -135
- package/doc/devel/development.md +224 -12
- package/doc/getting-started.md +114 -53
- package/doc/roadmap.md +5 -5
- package/docker/Mosquitto/Dockerfile +2 -2
- package/docker/Mosquitto/README.md +14 -11
- package/lib/constants.js +3 -0
- package/lib/fiware-iotagent-lib.js +12 -15
- package/lib/jexlTranformsMap.js +3 -1
- package/lib/model/dbConn.js +1 -4
- package/lib/services/common/alarmManagement.js +3 -0
- package/lib/services/groups/groupService.js +1 -1
- package/lib/services/ngsi/entities-NGSI-LD.js +320 -570
- package/lib/services/ngsi/entities-NGSI-v2.js +36 -1
- package/lib/services/ngsi/ngsiService.js +3 -1
- package/lib/services/northBound/deviceGroupAdministrationServer.js +42 -6
- package/lib/services/northBound/deviceProvisioningServer.js +0 -1
- package/lib/services/northBound/northboundServer.js +2 -0
- package/lib/services/stats/statsRegistry.js +128 -101
- package/lib/templates/createDevice.json +0 -24
- package/lib/templates/createDeviceLax.json +0 -23
- package/lib/templates/deviceGroup.json +1 -25
- package/lib/templates/updateDevice.json +0 -24
- package/lib/templates/updateDeviceLax.json +0 -23
- package/package.json +2 -2
- package/scripts/legacy_expression_tool/README.md +0 -1
- package/test/functional/README.md +22 -17
- package/test/functional/functional-tests-runner.js +9 -4
- package/test/functional/functional-tests.js +4 -4
- package/test/functional/testCases.js +245 -4
- package/test/unit/examples/deviceProvisioningRequests/provisionFullDevice.json +1 -13
- package/test/unit/examples/groupProvisioningRequests/multipleConfigGroupsCreation.json +44 -0
- package/test/unit/examples/groupProvisioningRequests/provisionDuplicateConfigGroup.json +35 -0
- package/test/unit/examples/groupProvisioningRequests/provisionFullConfigGroup.json +36 -0
- package/test/unit/examples/groupProvisioningRequests/provisionFullConfigGroupAlternate.json +36 -0
- package/test/unit/general/deviceService-test.js +102 -0
- package/test/unit/general/statistics-service_test.js +1 -74
- package/test/unit/mongodb/mongodb-configGroup-registry-test.js +452 -0
- package/test/unit/mongodb/mongodb-connectionoptions-test.js +2 -3
- package/test/unit/mongodb/mongodb-group-registry-test.js +34 -33
- package/test/unit/mongodb/mongodb-service-registry-test.js +477 -0
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin1a.json +4 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin2.json +22 -22
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin29.json +4 -4
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextExpressionPlugin32.json +14 -15
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin1.json +23 -23
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin15.json +0 -5
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin4.json +11 -16
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin5.json +23 -28
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin6.json +8 -13
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin7.json +0 -5
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityPlugin8.json +24 -29
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +12 -17
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextStaticLinkedAttributes.json +12 -10
- package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +0 -102
- package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +4 -5
- package/test/unit/ngsi-ld/provisioning/listProvisionedDevices-test.js +0 -4
- package/test/unit/ngsiv2/general/deviceService-test.js +94 -1
- package/test/unit/ngsiv2/general/iotam-autoregistration-test.js +195 -0
- package/test/unit/ngsiv2/provisioning/device-group-api-test.js +259 -0
- package/test/unit/ngsiv2/provisioning/device-provisioning-configGroup-api_test.js +1189 -0
- package/test/unit/ngsiv2/provisioning/listProvisionedDevices-test.js +0 -4
- package/test/unit/statsRegistry/openmetrics-test.js +167 -0
- package/lib/templates/queryContext.json +0 -25
- package/test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json +0 -35
- package/test/unit/examples/deviceProvisioningRequests/provisionDeviceBidirectionalGroup.json +0 -17
- package/test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json +0 -31
- package/test/unit/general/statistics-persistence_test.js +0 -121
- package/test/unit/ngsi-ld/examples/contextRequests/createBidirectionalDevice.json +0 -17
- package/test/unit/ngsi-ld/examples/contextRequests/updateContextProcessTimestamp.json +0 -12
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotification.json +0 -13
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithDatasetId.json +0 -21
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +0 -17
- package/test/unit/ngsi-ld/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -23
- package/test/unit/ngsi-ld/plugins/timestamp-processing-plugin_test.js +0 -132
- package/test/unit/ngsiv2/examples/contextRequests/createBidirectionalDevice.json +0 -8
- package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotification.json +0 -13
- package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalNotificationWithMetadata.json +0 -19
- package/test/unit/ngsiv2/examples/subscriptionRequests/bidirectionalSubscriptionRequest.json +0 -24
package/doc/deprecated.md
CHANGED
|
@@ -25,6 +25,9 @@ A list of deprecated features and the version in which they were deprecated foll
|
|
|
25
25
|
- Support to legacy expressions (finally removed in 3.2.0)
|
|
26
26
|
- Bidirectinal pluging (finally removed in 3.4.0)
|
|
27
27
|
- appendMode configuration (`IOTA_APPEND_MODE` env var) (finally removed in 3.4.0)
|
|
28
|
+
- `config.stats` section, and push-mode statistics.
|
|
29
|
+
- Services API routes (`/iot/services`) in favor of the `/iot/groups`. Both are still supported, but the former is
|
|
30
|
+
deprecated.
|
|
28
31
|
|
|
29
32
|
The use of Node.js v14 is highly recommended.
|
|
30
33
|
|
|
@@ -57,3 +60,4 @@ The following table provides information about the last iotagent-node-lib versio
|
|
|
57
60
|
| Support to Legacy Expressions | 3.1.0 | April 25th, 2023 |
|
|
58
61
|
| bidirectional plugin | 3.3.0 | August 24th, 2023 |
|
|
59
62
|
| appendMode configuration (`IOTA_APPEND_MODE` env var) | 3.3.0 | August 24th, 2023 |
|
|
63
|
+
| push-mode stats | 4.5.0 | June 11th, 2024 |
|
|
@@ -4,31 +4,6 @@ The following section defines the architecture and message flow which is common
|
|
|
4
4
|
|
|
5
5
|
### Device to NGSI Mapping
|
|
6
6
|
|
|
7
|
-
Each Device will be mapped as an Entity associated to a Context Provider: the Device ID will be mapped by default to the
|
|
8
|
-
entity ID and the type of the entity will be selected by the IoT Agent in a protocol-dependent way (e.g: with different
|
|
9
|
-
URLs for different types). Both the name and type will be configurable by the user, either by type configuration or with
|
|
10
|
-
the device preprovisioning.
|
|
11
|
-
|
|
12
|
-
Each of the measures obtained from the device should be mapped to a different attribute. The name and type of the
|
|
13
|
-
attribute will be configured by the user (globally for all the types in the IoT Agent configuration or in a per device
|
|
14
|
-
basis preprovisioning the devices). Device measures can have three different behaviors:
|
|
15
|
-
|
|
16
|
-
- **Active attributes**: are measures that are pushed from the device to the IoT agent. This measure changes will be
|
|
17
|
-
sent to the Context Broker as updateContext requests over the device entity. NGSI queries to the context broker will
|
|
18
|
-
be resolved in the Broker database.
|
|
19
|
-
|
|
20
|
-
- **Lazy attributes**: some sensors will be passive, and will wait for the IoT Agent to request for data. For those
|
|
21
|
-
measures, the IoT Agent will register itself in the Context Broker as a Context Provider (for all the lazy measures
|
|
22
|
-
of that device), so if any component asks the Context Broker for the value of that sensor, its request will be
|
|
23
|
-
redirected to the IoT Agent (that behaves as a NGSI10 Context Provider). This operation will be synchronous from the
|
|
24
|
-
customer perspective: the Context Broker won't return a response until the device has returned its response to the
|
|
25
|
-
IoT Agent.
|
|
26
|
-
|
|
27
|
-
- **Commands**: in this case, the interaction will begin by setting an attribute in the device's entity, for which the
|
|
28
|
-
IoT Agent will be regitered as CP. The IoT Agent will return an immediate response to the Context Broker, and will
|
|
29
|
-
be held responsible of contacting the device to perform the command itself, updating special `status` and `info`
|
|
30
|
-
attributes in the entity as soon as it has any information of the command progress.
|
|
31
|
-
|
|
32
7
|
The following sequence diagram shows the different NGSI interactions an IoT Agent makes with the Context Broker,
|
|
33
8
|
explained in the following subsections (using the example of a OMA Lightweight M2M device).
|
|
34
9
|
|
|
@@ -38,7 +13,7 @@ Be aware that the IoT Agents are only required to support NGSI10 operations `upd
|
|
|
38
13
|
standard formats (currently in JSON format; XML deprecated) but will not answer to NGSI9 operations (or NGSI convenience
|
|
39
14
|
operations of any kind).
|
|
40
15
|
|
|
41
|
-
####
|
|
16
|
+
#### Config groups and Device provisioning information
|
|
42
17
|
|
|
43
18
|
In order for a device to connect to the IoT Agent, the device should be provisioned (although there may be occasions
|
|
44
19
|
where this registration is not needed). The provision process is meant to provide the IoT Agent with the following
|
|
@@ -58,27 +33,15 @@ information:
|
|
|
58
33
|
In order to provide this information, the IoT Agent Northbound API provides two resources: Device and Configuration
|
|
59
34
|
provisioning.
|
|
60
35
|
|
|
61
|
-
**
|
|
62
|
-
the same set of information for every device. Custom APIKeys can be only provided with the use of
|
|
36
|
+
**Config groups** may be used when a set of similar devices will be connected to the IoT Agent, to avoid provisioning
|
|
37
|
+
the same set of information for every device. Custom APIKeys can be only provided with the use of config group for
|
|
63
38
|
device groups. When a device is provisioned, it is assigned to a configuration _if there is one that matches its type,
|
|
64
39
|
its service and its subservice_. In that case, all the default information in the Configuration is merged with the
|
|
65
40
|
device information to create the definitive Device object that will be stored in the system.
|
|
66
41
|
|
|
67
|
-
Particular IoT Agents _may_ support autoregistration of devices into
|
|
42
|
+
Particular IoT Agents _may_ support autoregistration of devices into config groups, if enough information is given from
|
|
68
43
|
the Southbound.
|
|
69
44
|
|
|
70
|
-
#### Configurations and subservices
|
|
71
|
-
|
|
72
|
-
Configurations are meant to be a mean of simplifying the device provisioning for groups of very similar devices.
|
|
73
|
-
Considering that different groups of devices may be created in the same subservice that may require different
|
|
74
|
-
configurations, multiple configurations are allowed for each subservice. Considering the key in the association between
|
|
75
|
-
Device and Configuration was the triplet (service, subservice, type), all of these elements are considered mandatory.
|
|
76
|
-
|
|
77
|
-
This statement doesn't hold true for older IoT Agents, though. In older versions of the IoT Agents, each device
|
|
78
|
-
configuration was assigned to a particular subservice and just one configuration was allowed per subservice, so the
|
|
79
|
-
relation between a Device and a Configuration didn't need the type to discriminate between Configurations. That's why
|
|
80
|
-
for those agents, type was not a mandatory parameter.
|
|
81
|
-
|
|
82
45
|
#### Registration
|
|
83
46
|
|
|
84
47
|
Whenever a device is registered, the IoT Agent reads the device's entity information from the request or, if that
|
|
@@ -103,7 +66,7 @@ response to the caller, transparently.
|
|
|
103
66
|
|
|
104
67
|
**IMPORTANT NOTE:** at the present moment, commands (both push and poll) are supported only in the case of explicitly
|
|
105
68
|
provisioned agents. For autoprovisioned agents commands are not currently supported, although
|
|
106
|
-
[an issue](https://github.com/telefonicaid/
|
|
69
|
+
[an issue](https://github.com/telefonicaid/iotagent-node-lib/issues/572) has been created about this functionality.
|
|
107
70
|
|
|
108
71
|
Commands are modelled as updates over a lazy attribute. As in the case of the lazy attributes, updates over a command
|
|
109
72
|
will be forwarded by the Context Broker to the IoT Agent, that will in turn interact with the device to perform the
|
|
@@ -153,52 +116,6 @@ taking too much to pick them up. See the configuration section for details.
|
|
|
153
116
|
The library does not deal with protocol transformation or South Bound communications for neither of the command types
|
|
154
117
|
(that's the task for those specific IoT Agents using the library).
|
|
155
118
|
|
|
156
|
-
##### NGSI-LD `datasetId` support
|
|
157
|
-
|
|
158
|
-
Limited support for parsing the NGSI-LD `datasetId` attribute is included within the library. A series of sequential
|
|
159
|
-
commands for a single attribute can be sent as an NGSI-LD PATCH payload as follows:
|
|
160
|
-
|
|
161
|
-
```json
|
|
162
|
-
{
|
|
163
|
-
"lampColor": [
|
|
164
|
-
{
|
|
165
|
-
"type": "Property",
|
|
166
|
-
"value": { "color": "green", "duration": "55 secs" },
|
|
167
|
-
"datasetId": "urn:ngsi-ld:Sequence:do-this"
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
"type": "Property",
|
|
171
|
-
"value": { "color": "red", "duration": "10 secs" },
|
|
172
|
-
"datasetId": "urn:ngsi-ld:Sequence:then-do-this"
|
|
173
|
-
}
|
|
174
|
-
]
|
|
175
|
-
}
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
This results in the following sequential array of attribute updates to be sent to the `UpdateHandler` of the IoT Agent
|
|
179
|
-
itself:
|
|
180
|
-
|
|
181
|
-
```json
|
|
182
|
-
[
|
|
183
|
-
{
|
|
184
|
-
"name": "lampColor",
|
|
185
|
-
"type": "Property",
|
|
186
|
-
"datasetId": "urn:ngsi-ld:Sequence:do-this",
|
|
187
|
-
"metadata": {},
|
|
188
|
-
"value": { "color": "green", "duration": "55 secs" }
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
"name": "lampColor",
|
|
192
|
-
"type": "Property",
|
|
193
|
-
"datasetId": "urn:ngsi-ld:Sequence:then-do-this",
|
|
194
|
-
"metadata": {},
|
|
195
|
-
"value": { "color": "red", "duration": "10 secs" }
|
|
196
|
-
}
|
|
197
|
-
]
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
The equivalent for NGSI-v2 is not required since `datasetId` syntax is not supported by NGSI-v2.
|
|
201
|
-
|
|
202
119
|
#### Active attributes
|
|
203
120
|
|
|
204
121
|
Whenever a device proactively sends a message to the IoT Agent, it should transform its data to the appropriate NGSI
|
|
@@ -243,50 +160,3 @@ The following figure offers a graphical example of how a COAP IoT Agent work, or
|
|
|
243
160
|
device to a command update to the device.
|
|
244
161
|
|
|
245
162
|

|
|
246
|
-
|
|
247
|
-
### The `TimeInstant` element
|
|
248
|
-
|
|
249
|
-
As part of the device to entity mapping process the IoT Agent creates and updates automatically a special timestamp.
|
|
250
|
-
This timestamp is represented as two different properties of the mapped entity::
|
|
251
|
-
|
|
252
|
-
- With NGSI-v2, an attribute metadata named `TimeInstant` (per dynamic attribute mapped, which captures as an ISO8601
|
|
253
|
-
timestamp when the associated measurement (represented as attribute value) was observed. With NGSI-LD, the Standard
|
|
254
|
-
`observedAt` property-of-a-property is used instead.
|
|
255
|
-
|
|
256
|
-
- For NGSI-v2 only, an additional attribute `TimeInstant` is added to the entity which captures as an ISO8601
|
|
257
|
-
timestamp when the last measurement received from the device was observed.
|
|
258
|
-
|
|
259
|
-
If no information about the measurement timestamp is received by the IoT Agent, the arrival time of the measurement will
|
|
260
|
-
be used to generate a `TimeInstant` for both the entity attribute and the attribute metadata.
|
|
261
|
-
|
|
262
|
-
Take into account that:
|
|
263
|
-
|
|
264
|
-
- the timestamp of different attributes belonging to the same measurement record may not be equal.
|
|
265
|
-
- the arrival time and the measurement timestamp will not be the same in the general case.
|
|
266
|
-
- if `timezone` field is defined as part of the provisioning of the device or group, timestamp fields will be
|
|
267
|
-
generated using it. For instance, if `timezone` is set to `America/Los_Angeles`, a possible timestamp could be
|
|
268
|
-
`2025-08-05T00:35:01.468-07:00`. If `timezone` field is not defined, by default Zulu Time Zone (UTC +0) will be
|
|
269
|
-
used. Following the previous example, timestamp could be `2015-08-05T07:35:01.468Z`.
|
|
270
|
-
|
|
271
|
-
E.g.: in the case of a device that can take measurements every hour of both temperature and humidity and sends the data
|
|
272
|
-
once every day, at midnight, the `TimeInstant` reported for each measurement will be the hour when that measurement was
|
|
273
|
-
observed (e.g. 4:00 PM), while all the measurements will have an arrival time around midnight. If no timestamps were
|
|
274
|
-
reported with such measurements, the `TimeInstant` attribute would take those values around midnight.
|
|
275
|
-
|
|
276
|
-
This functionality can be turned on and off through the use of the `timestamp` configuration flag (described in the
|
|
277
|
-
configuration), as well as 'timestamp' flag in device or group provision.
|
|
278
|
-
|
|
279
|
-
### Implementation decisions
|
|
280
|
-
|
|
281
|
-
Given the aforementioned requirements, there are some aspects of the implementation that were chosen, and are
|
|
282
|
-
particularly under consideration:
|
|
283
|
-
|
|
284
|
-
- Aside from its configuration, the IoT Agent Lib is considered to be stateless. To be precise, the library mantains a
|
|
285
|
-
state (the list of entities/devices whose information the agent can provide) but that state is considered to be
|
|
286
|
-
transient. It's up to the particular implementation of the agent to consider whether it should have a persistent
|
|
287
|
-
storage to hold the device information (so the internal list of devices is read from a DB) or to register the
|
|
288
|
-
devices each time a device sends a measure. To this extent, two flavours of the Device Registry has been provided: a
|
|
289
|
-
transient one (In-memory Registry) and a persistent one (based in MongoDB).
|
|
290
|
-
- The IoT Agent does not care about the origin of the data, its type or structure. The mapping from raw data to the
|
|
291
|
-
entity model, if there is any, is a responsibility of the particular IoT Agent implementation, or of another third
|
|
292
|
-
party library.
|
package/doc/devel/development.md
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
- [Function reference](#function-reference)
|
|
25
25
|
- [Generic middlewares](#generic-middlewares)
|
|
26
26
|
- [DB Models from API document](#db-models-from-api-document)
|
|
27
|
-
- [
|
|
27
|
+
- [Config group model](#config-group-model)
|
|
28
28
|
- [Device model](#device-model)
|
|
29
29
|
- [Developing a new IoT Agent](#developing-a-new-iot-agent)
|
|
30
30
|
- [Protocol](#protocol)
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
- [IoT Agent in multi-thread mode](#iot-agent-in-multi-thread-mode)
|
|
38
38
|
- [Configuration management](#configuration-management)
|
|
39
39
|
- [Provisioning handlers](#provisioning-handlers)
|
|
40
|
+
- [IoT Agent additional tools](#iot-agent-additional-tools)
|
|
40
41
|
|
|
41
42
|
## Preface
|
|
42
43
|
|
|
@@ -226,18 +227,20 @@ npm run prettier:text
|
|
|
226
227
|
|
|
227
228
|
### Stats Registry
|
|
228
229
|
|
|
229
|
-
The library provides a mechanism for the
|
|
230
|
-
|
|
231
|
-
[Configuration](../admin.md#configuration) section.
|
|
232
|
-
|
|
233
|
-
The Stats Registry holds two dictionaries, with the same set of stats. For each stat, one of the dictionaries holds the
|
|
234
|
-
historical global value and the other one stores the value since the last value reporting (or current value).
|
|
230
|
+
The library provides a mechanism for the collection of stats related to the library's work. The Stats Registry holds a
|
|
231
|
+
dictionary with the historical global value of each stat.
|
|
235
232
|
|
|
236
233
|
The stats library currently stores only the following values:
|
|
237
234
|
|
|
238
235
|
- **deviceCreationRequests**: number of Device Creation Requests that arrived to the API (no matter the result).
|
|
239
236
|
- **deviceRemovalRequests**: number of Removal Device Requests that arrived to the API (no matter the result).
|
|
240
237
|
- **measureRequests**: number of times the ngsiService.update() function has been invoked (no matter the result).
|
|
238
|
+
- **raiseAlarm**: number of times the alarmManagement.raise() function has been invoked.
|
|
239
|
+
- **releaseAlarm**: number of times the alarmManagement.release() function has been invoked.
|
|
240
|
+
- **updateEntityRequestsOk**: number of times the ngsiService.sendUpdateValue() function has been invoked
|
|
241
|
+
successfully.
|
|
242
|
+
- **updateEntityRequestsError**: number of times the ngsiService.sendUpdateValue() function has been invoked and
|
|
243
|
+
failed.
|
|
241
244
|
|
|
242
245
|
More values will be added in the future to the library. The applications using the library can add values to the Stats
|
|
243
246
|
Registry just by using the following function:
|
|
@@ -247,7 +250,7 @@ iotagentLib.statsRegistry.add('statName', statIncrementalValue, callback);
|
|
|
247
250
|
```
|
|
248
251
|
|
|
249
252
|
The first time this function is invoked, it will add the new stat to the registry. Subsequent calls will add the value
|
|
250
|
-
to the specified stat
|
|
253
|
+
to the specified stat.
|
|
251
254
|
|
|
252
255
|
### Alarm module
|
|
253
256
|
|
|
@@ -753,9 +756,9 @@ The `newConfiguration` parameter will contain the newly created configuration. T
|
|
|
753
756
|
callback with no parameters (this handler should only be used for reconfiguration purposes of the IoT Agent).
|
|
754
757
|
|
|
755
758
|
For the cases of multiple updates (a single Device Configuration POST that will create several device groups), the
|
|
756
|
-
handler will be called once for each of the
|
|
759
|
+
handler will be called once for each of the config groups (both in the case of the creations and the updates).
|
|
757
760
|
|
|
758
|
-
The handler will be also called in the case of updates related to
|
|
761
|
+
The handler will be also called in the case of updates related to config groups. In that situation, the
|
|
759
762
|
`newConfiguration` parameter contains also the fields needed to identify the configuration to be updated, i.e.,
|
|
760
763
|
`service`, `subservice`, `resource` and `apikey`.
|
|
761
764
|
|
|
@@ -1330,7 +1333,7 @@ The IoT Agent is now ready to be used. Execute it with the following command:
|
|
|
1330
1333
|
node index.js
|
|
1331
1334
|
```
|
|
1332
1335
|
|
|
1333
|
-
The North Port interface should now be fully functional, i.e.: management of device registrations and
|
|
1336
|
+
The North Port interface should now be fully functional, i.e.: management of device registrations and config groups.
|
|
1334
1337
|
|
|
1335
1338
|
### IoT Agent With Active attributes
|
|
1336
1339
|
|
|
@@ -1828,7 +1831,7 @@ iotAgentLib.startServer(config, iotAgent, function (error) {
|
|
|
1828
1831
|
|
|
1829
1832
|
### Configuration management
|
|
1830
1833
|
|
|
1831
|
-
For some IoT Agents, it will be useful to know what devices or
|
|
1834
|
+
For some IoT Agents, it will be useful to know what devices or config groups were registered in the Agent, or to do
|
|
1832
1835
|
some actions whenever a new device is registered. All this configuration and provisioning actions can be performed using
|
|
1833
1836
|
two mechanisms: the provisioning handlers and the provisioning API.
|
|
1834
1837
|
|
|
@@ -1877,3 +1880,212 @@ iotAgentLib.setProvisioningHandler(provisioningHandler);
|
|
|
1877
1880
|
Now we can test our implementation by sending provisioning requests to the North Port of the IoT Agent. If we provision
|
|
1878
1881
|
a new device into the platform, and then we ask for the list of provisioned devices, we shall see the type of the
|
|
1879
1882
|
provisioned device has changed to `CertifiedType`.
|
|
1883
|
+
|
|
1884
|
+
## IoT Agent additional tools
|
|
1885
|
+
|
|
1886
|
+
The IoT Agent Node Lib provides some additional tools that can be used to ease the development of IoT Agents and test
|
|
1887
|
+
their functionality.
|
|
1888
|
+
|
|
1889
|
+
### Agent Console
|
|
1890
|
+
|
|
1891
|
+
A command-line client to experiment with the library is packed with it. The command-line client can be started using the
|
|
1892
|
+
following command:
|
|
1893
|
+
|
|
1894
|
+
```console
|
|
1895
|
+
bin/agentConsole.js
|
|
1896
|
+
```
|
|
1897
|
+
|
|
1898
|
+
The client offers an API similar to the one offered by the library: it can start and stop an IoT agent, register and
|
|
1899
|
+
unregister devices, send measures mimicking the device and receive updates of the device data. Take into account that,
|
|
1900
|
+
by default, the console uses the same `config.js` file than the IoT Agent.
|
|
1901
|
+
|
|
1902
|
+
The command-line client creates a console that offers the following options:
|
|
1903
|
+
|
|
1904
|
+
```text
|
|
1905
|
+
stressInit
|
|
1906
|
+
|
|
1907
|
+
Start recording a stress batch.
|
|
1908
|
+
|
|
1909
|
+
stressCommit <delay> <times> <threads> <initTime>
|
|
1910
|
+
|
|
1911
|
+
Executes the recorded batch as many times as requested, with delay (ms) between commands.
|
|
1912
|
+
The "threads" parameter indicates how many agents will repeat that same sequence. The "initTime" (ms)
|
|
1913
|
+
parameter indicates the mean of the random initial waiting times for each agent.
|
|
1914
|
+
|
|
1915
|
+
exit
|
|
1916
|
+
|
|
1917
|
+
Exit from the command-line.
|
|
1918
|
+
|
|
1919
|
+
start
|
|
1920
|
+
|
|
1921
|
+
Start the IoT Agent
|
|
1922
|
+
|
|
1923
|
+
stop
|
|
1924
|
+
|
|
1925
|
+
Stop the IoT Agent
|
|
1926
|
+
|
|
1927
|
+
register <id> <type>
|
|
1928
|
+
|
|
1929
|
+
Register a new device in the IoT Agent. The attributes to register will be extracted from the
|
|
1930
|
+
type configuration
|
|
1931
|
+
|
|
1932
|
+
unregister <id> <type>
|
|
1933
|
+
|
|
1934
|
+
Unregister the selected device
|
|
1935
|
+
|
|
1936
|
+
showConfig
|
|
1937
|
+
|
|
1938
|
+
Show the current configuration file
|
|
1939
|
+
|
|
1940
|
+
config <newConfig>
|
|
1941
|
+
|
|
1942
|
+
Change the configuration file to a new one
|
|
1943
|
+
|
|
1944
|
+
updatevalue <deviceId> <deviceType> <attributes>
|
|
1945
|
+
|
|
1946
|
+
Update a device value in the Context Broker. The attributes should be triads with the following
|
|
1947
|
+
format: "name/type/value" sepparated by commas.
|
|
1948
|
+
|
|
1949
|
+
listdevices
|
|
1950
|
+
|
|
1951
|
+
List all the devices that have been registered in this IoT Agent session
|
|
1952
|
+
```
|
|
1953
|
+
|
|
1954
|
+
### Agent tester
|
|
1955
|
+
|
|
1956
|
+
#### Command-line testing
|
|
1957
|
+
|
|
1958
|
+
The library also offers a Context Broker and IoT Agent client that can be used to:
|
|
1959
|
+
|
|
1960
|
+
- Simulate operations to the Context Broker used by the IoT Agent, triggering Context Provider forwardings for lazy
|
|
1961
|
+
attributes and checking the appropriate values for active ones.
|
|
1962
|
+
- Simulate operations to the Device Provisioning API and Configuration API of the IoT Agent.
|
|
1963
|
+
|
|
1964
|
+
The tester can be started with the following command, from the root folder of the project:
|
|
1965
|
+
|
|
1966
|
+
```console
|
|
1967
|
+
bin/iotAgentTester.js
|
|
1968
|
+
```
|
|
1969
|
+
|
|
1970
|
+
From the command-line, the `help` command can be used to show a description of the currently supported features. These
|
|
1971
|
+
are the following:
|
|
1972
|
+
|
|
1973
|
+
```text
|
|
1974
|
+
stressInit
|
|
1975
|
+
|
|
1976
|
+
Start recording a stress batch.
|
|
1977
|
+
|
|
1978
|
+
stressCommit <delay> <times> <threads> <initTime>
|
|
1979
|
+
|
|
1980
|
+
Executes the recorded batch as many times as requested, with delay (ms) between commands.
|
|
1981
|
+
The "threads" parameter indicates how many agents will repeat that same sequence. The "initTime" (ms)
|
|
1982
|
+
parameter indicates the mean of the random initial waiting times for each agent.
|
|
1983
|
+
|
|
1984
|
+
exit
|
|
1985
|
+
|
|
1986
|
+
Exit from the command-line.
|
|
1987
|
+
|
|
1988
|
+
update <entity> <type> <attributes>
|
|
1989
|
+
|
|
1990
|
+
Update the values of the defined set of attributes, using the following format: name#type=value(|name#type=value)*
|
|
1991
|
+
|
|
1992
|
+
append <entity> <type> <attributes>
|
|
1993
|
+
|
|
1994
|
+
Append a new Entity with the defined set of attributes, using the following format: name:type=value(,name:type=value)*
|
|
1995
|
+
|
|
1996
|
+
query <entity> <type>
|
|
1997
|
+
|
|
1998
|
+
Get all the information on the selected object.
|
|
1999
|
+
|
|
2000
|
+
queryAttr <entity> <type> <attributes>
|
|
2001
|
+
|
|
2002
|
+
Get information on the selected object for the selected attributes.
|
|
2003
|
+
|
|
2004
|
+
discover <entity> <type>
|
|
2005
|
+
|
|
2006
|
+
Get all the context providers for a entity and type.
|
|
2007
|
+
|
|
2008
|
+
configCb <host> <port> <service> <subservice>
|
|
2009
|
+
|
|
2010
|
+
Config a new host and port for the remote Context Broker.
|
|
2011
|
+
|
|
2012
|
+
showConfigCb
|
|
2013
|
+
|
|
2014
|
+
Show the current configuration of the client for the Context Broker.
|
|
2015
|
+
|
|
2016
|
+
configIot <host> <port> <service> <subservice>
|
|
2017
|
+
|
|
2018
|
+
Config a new host and port for the remote IoT Agent.
|
|
2019
|
+
|
|
2020
|
+
showConfigIot
|
|
2021
|
+
|
|
2022
|
+
Show the current configuration of the client for the IoT Agent.
|
|
2023
|
+
|
|
2024
|
+
provision <filename>
|
|
2025
|
+
|
|
2026
|
+
Provision a new device using the Device Provisioning API. The device configuration is
|
|
2027
|
+
read from the file specified in the "filename" parameter.
|
|
2028
|
+
|
|
2029
|
+
provisionGroup <template> <data> <type>
|
|
2030
|
+
|
|
2031
|
+
Provision a group of devices with the selected template, taking the information needed to
|
|
2032
|
+
fill the template from a CSV with two columns, DEVICE_ID and DEVICE_NAME. The third parameter, type
|
|
2033
|
+
will be used to replace the DEVICE_TYPE field in the template. All the devices will be provisioned
|
|
2034
|
+
to the same IoT Agent, once the templates have been fulfilled.
|
|
2035
|
+
|
|
2036
|
+
listProvisioned
|
|
2037
|
+
|
|
2038
|
+
List all the provisioned devices in an IoT Agent.
|
|
2039
|
+
|
|
2040
|
+
removeProvisioned <deviceId>
|
|
2041
|
+
|
|
2042
|
+
Remove the selected provisioned device from the IoT Agent, specified by its Device ID.
|
|
2043
|
+
|
|
2044
|
+
addGroup <filename>
|
|
2045
|
+
|
|
2046
|
+
Add a new device group to the specified IoT Agent through the Configuration API. The
|
|
2047
|
+
body is taken from the file specified in the "filename" parameter.
|
|
2048
|
+
|
|
2049
|
+
listGroups
|
|
2050
|
+
|
|
2051
|
+
List all the device groups created in the selected IoT Agent for the configured service
|
|
2052
|
+
|
|
2053
|
+
removeGroup <apiKey> <resource>
|
|
2054
|
+
|
|
2055
|
+
Remove the device group corresponding to the current configured subservice.
|
|
2056
|
+
|
|
2057
|
+
authenticate <host> <port> <user> <password> <service>
|
|
2058
|
+
|
|
2059
|
+
Authenticates to the given authentication server, and use the token in subsequent requests.
|
|
2060
|
+
|
|
2061
|
+
setProtocol <protocol>
|
|
2062
|
+
|
|
2063
|
+
Sets the protocol to use in the requests (http or https). Defaults to http.
|
|
2064
|
+
|
|
2065
|
+
configMigration <host> <port> <originDb>
|
|
2066
|
+
|
|
2067
|
+
Sets the configuration for a migration between a C++ IoTA and a Node.js one.
|
|
2068
|
+
|
|
2069
|
+
showConfigMigration
|
|
2070
|
+
|
|
2071
|
+
Shows the current migration configuration.
|
|
2072
|
+
|
|
2073
|
+
addProtocols <protocols>
|
|
2074
|
+
|
|
2075
|
+
Add a protocol translation table, in the following format:
|
|
2076
|
+
protocolOrigin1=protocolTarget1;protocolOrigin2=protocolTarget2...
|
|
2077
|
+
|
|
2078
|
+
|
|
2079
|
+
migrate <targetDb> <service> <subservice>
|
|
2080
|
+
|
|
2081
|
+
Migrate all the devices and groups for the selected service and subservice into the
|
|
2082
|
+
specified Mongo database. To perform the migration for all the services or all the
|
|
2083
|
+
subservices, use the "*" value.
|
|
2084
|
+
```
|
|
2085
|
+
|
|
2086
|
+
The agent session stores transient configuration data about the target Context Broker and the target IoT Agent. This
|
|
2087
|
+
configuration is independent, and can be checked with the `showConfigCb` and `showConfigIot` commands, respectively.
|
|
2088
|
+
Their values can be changed with the `configCb` and `configIot` commands respectively. The new config group will be
|
|
2089
|
+
deleted upon startup.
|
|
2090
|
+
|
|
2091
|
+
---
|