iotagent-node-lib 2.19.0 → 2.20.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/.nyc_output/76bc24ff-5fac-4b5a-997d-de2799342eb0.json +1 -0
- package/.nyc_output/processinfo/76bc24ff-5fac-4b5a-997d-de2799342eb0.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/CHANGES_NEXT_RELEASE +1 -0
- package/README.md +3 -54
- package/doc/advanced-topics.md +0 -33
- package/lib/fiware-iotagent-lib.js +0 -2
- package/lib/services/common/domain.js +6 -2
- package/package.json +2 -8
- package/bin/agentConsole.js +0 -257
- package/bin/iotAgentTester.js +0 -44
- package/lib/command/commandLine.js +0 -918
- package/lib/command/migration.js +0 -176
- package/test/unit/general/migration-test.js +0 -257
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"parent":null,"pid":26617,"argv":["/home/fermin/.nvm/versions/node/v10.24.1/bin/node","/home/fermin/src/iotagent-node-lib/node_modules/.bin/mocha","--recursive","test/**/*.js","--reporter","spec","--timeout","8000","--ui","bdd","--exit","--color","true"],"execArgv":[],"cwd":"/home/fermin/src/iotagent-node-lib","time":1646066946112,"ppid":26606,"coverageFilename":"/home/fermin/src/iotagent-node-lib/.nyc_output/76bc24ff-5fac-4b5a-997d-de2799342eb0.json","externalId":"","uuid":"76bc24ff-5fac-4b5a-997d-de2799342eb0","files":["/home/fermin/src/iotagent-node-lib/lib/fiware-iotagent-lib.js","/home/fermin/src/iotagent-node-lib/lib/services/ngsi/ngsiService.js","/home/fermin/src/iotagent-node-lib/lib/services/common/domain.js","/home/fermin/src/iotagent-node-lib/lib/constants.js","/home/fermin/src/iotagent-node-lib/lib/errors.js","/home/fermin/src/iotagent-node-lib/lib/commonConfig.js","/home/fermin/src/iotagent-node-lib/lib/services/ngsi/ngsiUtils.js","/home/fermin/src/iotagent-node-lib/lib/services/common/genericMiddleware.js","/home/fermin/src/iotagent-node-lib/lib/model/dbConn.js","/home/fermin/src/iotagent-node-lib/lib/services/common/alarmManagement.js","/home/fermin/src/iotagent-node-lib/lib/services/ngsi/subscriptionService.js","/home/fermin/src/iotagent-node-lib/lib/services/stats/statsRegistry.js","/home/fermin/src/iotagent-node-lib/lib/services/devices/deviceService.js","/home/fermin/src/iotagent-node-lib/lib/services/groups/groupService.js","/home/fermin/src/iotagent-node-lib/lib/services/common/iotManagerService.js","/home/fermin/src/iotagent-node-lib/lib/request-shim.js","/home/fermin/src/iotagent-node-lib/lib/services/devices/registrationUtils.js","/home/fermin/src/iotagent-node-lib/lib/services/northBound/restUtils.js","/home/fermin/src/iotagent-node-lib/lib/services/commands/commandService.js","/home/fermin/src/iotagent-node-lib/lib/services/northBound/northboundServer.js","/home/fermin/src/iotagent-node-lib/lib/services/northBound/contextServer.js","/home/fermin/src/iotagent-node-lib/lib/services/northBound/contextServerUtils.js","/home/fermin/src/iotagent-node-lib/lib/services/northBound/deviceProvisioningServer.js","/home/fermin/src/iotagent-node-lib/lib/services/northBound/deviceGroupAdministrationServer.js","/home/fermin/src/iotagent-node-lib/lib/plugins/compressTimestamp.js","/home/fermin/src/iotagent-node-lib/lib/plugins/pluginUtils.js","/home/fermin/src/iotagent-node-lib/lib/plugins/attributeAlias.js","/home/fermin/src/iotagent-node-lib/lib/plugins/addEvent.js","/home/fermin/src/iotagent-node-lib/lib/plugins/timestampProcessPlugin.js","/home/fermin/src/iotagent-node-lib/lib/plugins/expressionPlugin.js","/home/fermin/src/iotagent-node-lib/lib/plugins/expressionParser.js","/home/fermin/src/iotagent-node-lib/lib/plugins/jexlParser.js","/home/fermin/src/iotagent-node-lib/lib/jexlTranformsMap.js","/home/fermin/src/iotagent-node-lib/lib/plugins/multiEntity.js","/home/fermin/src/iotagent-node-lib/lib/plugins/bidirectionalData.js","/home/fermin/src/iotagent-node-lib/lib/services/groups/groupRegistryMemory.js","/home/fermin/src/iotagent-node-lib/lib/services/common/securityServiceKeystone.js","/home/fermin/src/iotagent-node-lib/lib/services/devices/deviceRegistryMemory.js","/home/fermin/src/iotagent-node-lib/lib/services/commands/commandRegistryMemory.js","/home/fermin/src/iotagent-node-lib/lib/services/devices/devices-NGSI-v2.js","/home/fermin/src/iotagent-node-lib/lib/services/ngsi/entities-NGSI-v2.js","/home/fermin/src/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-v2.js","/home/fermin/src/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-v2.js","/home/fermin/src/iotagent-node-lib/lib/model/Device.js","/home/fermin/src/iotagent-node-lib/lib/model/Group.js","/home/fermin/src/iotagent-node-lib/lib/model/Command.js","/home/fermin/src/iotagent-node-lib/lib/services/devices/deviceRegistryMongoDB.js","/home/fermin/src/iotagent-node-lib/lib/services/groups/groupRegistryMongoDB.js","/home/fermin/src/iotagent-node-lib/lib/services/commands/commandRegistryMongoDB.js","/home/fermin/src/iotagent-node-lib/lib/services/devices/devices-NGSI-LD.js","/home/fermin/src/iotagent-node-lib/lib/services/ngsi/entities-NGSI-LD.js","/home/fermin/src/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-LD.js","/home/fermin/src/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-LD.js","/home/fermin/src/iotagent-node-lib/lib/services/common/securityServiceOAuth2.js","/home/fermin/src/iotagent-node-lib/lib/services/devices/devices-NGSI-mixed.js","/home/fermin/src/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-mixed.js","/home/fermin/src/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-mixed.js","/home/fermin/src/iotagent-node-lib/lib/services/ngsi/entities-NGSI-mixed.js"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"processes":{"76bc24ff-5fac-4b5a-997d-de2799342eb0":{"parent":null,"children":[]}},"files":{"/home/fermin/src/iotagent-node-lib/lib/fiware-iotagent-lib.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/ngsi/ngsiService.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/common/domain.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/constants.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/errors.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/commonConfig.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/ngsi/ngsiUtils.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/common/genericMiddleware.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/model/dbConn.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/common/alarmManagement.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/ngsi/subscriptionService.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/stats/statsRegistry.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/devices/deviceService.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/groups/groupService.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/common/iotManagerService.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/request-shim.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/devices/registrationUtils.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/northBound/restUtils.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/commands/commandService.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/northBound/northboundServer.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/northBound/contextServer.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/northBound/contextServerUtils.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/northBound/deviceProvisioningServer.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/northBound/deviceGroupAdministrationServer.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/plugins/compressTimestamp.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/plugins/pluginUtils.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/plugins/attributeAlias.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/plugins/addEvent.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/plugins/timestampProcessPlugin.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/plugins/expressionPlugin.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/plugins/expressionParser.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/plugins/jexlParser.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/jexlTranformsMap.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/plugins/multiEntity.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/plugins/bidirectionalData.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/groups/groupRegistryMemory.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/common/securityServiceKeystone.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/devices/deviceRegistryMemory.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/commands/commandRegistryMemory.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/devices/devices-NGSI-v2.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/ngsi/entities-NGSI-v2.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-v2.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-v2.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/model/Device.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/model/Group.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/model/Command.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/devices/deviceRegistryMongoDB.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/groups/groupRegistryMongoDB.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/commands/commandRegistryMongoDB.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/devices/devices-NGSI-LD.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/ngsi/entities-NGSI-LD.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-LD.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-LD.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/common/securityServiceOAuth2.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/devices/devices-NGSI-mixed.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/ngsi/subscription-NGSI-mixed.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/northBound/contextServer-NGSI-mixed.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"],"/home/fermin/src/iotagent-node-lib/lib/services/ngsi/entities-NGSI-mixed.js":["76bc24ff-5fac-4b5a-997d-de2799342eb0"]},"externalIds":{}}
|
package/CHANGES_NEXT_RELEASE
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/README.md
CHANGED
|
@@ -72,7 +72,7 @@ IoT Agent
|
|
|
72
72
|
In order to use the library within your own IoT Agent, you must first you require it before use:
|
|
73
73
|
|
|
74
74
|
```javascript
|
|
75
|
-
const iotagentLib = require(
|
|
75
|
+
const iotagentLib = require('iotagent-node-lib');
|
|
76
76
|
```
|
|
77
77
|
|
|
78
78
|
Information about how to configure the Library can be found at the corresponding section of the
|
|
@@ -298,57 +298,6 @@ configuration is independent, and can be checked with the `showConfigCb` and `sh
|
|
|
298
298
|
Their values can be changed with the `configCb` and `configIot` commands respectively. The new configurations will be
|
|
299
299
|
deleted upon startup.
|
|
300
300
|
|
|
301
|
-
#### Creating specialized testers
|
|
302
|
-
|
|
303
|
-
The command-line testing tools make use of the
|
|
304
|
-
[command-node Node.js library](https://github.com/telefonicaid/command-shell-lib) for command-line utils. In order to
|
|
305
|
-
help creating testing tools for IoTAgents of specific protocols, all the commands of the library tester are offered as a
|
|
306
|
-
array that can be directly imported into other Command-Line tools, using the following steps:
|
|
307
|
-
|
|
308
|
-
- Require the `iotagent-node-lib` command-line module in your command-line tool:
|
|
309
|
-
|
|
310
|
-
```javascript
|
|
311
|
-
var iotaCommands = require("iotagent-node-lib").commandLine;
|
|
312
|
-
```
|
|
313
|
-
|
|
314
|
-
- Initialize the command-line utils (the initialization function takes two arguments, that will be explained in detail
|
|
315
|
-
below:
|
|
316
|
-
|
|
317
|
-
```javascript
|
|
318
|
-
iotaCommands.init(configCb, configIot);
|
|
319
|
-
```
|
|
320
|
-
|
|
321
|
-
- Add the IOTA Lib commands to your array of commands
|
|
322
|
-
|
|
323
|
-
```javascript
|
|
324
|
-
commands = commands.concat(commands, iotaCommands.commands);
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
- Execute the command-line interpreter as usual:
|
|
328
|
-
|
|
329
|
-
```javascript
|
|
330
|
-
clUtils.initialize(commandLine.commands, "IoT Agent tester> ");
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
The command-line module makes use of two configuration objects. Both can be shown and edited in the command-line using
|
|
334
|
-
the provided commands, but a default value must be present.
|
|
335
|
-
|
|
336
|
-
The Context Broker configuration object holds all the information about the Context Broker where the IoT Agent to be
|
|
337
|
-
tested is connected. It MUST contain the following attributes:
|
|
338
|
-
|
|
339
|
-
- **host**: host where the Context Broker instance is located.
|
|
340
|
-
- **port**: port where the Context Broker instance is listening.
|
|
341
|
-
- **service**: service that will be used in all the NGSI operations.
|
|
342
|
-
- **subservice**: service that will be used in all the NGSI operations.
|
|
343
|
-
|
|
344
|
-
The IoT Agent configuration object holds information about the IoT Agent that is being tested. It MUST contain the
|
|
345
|
-
following attributes:
|
|
346
|
-
|
|
347
|
-
- **host**: host where the IoT Agent instance is located.
|
|
348
|
-
- **port**: port where the IoT Agent instance is listening.
|
|
349
|
-
- **service**: service that will be used to group devices and device information.
|
|
350
|
-
- **subservice**: subservice that will be used to group devices and device information.
|
|
351
|
-
|
|
352
301
|
---
|
|
353
302
|
|
|
354
303
|
## Licence
|
|
@@ -364,8 +313,8 @@ related with the fact that different people assign different interpretations on
|
|
|
364
313
|
used in these licenses. Due to this, some people believe that there is a risk in just _using_ software under GPL or AGPL
|
|
365
314
|
licenses (even without _modifying_ it).
|
|
366
315
|
|
|
367
|
-
For the avoidance of doubt, the owners of this software licensed under an AGPL-3.0 license
|
|
368
|
-
|
|
316
|
+
For the avoidance of doubt, the owners of this software licensed under an AGPL-3.0 license wish to make a clarifying
|
|
317
|
+
public statement as follows:
|
|
369
318
|
|
|
370
319
|
> Please note that software derived as a result of modifying the source code of this software in order to fix a bug or
|
|
371
320
|
> incorporate enhancements is considered a derivative work of the product. Software that merely uses or aggregates (i.e.
|
package/doc/advanced-topics.md
CHANGED
|
@@ -21,7 +21,6 @@
|
|
|
21
21
|
- [Autoprovision configuration (autoprovision)](#autoprovision-configuration-autoprovision)
|
|
22
22
|
- [Explicitly defined attributes (explicitAttrs)](#explicitly-defined-attributes-explicitattrs)
|
|
23
23
|
- [Configuring operation to persist the data in Context Broker (appendMode)](#configuring-operation-to-persist-the-data-in-context-broker-appendmode)
|
|
24
|
-
- [Old IoTAgent data migration](#old-iotagent-data-migration)
|
|
25
24
|
|
|
26
25
|
### Secured access to the Context Broker
|
|
27
26
|
|
|
@@ -539,35 +538,3 @@ subscription payload.
|
|
|
539
538
|
For each attribute in the `reverse` array, an expression must be defined to calculate its value based on the
|
|
540
539
|
notification attributes. This value will be passed to the underlying protocol with the `object_id` name. Details about
|
|
541
540
|
how the value is then progressed to the device are protocol-specific.
|
|
542
|
-
|
|
543
|
-
### Old IoTAgent data migration
|
|
544
|
-
|
|
545
|
-
In order to ease the transition from the old IoTAgent implementation (formerly known as IDAS) to the new Node.js based
|
|
546
|
-
implementations, a data migration tool has been developed. This data migration tool has been integrated as a command in
|
|
547
|
-
the IoTAgent command-line tester.
|
|
548
|
-
|
|
549
|
-
In order to perform a full migration, follow this steps:
|
|
550
|
-
|
|
551
|
-
- From the project root, start the command-line tester:
|
|
552
|
-
|
|
553
|
-
```bash
|
|
554
|
-
bin/iotAgentTester.js
|
|
555
|
-
```
|
|
556
|
-
|
|
557
|
-
- Configure the MongoDB host and port, and the origin Database (that holds the data to be migrated):
|
|
558
|
-
|
|
559
|
-
```bash
|
|
560
|
-
configMigration localhost 27017 originDB
|
|
561
|
-
```
|
|
562
|
-
|
|
563
|
-
- Launch the migration, using the special value "\*" as service and subservice
|
|
564
|
-
|
|
565
|
-
```bash
|
|
566
|
-
migrate targetDB * *
|
|
567
|
-
```
|
|
568
|
-
|
|
569
|
-
Some warnings may appear with the "Attribute [_id] was not found for item translation" message during the migration.
|
|
570
|
-
They show the values existing in the original DB that had no translation for the target DB.
|
|
571
|
-
|
|
572
|
-
If you want to restrict the migration for certain services and subservices, just substitute the `*` value for the
|
|
573
|
-
particular service and subservice you want to use.
|
|
@@ -355,8 +355,6 @@ exports.fillService = domainUtils.fillService;
|
|
|
355
355
|
|
|
356
356
|
exports.middlewares = middlewares;
|
|
357
357
|
|
|
358
|
-
exports.commandLine = require('./command/commandLine');
|
|
359
|
-
|
|
360
358
|
exports.dataPlugins = {
|
|
361
359
|
compressTimestamp: require('./plugins/compressTimestamp'),
|
|
362
360
|
attributeAlias: require('./plugins/attributeAlias'),
|
|
@@ -47,6 +47,8 @@ function cleanDomain(domainToClean) {
|
|
|
47
47
|
delete domainToClean.from;
|
|
48
48
|
delete domainToClean.op;
|
|
49
49
|
delete domainToClean.path;
|
|
50
|
+
delete domainToClean.service;
|
|
51
|
+
delete domainToClean.subservice;
|
|
50
52
|
domainToClean.exit();
|
|
51
53
|
}
|
|
52
54
|
|
|
@@ -139,8 +141,10 @@ function ensureSouthboundTransaction(context, callback) {
|
|
|
139
141
|
reqDomain.corr = reqDomain.trans;
|
|
140
142
|
}
|
|
141
143
|
|
|
142
|
-
if (context
|
|
143
|
-
|
|
144
|
+
if (context) {
|
|
145
|
+
if (context.op) {
|
|
146
|
+
reqDomain.op = context.op;
|
|
147
|
+
}
|
|
144
148
|
|
|
145
149
|
if (context.srv) {
|
|
146
150
|
reqDomain.service = context.srv;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "iotagent-node-lib",
|
|
3
3
|
"license": "AGPL-3.0-only",
|
|
4
4
|
"description": "IoT Agent library to interface with NGSI Context Broker",
|
|
5
|
-
"version": "2.
|
|
5
|
+
"version": "2.20.0",
|
|
6
6
|
"homepage": "https://github.com/telefonicaid/iotagent-node-lib",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"fiware",
|
|
@@ -21,17 +21,13 @@
|
|
|
21
21
|
"bugs": {
|
|
22
22
|
"url": "https://github.com/telefonicaid/iotagent-node-lib/issues"
|
|
23
23
|
},
|
|
24
|
-
"bin": {
|
|
25
|
-
"agentConsole": "bin/agentConsole.js",
|
|
26
|
-
"iotAgentTester": "bin/iotAgentTester.js"
|
|
27
|
-
},
|
|
28
24
|
"main": "lib/fiware-iotagent-lib",
|
|
29
25
|
"engines": {
|
|
30
26
|
"node": ">=12"
|
|
31
27
|
},
|
|
32
28
|
"scripts": {
|
|
33
29
|
"clean": "rm -rf package-lock.json && rm -rf node_modules && rm -rf coverage",
|
|
34
|
-
"lint": "eslint lib/
|
|
30
|
+
"lint": "eslint lib/ test/ --cache --fix",
|
|
35
31
|
"lint:md": "remark -f '*.md' 'doc/*.md'",
|
|
36
32
|
"lint:text": "textlint '*.md' 'doc/*.md'",
|
|
37
33
|
"prettier": "prettier --config .prettierrc.json --write '**/**/**/**/*.js' '**/**/**/*.js' '**/**/*.js' '**/*.js' '*.js'",
|
|
@@ -48,7 +44,6 @@
|
|
|
48
44
|
"dependencies": {
|
|
49
45
|
"async": "2.6.2",
|
|
50
46
|
"body-parser": "~1.19.0",
|
|
51
|
-
"command-shell-lib": "1.0.0",
|
|
52
47
|
"express": "~4.16.4",
|
|
53
48
|
"got": "~11.8.2",
|
|
54
49
|
"jexl": "2.3.0",
|
|
@@ -58,7 +53,6 @@
|
|
|
58
53
|
"moment-timezone": "~0.5.25",
|
|
59
54
|
"mongodb": "3.6.8",
|
|
60
55
|
"mongoose": "5.7.7",
|
|
61
|
-
"mu2": "~0.5.20",
|
|
62
56
|
"query-string": "6.5.0",
|
|
63
57
|
"revalidator": "~0.3.1",
|
|
64
58
|
"underscore": "~1.12.1",
|
package/bin/agentConsole.js
DELETED
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U
|
|
5
|
-
*
|
|
6
|
-
* This file is part of fiware-iotagent-lib
|
|
7
|
-
*
|
|
8
|
-
* fiware-iotagent-lib is free software: you can redistribute it and/or
|
|
9
|
-
* modify it under the terms of the GNU Affero General Public License as
|
|
10
|
-
* published by the Free Software Foundation, either version 3 of the License,
|
|
11
|
-
* or (at your option) any later version.
|
|
12
|
-
*
|
|
13
|
-
* fiware-iotagent-lib is distributed in the hope that it will be useful,
|
|
14
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
16
|
-
* See the GNU Affero General Public License for more details.
|
|
17
|
-
*
|
|
18
|
-
* You should have received a copy of the GNU Affero General Public
|
|
19
|
-
* License along with fiware-iotagent-lib.
|
|
20
|
-
* If not, see http://www.gnu.org/licenses/.
|
|
21
|
-
*
|
|
22
|
-
* For those usages not covered by the GNU Affero General Public License
|
|
23
|
-
* please contact with::[contacto@tid.es]
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/* eslint-disable no-unused-vars */
|
|
27
|
-
/* eslint-disable no-console */
|
|
28
|
-
|
|
29
|
-
const readline = require('readline');
|
|
30
|
-
const iotAgentLib = require('../lib/fiware-iotagent-lib');
|
|
31
|
-
const commandUtils = require('command-shell-lib');
|
|
32
|
-
let config = require('../config');
|
|
33
|
-
const logger = require('logops');
|
|
34
|
-
const async = require('async');
|
|
35
|
-
const separator = '\n\n\t';
|
|
36
|
-
|
|
37
|
-
const commands = {
|
|
38
|
-
start: {
|
|
39
|
-
parameters: [],
|
|
40
|
-
description: '\tStart the IoT Agent',
|
|
41
|
-
handler: startApp
|
|
42
|
-
},
|
|
43
|
-
stop: {
|
|
44
|
-
parameters: [],
|
|
45
|
-
description: '\tStop the IoT Agent',
|
|
46
|
-
handler: stopApp
|
|
47
|
-
},
|
|
48
|
-
register: {
|
|
49
|
-
parameters: ['id', 'type'],
|
|
50
|
-
description:
|
|
51
|
-
'\tRegister a new device in the IoT Agent. The attributes to register will be extracted from the\n' +
|
|
52
|
-
'\ttype configuration',
|
|
53
|
-
handler: registerDevice
|
|
54
|
-
},
|
|
55
|
-
unregister: {
|
|
56
|
-
parameters: ['id', 'type'],
|
|
57
|
-
description: '\tUnregister the selected device',
|
|
58
|
-
handler: unregisterDevice
|
|
59
|
-
},
|
|
60
|
-
showConfig: {
|
|
61
|
-
parameters: [],
|
|
62
|
-
description: '\tShow the current configuration file',
|
|
63
|
-
handler: showConfig
|
|
64
|
-
},
|
|
65
|
-
config: {
|
|
66
|
-
parameters: ['newConfig'],
|
|
67
|
-
description: '\tChange the configuration file to a new one',
|
|
68
|
-
handler: changeConfig
|
|
69
|
-
},
|
|
70
|
-
updatevalue: {
|
|
71
|
-
parameters: ['deviceId', 'deviceType', 'attributes'],
|
|
72
|
-
description:
|
|
73
|
-
'\tUpdate a device value in the Context Broker. The attributes should be triads with the following\n' +
|
|
74
|
-
'\tformat: "name/type/value" sepparated by commas.',
|
|
75
|
-
handler: updateDeviceValue
|
|
76
|
-
},
|
|
77
|
-
listdevices: {
|
|
78
|
-
parameters: [],
|
|
79
|
-
description: '\tList all the devices that have been registered in this IoT Agent session\n',
|
|
80
|
-
handler: listDevices
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
function handleError(message) {
|
|
85
|
-
return function (error) {
|
|
86
|
-
if (error) {
|
|
87
|
-
console.log('\n\\033[31mERROR:\\033[0m %s', error.message);
|
|
88
|
-
} else {
|
|
89
|
-
console.log(message);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
commandUtils.prompt();
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function listDevices() {
|
|
97
|
-
iotAgentLib.listDevices(config.service, config.subservice, function (error, devices) {
|
|
98
|
-
if (error) {
|
|
99
|
-
console.log('\n\\033[31mERROR:\\033[0m %s', error.message);
|
|
100
|
-
} else {
|
|
101
|
-
const keys = Object.keys(devices);
|
|
102
|
-
|
|
103
|
-
for (let i = 0; i < keys.length; i++) {
|
|
104
|
-
console.log('\n\n%s\n', JSON.stringify(devices[keys[i]], null, 4));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
commandUtils.prompt();
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function extractAttributes(attributeString, callback) {
|
|
113
|
-
const attributes = attributeString.split(',');
|
|
114
|
-
const attributesResult = [];
|
|
115
|
-
|
|
116
|
-
for (let i = 0; i < attributes.length; i++) {
|
|
117
|
-
const fields = attributes[i].split('/');
|
|
118
|
-
const attribute = {
|
|
119
|
-
name: fields[0],
|
|
120
|
-
type: fields[1]
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
if (fields[2]) {
|
|
124
|
-
attribute.value = fields[2];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
attributesResult.push(attribute);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
callback(null, attributesResult);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function showConfig() {
|
|
134
|
-
console.log('Current configuration file:\n\n%s', JSON.stringify(config, null, 4));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function changeConfig(command) {
|
|
138
|
-
config = require(command[0]);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function writeHandler(id, type, attributes, callback) {
|
|
142
|
-
console.log(
|
|
143
|
-
'\n\nFake WRITE handler for update in entity [%s] with type [%s]\n%s\n',
|
|
144
|
-
id,
|
|
145
|
-
type,
|
|
146
|
-
JSON.stringify(attributes, null, 4)
|
|
147
|
-
);
|
|
148
|
-
|
|
149
|
-
callback(null, {
|
|
150
|
-
id,
|
|
151
|
-
type,
|
|
152
|
-
attributes
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function readHandler(id, type, attributes, callback) {
|
|
157
|
-
console.log(
|
|
158
|
-
'\n\nFake READ handler for update in entity [%s] with type [%s]\n%s\n',
|
|
159
|
-
id,
|
|
160
|
-
type,
|
|
161
|
-
JSON.stringify(attributes, null, 4)
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
const sensorData = {
|
|
165
|
-
id,
|
|
166
|
-
isPattern: false,
|
|
167
|
-
type,
|
|
168
|
-
attributes: [
|
|
169
|
-
{
|
|
170
|
-
name: 'luminance',
|
|
171
|
-
type: 'lumens',
|
|
172
|
-
value: 19
|
|
173
|
-
}
|
|
174
|
-
]
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
callback(null, sensorData);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function startApp(command) {
|
|
181
|
-
iotAgentLib.setDataUpdateHandler(writeHandler);
|
|
182
|
-
iotAgentLib.setCommandHandler(writeHandler);
|
|
183
|
-
iotAgentLib.setDataQueryHandler(readHandler);
|
|
184
|
-
iotAgentLib.activate(config, handleError('Application started'));
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function stopApp(command) {
|
|
188
|
-
iotAgentLib.deactivate(handleError('Application stopped'));
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function exitAgent(command) {
|
|
192
|
-
process.exit(0);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function registerDevice(command) {
|
|
196
|
-
const device = {
|
|
197
|
-
id: command[0],
|
|
198
|
-
type: command[1]
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
console.log('Registering device');
|
|
202
|
-
iotAgentLib.register(device, handleError('Device registered in the Context Broker'));
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function unregisterDevice(command) {
|
|
206
|
-
console.log('Unregistering device');
|
|
207
|
-
iotAgentLib.unregister(command[0], handleError('Device unregistered'));
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function updateDeviceValue(command) {
|
|
211
|
-
iotAgentLib.getDevice(command[0], function (error, device) {
|
|
212
|
-
if (device) {
|
|
213
|
-
extractAttributes(command[2], function (error, attributes) {
|
|
214
|
-
iotAgentLib.update(
|
|
215
|
-
device.name,
|
|
216
|
-
device.type,
|
|
217
|
-
'',
|
|
218
|
-
attributes,
|
|
219
|
-
device,
|
|
220
|
-
handleError('Device value updated')
|
|
221
|
-
);
|
|
222
|
-
});
|
|
223
|
-
} else {
|
|
224
|
-
async.waterfall(
|
|
225
|
-
[
|
|
226
|
-
async.apply(extractAttributes, command[2]),
|
|
227
|
-
async.apply(iotAgentLib.update, command[0], command[1], '')
|
|
228
|
-
],
|
|
229
|
-
handleError('Device value updated')
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function queryHandler(id, type, attributes, callback) {
|
|
236
|
-
console.log('Handling query for [%s] of type [%s]:\n%s', JSON.stringify(attributes));
|
|
237
|
-
|
|
238
|
-
callback(null, {
|
|
239
|
-
type,
|
|
240
|
-
isPattern: false,
|
|
241
|
-
id,
|
|
242
|
-
attributes: []
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function updateHandler(id, type, attributes, callback) {
|
|
247
|
-
console.log('Update message received for device with id [%s] and type [%s]', id, type);
|
|
248
|
-
|
|
249
|
-
callback(null, {
|
|
250
|
-
type,
|
|
251
|
-
isPattern: false,
|
|
252
|
-
id,
|
|
253
|
-
attributes: []
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
commandUtils.initialize(commands, 'IoTAgent> ');
|
package/bin/iotAgentTester.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* Copyright 2014 Telefonica Investigación y Desarrollo, S.A.U
|
|
5
|
-
*
|
|
6
|
-
* This file is part of fiware-iotagent-lib
|
|
7
|
-
*
|
|
8
|
-
* fiware-iotagent-lib is free software: you can redistribute it and/or
|
|
9
|
-
* modify it under the terms of the GNU Affero General Public License as
|
|
10
|
-
* published by the Free Software Foundation, either version 3 of the License,
|
|
11
|
-
* or (at your option) any later version.
|
|
12
|
-
*
|
|
13
|
-
* fiware-iotagent-lib is distributed in the hope that it will be useful,
|
|
14
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
16
|
-
* See the GNU Affero General Public License for more details.
|
|
17
|
-
*
|
|
18
|
-
* You should have received a copy of the GNU Affero General Public
|
|
19
|
-
* License along with fiware-iotagent-lib.
|
|
20
|
-
* If not, see http://www.gnu.org/licenses/.
|
|
21
|
-
*
|
|
22
|
-
* For those usages not covered by the GNU Affero General Public License
|
|
23
|
-
* please contact with::[contacto@tid.es]
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
const commandLine = require('../lib/command/commandLine');
|
|
27
|
-
const clUtils = require('command-shell-lib');
|
|
28
|
-
const configCb = {
|
|
29
|
-
host: 'localhost',
|
|
30
|
-
port: 1026,
|
|
31
|
-
service: 'tester',
|
|
32
|
-
subservice: '/test'
|
|
33
|
-
};
|
|
34
|
-
const configIot = {
|
|
35
|
-
host: 'localhost',
|
|
36
|
-
port: 4041,
|
|
37
|
-
name: 'default',
|
|
38
|
-
service: 'tester',
|
|
39
|
-
subservice: '/test'
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
commandLine.init(configCb, configIot);
|
|
43
|
-
|
|
44
|
-
clUtils.initialize(commandLine.commands, 'IoT Agent tester> ');
|