iotagent-node-lib 3.1.0 → 3.3.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.
Files changed (163) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +134 -0
  2. package/.github/ISSUE_TEMPLATE/config.yml +16 -0
  3. package/.github/ISSUE_TEMPLATE/feature_request.yml +55 -0
  4. package/.github/advanced-issue-labeler.yml +30 -0
  5. package/.github/workflows/issue-labeler.yml +43 -0
  6. package/CHANGES_NEXT_RELEASE +0 -2
  7. package/config.js +5 -5
  8. package/doc/api.md +1483 -298
  9. package/doc/deprecated.md +7 -1
  10. package/doc/development.md +120 -0
  11. package/doc/howto.md +58 -62
  12. package/doc/installationguide.md +3 -11
  13. package/doc/requirements.txt +1 -1
  14. package/docker/Mosquitto/Dockerfile +1 -1
  15. package/lib/commonConfig.js +7 -10
  16. package/lib/fiware-iotagent-lib.js +0 -10
  17. package/lib/jexlTranformsMap.js +2 -1
  18. package/lib/model/Device.js +0 -1
  19. package/lib/model/Group.js +0 -1
  20. package/lib/model/dbConn.js +1 -7
  21. package/lib/plugins/bidirectionalData.js +8 -26
  22. package/lib/plugins/expressionPlugin.js +8 -40
  23. package/lib/plugins/jexlParser.js +28 -0
  24. package/lib/services/commands/commandService.js +1 -1
  25. package/lib/services/common/iotManagerService.js +0 -1
  26. package/lib/services/devices/deviceRegistryMongoDB.js +10 -10
  27. package/lib/services/devices/deviceService.js +16 -20
  28. package/lib/services/devices/devices-NGSI-v2.js +2 -5
  29. package/lib/services/ngsi/entities-NGSI-LD.js +16 -60
  30. package/lib/services/ngsi/entities-NGSI-v2.js +179 -119
  31. package/lib/services/northBound/deviceProvisioningServer.js +17 -17
  32. package/lib/templates/createDevice.json +5 -6
  33. package/lib/templates/createDeviceLax.json +6 -8
  34. package/lib/templates/deviceGroup.json +1 -5
  35. package/lib/templates/updateDevice.json +9 -2
  36. package/lib/templates/updateDeviceLax.json +14 -5
  37. package/package.json +1 -1
  38. package/scripts/legacy_expression_tool/README.md +262 -0
  39. package/scripts/legacy_expression_tool/legacy_expression_tool.py +423 -0
  40. package/scripts/legacy_expression_tool/requirements.txt +3 -0
  41. package/test/unit/examples/deviceProvisioningRequests/provisionBidirectionalDevice.json +5 -5
  42. package/test/unit/examples/groupProvisioningRequests/bidirectionalGroup.json +4 -4
  43. package/test/unit/general/contextBrokerKeystoneSecurityAccess-test.js +3 -13
  44. package/test/unit/ngsi-ld/expressions/jexlBasedTransformations-test.js +0 -2
  45. package/test/unit/ngsi-ld/lazyAndCommands/merge-patch-test.js +31 -30
  46. package/test/unit/ngsi-ld/plugins/bidirectional-plugin_test.js +8 -8
  47. package/test/unit/ngsi-ld/plugins/custom-plugin_test.js +152 -0
  48. package/test/unit/ngsi-ld/plugins/multientity-plugin_test.js +1 -1
  49. package/test/unit/ngsi-mixed/provisioning/ngsi-versioning-test.js +33 -37
  50. package/test/unit/ngsiv2/examples/contextRequests/createMinimumProvisionedDevice4.json +5 -1
  51. package/test/unit/ngsiv2/examples/contextRequests/updateContext.json +2 -0
  52. package/test/unit/ngsiv2/examples/contextRequests/updateContext1.json +3 -1
  53. package/test/unit/ngsiv2/examples/contextRequests/updateContext3WithStatic.json +2 -0
  54. package/test/unit/ngsiv2/examples/contextRequests/updateContext4.json +4 -1
  55. package/test/unit/ngsiv2/examples/contextRequests/updateContext5.json +12 -0
  56. package/test/unit/ngsiv2/examples/contextRequests/updateContext6.json +10 -0
  57. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin1.json +2 -0
  58. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin2.json +3 -1
  59. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin3.json +3 -1
  60. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin4.json +3 -1
  61. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin5.json +3 -1
  62. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin6.json +3 -1
  63. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin7.json +3 -1
  64. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin8.json +3 -1
  65. package/test/unit/ngsiv2/examples/contextRequests/updateContextAliasPlugin9.json +3 -1
  66. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast1.json +2 -0
  67. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast2.json +2 -0
  68. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast3.json +3 -1
  69. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast4.json +3 -1
  70. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast5.json +3 -1
  71. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast6.json +3 -1
  72. package/test/unit/ngsiv2/examples/contextRequests/updateContextAutocast7.json +3 -1
  73. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandError.json +3 -1
  74. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandExpired.json +3 -1
  75. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandFinish.json +3 -1
  76. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus.json +2 -0
  77. package/test/unit/ngsiv2/examples/contextRequests/updateContextCommandStatus2.json +2 -0
  78. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp1.json +3 -1
  79. package/test/unit/ngsiv2/examples/contextRequests/updateContextCompressTimestamp2.json +3 -1
  80. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin1.json +2 -0
  81. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin11.json +2 -0
  82. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin12.json +2 -0
  83. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin13.json +3 -1
  84. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin2.json +2 -0
  85. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin29.json +2 -0
  86. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin3.json +2 -0
  87. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin30.json +2 -0
  88. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin31.json +2 -8
  89. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin32.json +2 -0
  90. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin33.json +2 -0
  91. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin34.json +2 -0
  92. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin35.json +22 -0
  93. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin36.json +1 -0
  94. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin4.json +2 -0
  95. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin40.json +42 -0
  96. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin41.json +33 -0
  97. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin5.json +2 -0
  98. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin6.json +2 -0
  99. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin7.json +2 -0
  100. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin8.json +2 -0
  101. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionPlugin9.json +2 -0
  102. package/test/unit/ngsiv2/examples/contextRequests/updateContextExpressionSkip.json +12 -0
  103. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityJexlExpressionPlugin1.json +1 -1
  104. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin1.json +1 -1
  105. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin10.json +1 -1
  106. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin11.json +1 -1
  107. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin12.json +1 -1
  108. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin13.json +1 -1
  109. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin14.json +1 -1
  110. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin15.json +1 -1
  111. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin16.json +1 -1
  112. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin17.json +1 -1
  113. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin2.json +1 -1
  114. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin25.json +37 -0
  115. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin3.json +1 -1
  116. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin4.json +1 -1
  117. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin5.json +1 -1
  118. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin6.json +1 -1
  119. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin7.json +1 -1
  120. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin8.json +1 -1
  121. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityPlugin9.json +1 -1
  122. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin1.json +1 -1
  123. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin2.json +1 -1
  124. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin3.json +1 -1
  125. package/test/unit/ngsiv2/examples/contextRequests/updateContextMultientityTimestampPlugin4.json +2 -0
  126. package/test/unit/ngsiv2/examples/contextRequests/updateContextProcessTimestamp.json +2 -0
  127. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributes.json +2 -0
  128. package/test/unit/ngsiv2/examples/contextRequests/updateContextStaticAttributesMetadata.json +3 -1
  129. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestamp.json +3 -1
  130. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalse.json +12 -0
  131. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampFalseTimeInstant.json +12 -0
  132. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverride.json +2 -0
  133. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampOverrideWithoutMilis.json +2 -0
  134. package/test/unit/ngsiv2/examples/contextRequests/updateContextTimestampTimezone.json +3 -1
  135. package/test/unit/ngsiv2/expressions/jexlBasedTransformations-test.js +355 -75
  136. package/test/unit/ngsiv2/general/contextBrokerOAuthSecurityAccess-test.js +18 -51
  137. package/test/unit/ngsiv2/general/https-support-test.js +1 -5
  138. package/test/unit/ngsiv2/lazyAndCommands/command-test.js +4 -10
  139. package/test/unit/ngsiv2/lazyAndCommands/polling-commands-test.js +9 -26
  140. package/test/unit/ngsiv2/ngsiService/active-devices-test.js +143 -57
  141. package/test/unit/ngsiv2/ngsiService/autocast-test.js +14 -21
  142. package/test/unit/ngsiv2/ngsiService/staticAttributes-test.js +3 -5
  143. package/test/unit/ngsiv2/ngsiService/subscriptions-test.js +1 -10
  144. package/test/unit/ngsiv2/plugins/alias-plugin_test.js +20 -30
  145. package/test/unit/ngsiv2/plugins/bidirectional-plugin_test.js +6 -69
  146. package/test/unit/ngsiv2/plugins/compress-timestamp-plugin_test.js +4 -6
  147. package/test/unit/ngsiv2/plugins/custom-plugin_test.js +150 -0
  148. package/test/unit/ngsiv2/plugins/multientity-plugin_test.js +87 -16
  149. package/test/unit/ngsiv2/plugins/timestamp-processing-plugin_test.js +2 -3
  150. package/test/unit/ngsiv2/provisioning/device-group-api-test.js +2 -3
  151. package/test/unit/ngsiv2/provisioning/device-provisioning-api_test.js +15 -55
  152. package/test/unit/ngsiv2/provisioning/device-registration_test.js +1 -7
  153. package/test/unit/ngsiv2/provisioning/device-update-registration_test.js +2 -9
  154. package/test/unit/ngsiv2/provisioning/singleConfigurationMode-test.js +0 -11
  155. package/test/unit/ngsiv2/provisioning/updateProvisionedDevices-test.js +0 -7
  156. package/test/unit/plugins/capture-provision-inPlugins_test.js +0 -6
  157. package/doc/advanced-topics.md +0 -626
  158. package/doc/expressionLanguage.md +0 -762
  159. package/lib/plugins/expressionParser.js +0 -205
  160. package/test/unit/expressions/expression-test.js +0 -197
  161. package/test/unit/ngsi-ld/expressions/expressionBasedTransformations-test.js +0 -882
  162. package/test/unit/ngsiv2/expressions/expressionBasedTransformations-test.js +0 -951
  163. package/test/unit/ngsiv2/expressions/expressionCombinedTransformations-test.js +0 -296
package/doc/api.md CHANGED
@@ -1,116 +1,1149 @@
1
1
  # IoT Agent API
2
2
 
3
- The **IoT Agent node library** offers a simple REST API which provides common functionality to access, provision and
4
- decommission devices.
3
+ <!-- TOC -->
4
+
5
+ - [Preface](#preface)
6
+ - [Topics](#topics)
7
+ - [Terminology](#terminology)
8
+ - [IoT Agent information model](#iot-agent-information-model)
9
+ - [Config groups](#config-groups)
10
+ - [Devices](#devices)
11
+ - [Entity attributes](#entity-attributes)
12
+ - [Multientity support)](#multientity-support)
13
+ - [Metadata support](#metadata-support)
14
+ - [NGSI LD data and metadata considerations](#ngsi-ld-data-and-metadata-considerations)
15
+ - [Advice on Attribute definitions](#advice-on-attribute-definitions)
16
+ - [Reuse of attribute names](#reuse-of-attribute-names)
17
+ - [Reuse of attribute types](#reuse-of-attribute-types)
18
+ - [How to specify attribute Units of Measurement](#how-to-specify-attribute-units-of-measurement)
19
+ - [Measurement persistence options](#measurement-persistence-options)
20
+ - [Autoprovision configuration (autoprovision)](#autoprovision-configuration-autoprovision)
21
+ - [Explicitly defined attributes (explicitAttrs)](#explicitly-defined-attributes-explicitattrs)
22
+ - [Differences between `autoprovision`, `explicitAttrs`](#differences-between-autoprovision-explicitattrs)
23
+ - [Expression language support](#expression-language-support)
24
+ - [Examples of JEXL expressions](#examples-of-jexl-expressions)
25
+ - [Available functions](#available-functions)
26
+ - [Expressions with multiple transformations](#expressions-with-multiple-transformations)
27
+ - [Measurement transformation](#measurement-transformation)
28
+ - [Measurement transformation definition](#measurement-transformation-definition)
29
+ - [Measurement transformation execution](#measurement-transformation-execution)
30
+ - [Multientity measurement transformation support (`object_id`)](#multientity-measurement-transformation-support-object_id)
31
+ - [Timestamp Compression](#timestamp-compression)
32
+ - [Timestamp Processing](#timestamp-processing)
33
+ - [Overriding global Context Broker host](#overriding-global-context-broker-host)
34
+ - [Multitenancy, FIWARE Service and FIWARE ServicePath](#multitenancy-fiware-service-and-fiware-servicepath)
35
+ - [Secured access to the Context Broker](#secured-access-to-the-context-broker)
36
+ - [NGSI-LD support](#ngsi-ld-support)
37
+ - [NGSI-LD `GeoProperty` support](#ngsi-ld-geoproperty-support)
38
+ - [NGSI-LD Linked Data support](#ngsi-ld-linked-data-support)
39
+ - [NGSI-LD `datasetId` support](#ngsi-ld-datasetid-support)
40
+ - [API Routes](#api-routes)
41
+ - [Config group API](#config-group-api)
42
+ - [Config group datamodel](#config-group-datamodel)
43
+ - [Config group operations](#config-group-operations)
44
+ - [Retrieve config groups `GET /iot/services`](#retrieve-config-groups-get-iotservices)
45
+ - [Create config group `POST /iot/services`](#create-config-group-post-iotservices)
46
+ - [Modify config group `PUT /iot/services`](#modify-config-group-put-iotservices)
47
+ - [Remove config group `DELETE /iot/services`](#remove-config-group-delete-iotservices)
48
+ - [Device API](#device-api)
49
+ - [Device datamodel](#device-datamodel)
50
+ - [Device operations](#device-operations)
51
+ - [Retrieve devices /iot/devices `GET /iot/devices`](#retrieve-devices-iotdevices-get-iotdevices)
52
+ - [Create device `POST /iot/devices`](#create-device-post-iotdevices)
53
+ - [Get device details `GET /iot/devices/:deviceId`](#get-device-details-get-iotdevicesdeviceid)
54
+ - [Modify device `PUT /iot/devices/:deviceId`](#modify-device-put-iotdevicesdeviceid)
55
+ - [Remove device `DELETE /iot/devices/:deviceId`](#remove-device-delete-iotdevicesdeviceid)
56
+ - [Miscellaneous API](#miscellaneous-api)
57
+ - [Log operations](#log-operations)
58
+ - [Modify Loglevel `PUT /admin/log`](#modify-loglevel-put-adminlog)
59
+ - [Retrieve log level `PUT /admin/log`](#retrieve-log-level-put-adminlog)
60
+ - [About operations](#about-operations)
61
+ - [List IoTA Information `GET /iot/about`](#list-iota-information-get-iotabout)
62
+
63
+ <!-- /TOC -->
64
+
65
+ # Preface
66
+
67
+ The IoT Agent mission is to provide a common abstraction layer between the devices and the NGSI entities stored in
68
+ Context Broker. In order to achieve this, the IoT Agent sits between the Context Broker and a set of devices. It is in
69
+ charge of translating the information coming from the devices into NGSI requests and viceversa.
70
+
71
+ The **IoT Agent node library** is a Node.js module that can be used to implement IoT Agents. It provides a set of common
72
+ functionality that can be used to implement the different IoT Agents, offering a simple REST API which provides common
73
+ functionality to access, provision and decommission devices and config groups of devices. This document describes the
74
+ API provided by the IoT Agent node library.
75
+
76
+ # Topics
77
+
78
+ ## Terminology
79
+
80
+ - **Devices**: A resource that match physical devices that are connected to the IoT Agent. Each device has a set of
81
+ attributes that can be read or written and a set of commands that can be invoked. The device is identified by a
82
+ `device_id` and points particular entity in the context broker.
83
+ - **Config Groups**: Also known as `provisioning groups` or `service groups`. A logical group of devices. Each Config
84
+ Group has a set of attributes that can be read or written. The config group is identified by a an `apikey`, used to
85
+ authenticate the requests coming from the devices.
86
+ - **Measurements**: A set of values that are sent by a device to the IoT Agent.
87
+ - **Service**: It is the `FIWARE-Service` that the device or config group belongs to.
88
+ - **Subservice**: It is the specific `FIWARE-ServicePath` that the device or config group belongs to.
89
+ - **provision**: The process of creating a new device. A device provisioned means that the device has been already
90
+ created in the IoT Agent. It can also refer to the group creation process.
91
+ - **autoprovision**: The process of creating a new device when a measure arrives to the IoT Agent and the device is
92
+ not provisioned yet. The attributes, entity type and other information is taken from the config group, and entity
93
+ name is generated according to the entity type and device ID or as a result of an expression if `entityNameExp` is
94
+ defined.
95
+
96
+ ## IoT Agent information model
97
+
98
+ IoT Agents models 2 different kinds of resources: devices and config groups. Devices are the physical devices that send
99
+ measurements to the IoT Agent. Config groups are logical groups of devices that share the same configuration. A config
100
+ group contains zero or more devices.
101
+
102
+ ```mermaid
103
+ erDiagram
104
+ "Config Group" ||--o{ Devices : contains
105
+ ```
106
+
107
+ ### Config groups
108
+
109
+ Config groups provides a template configuration for the all devices that belong to them. This allows to provision a set
110
+ of devices with a single operation. They are identified by an `apikey` and a `resource` and mapped to a particular
111
+ entity type.
112
+
113
+ Once a measure is received by the IoT Agent, the `apikey` and `resource` are used to identify the config group to which
114
+ the device belongs. The config group is used to map the measure to a particular entity type and to provide the
115
+ information needed to interact with the Context Broker.
116
+
117
+ If the device already exists in the Context Broker, the IoT Agent will update the entity with the new values. If the
118
+ device does not exist, the IoT Agent will create it with the information provided by the config group and eventually
119
+ will also create the entity in the Context Broker. This last operation is only possible if the IoT Agent is configured
120
+ to use autoprovisioning.
121
+
122
+ For every config group, the pair (resource, apikey) _must_ be unique (as it is used to identify which group to assign to
123
+ which device). Those operations of the API targeting specific resources will need the use of the `resource` and `apikey`
124
+ parameters to select the appropriate instance.
125
+
126
+ Config groups can be created with preconfigured sets of attributes, service information, security information and other
127
+ parameters. The specific parameters that can be configured for a given config group are described in the
128
+ [Config group datamodel](#config-group-datamodel) section.
129
+
130
+ ### Devices
131
+
132
+ A device contains the information that connects a physical device to a particular entity in the Context Broker. Devices
133
+ are identified by a `device_id`, and they are associated to an existing config group based in `apiKey` matching or
134
+ `type` matching (in the case `apiKey` matching fails). For instance, let's consider a situation in which a config group
135
+ has been provisioned with `type=X`/`apiKey=111` and no other config group has been provisioned.
136
+
137
+ The IoT Agents offer a provisioning API where devices can be preregistered, so all the information about service and
138
+ subservice mapping, security information and attribute configuration can be specified in a per device way instead of
139
+ relaying on the config group configuration. The specific parameters that can be configured for a given device are
140
+ described in the [Device datamodel](#device-datamodel) section.
141
+
142
+ If devices are not pre-registered, they will be automatically created when a measure arrives to the IoT Agent - this
143
+ process is known as autoprovisioning. The IoT Agent will create an empty device with the group `apiKey` and `type` - the
144
+ associated document created in database doesn't include config group parameters (in particular, `timestamp`,
145
+ `explicitAttrs`, `active` or `attributes`, `static` and `lazy` attributes and commands). The IoT Agent will also create
146
+ the entity in the Context Broker if it does not exist yet.
147
+
148
+ This behavior allows that autoprovisioned parameters can freely established modifying the device information after
149
+ creation using the provisioning API. However, note that if a device (autoprovisioned or not) doesn't have these
150
+ parameters defined at device level in database, the parameters are inherit from config group parameters.
151
+
152
+ ## Entity attributes
153
+
154
+ In the config group/device model there are four list of attributes with different purpose to configure how the
155
+ information coming from the device is mapped to the Context Broker attributes:
156
+
157
+ - **`attributes`**: Are measures that are pushed from the device to the IoT agent. This measure changes will be sent
158
+ to the Context Broker as updateContext requests over the device entity. NGSI queries to the context broker will be
159
+ resolved in the Broker database. For each attribute, its `name` and `type` must be provided. Additional `metadata`
160
+ is optional.
161
+
162
+ - **`lazy`**: Passive measures that are pulled from the device to the IoT agent. When a request for data from a lazy
163
+ attribute arrives to the Context Broker, it forwards the request to the Context Provider of that entity, in this
164
+ case the IoT Agent. The IoT Agent will then ask the device for the information needed, transform that information to
165
+ a NGSI format and return it to the Context Broker. This operation will be synchronous from the customer perspective:
166
+ the Context Broker won't return a response until the device has returned its response to the IoT Agent. For each
167
+ attribute, its `name` and `type` must be provided.
168
+
169
+ - **`static`**: It is static attributes that are persisted in the Context Broker. They are not updated by the device,
170
+ but they can be modified by the user. They are useful to store information about the device that is not updated by
171
+ the device itself. For instance, a `location` static attribute is can be used to store the location of a fixed
172
+ device.
173
+
174
+ - **`commands`**: Commands are actions that can be invoked in the device. They are similar to attributes, but they are
175
+ not updated by the device. They are updated by the Context Broker, and the IoT Agent will be in charge of
176
+ translating the updateContext request to the proper action in the device. Two additional attributes are created for
177
+ each command: `status` and `info`. For each command, its `name` and `type` must be provided.
178
+
179
+ All of them have the same syntax, a list of objects with the following attributes:
180
+
181
+ - **object_id** (optional): name of the attribute as coming from the device.
182
+ - **name** (mandatory): ID of the attribute in the target entity in the Context Broker.
183
+ - **type** (mandatory): name of the type of the attribute in the target entity.
184
+ - **metadata** (optional): additional static metadata for the attribute in the target entity. (e.g. `unitCode`)
185
+
186
+ Some transformation plugins also allow the use of the following optional fields:
187
+
188
+ - **expression**: indicates that the value of the target attribute will not be the plain value or the measurement, but
189
+ an expression based on a combination of the reported values. See the
190
+ [Expression Language definition](#expression-language-support) for details
191
+ - **skipValue**: indicates that if the result of applying `expression` to a measure is equal to the value of
192
+ `skipValue` then the attribute corresponding to the measure is not sent to CB. In other words, this field **is not
193
+ an expression**, it is a value that is compared with the result of applying `expression` to a measure. By default if
194
+ `skipValue` is not defined then is considered as `null` (i.e. if the result of apply `expression` results in `null`
195
+ then corresponding attribute is not sent to CB). It is only used if `expression` is provided (otherwise is ignored).
196
+ - **entity_name**: the presence of this attribute indicates that the value will not be stored in the original device
197
+ entity but in a new entity with an ID given by this attribute. The type of this additional entity can be configured
198
+ with the `entity_type` attribute. If no type is configured, the device entity type is used instead. Entity names can
199
+ be defined as expressions, using the [Expression Language definition](#expression-language-support).
200
+ - **entity_type**: configures the type of an alternative entity.
201
+
202
+ Additionally for commands (which are attributes of type `command`) the following fields are optional:
203
+
204
+ - **expression** indicates that the value of the target command will not be the plain value or the command, but an
205
+ expression based on a combination of the returned values. See the
206
+ [Expression Language definition](#expression-language-support) for details
207
+ - **payloadType**: indicates how command payload will be transformed before be sent to device. Please have a look to
208
+ particular IOTAs documentation for allowed values of this field in each case.
209
+ - **contentType**: `content-type` header used when send command by HTTP transport (ignored in other kinds of
210
+ transports)
211
+
212
+ ## Multientity support
213
+
214
+ The IOTA is able to persists measures coming from a single device to more than one entity, declaring the target entities
215
+ through the config group or device provision APIs.
216
+
217
+ ```json
218
+ {
219
+ "devices": [
220
+ {
221
+ "protocol": "IoTA-UL",
222
+ "entity_name": "urn:ngsi-ld:Device:contador12",
223
+ "entity_type": "multientity",
224
+ "attributes": [
225
+ {
226
+ "object_id": "cont1",
227
+ "name": "vol",
228
+ "type": "Text",
229
+ "entity_name": "urn:ngsi-ld:Device:WaterMeterSoria01",
230
+ "entity_type": "WaterMeter"
231
+ },
232
+ {
233
+ "object_id": "cont2",
234
+ "name": "vol",
235
+ "type": "Text",
236
+ "entity_name": "urn:ngsi-ld:Device:WaterMeterSoria02",
237
+ "entity_type": "WaterMeter"
238
+ },
239
+ {
240
+ "object_id": "cont3",
241
+ "name": "vol",
242
+ "type": "Text",
243
+ "entity_name": "urn:ngsi-ld:Device:WaterMeterSoria03",
244
+ "entity_type": "WaterMeter"
245
+ }
246
+ ],
247
+ "device_id": "contador12"
248
+ }
249
+ ]
250
+ }
251
+ ```
252
+
253
+ ## Metadata support
254
+
255
+ Both `attributes` and `static_attributes` may be supplied with metadata when creating a config group, so that the units
256
+ of measurement can be placed into the resultant entity.
257
+
258
+ e.g.:
259
+
260
+ ```json
261
+ {
262
+ "entity_type": "Lamp",
263
+ "resource": "/iot/d",
264
+ "protocol": "PDI-IoTA-UltraLight",
265
+ ..etc
266
+ "commands": [
267
+ {"name": "on","type": "command"},
268
+ {"name": "off","type": "command"}
269
+ ],
270
+ "attributes": [
271
+ {"object_id": "s", "name": "state", "type":"Text"},
272
+ {"object_id": "l", "name": "luminosity", "type":"Integer",
273
+ "metadata":{
274
+ "unitCode":{"type": "Text", "value" :"CAL"}
275
+ }
276
+ }
277
+ ],
278
+ "static_attributes": [
279
+ {"name": "category", "type":"Text", "value": ["actuator","sensor"]},
280
+ {"name": "controlledProperty", "type": "Text", "value": ["light"],
281
+ "metadata":{
282
+ "includes":{"type": "Text", "value" :["state", "luminosity"]},
283
+ "alias":{"type": "Text", "value" :"lamp"}
284
+ }
285
+ },
286
+ ]
287
+ }
288
+ ```
289
+
290
+ ### NGSI-LD data and metadata considerations
291
+
292
+ When provisioning devices for an NGSI-LD Context Broker, `type` values should typically correspond to one of the
293
+ following:
294
+
295
+ - `Property`, `Relationship`, `GeoProperty`, `LanguageProperty`
296
+ - Native JSON types (e.g. `String`, `Boolean`, `Float` , `Integer` `Number`)
297
+ - Temporal Properties (e.g. `Datetime`, `Date` , `Time`)
298
+ - GeoJSON types (e.g `Point`, `LineString`, `Polygon`, `MultiPoint`, `MultiLineString`, `MultiPolygon`)
299
+
300
+ Most NGSI-LD attributes are sent to the Context Broker as _properties_. If a GeoJSON type or native JSON type is
301
+ defined, the data will be converted to the appropriate type. Temporal properties should always be expressed in UTC,
302
+ using ISO 8601. This ISO 8601 conversion is applied automatically for the `observedAt` _property-of-a-property_ metadata
303
+ where present.
304
+
305
+ Data for any attribute defined as a _relationship_ must be a valid URN.
306
+
307
+ Note that when the `unitCode` metadata attribute is supplied in the provisioning data under NGSI-LD, the standard
308
+ `unitCode` _property-of-a-property_ `String` attribute is created.
309
+
310
+ Other unrecognised `type` attributes will be passed as NGSI-LD data using the following JSON-LD format:
311
+
312
+ ```json
313
+ "<property_name>": {
314
+ "type" : "Property",
315
+ "value": {
316
+ "@type": "<property_type>",
317
+ "@value": { string or object}
318
+ }
319
+ }
320
+ ```
321
+
322
+ `null` values will be passed in the following format:
323
+
324
+ ```json
325
+ "<property_name>": {
326
+ "type" : "Property",
327
+ "value": {
328
+ "@type": "Intangible",
329
+ "@value": null
330
+ }
331
+ }
332
+ ```
333
+
334
+ ## Advice on Attribute definitions
335
+
336
+ ### Reuse of attribute names
337
+
338
+ Check for the existence of the same Attribute on any of the other models and reuse it, if pertinent. Have a look at
339
+ schema.org trying to find a similar term with the same semantics. Try to find common used ontologies or existing
340
+ standards well accepted by the Community, or by goverments, agencies, etc. For instance, Open311 for civic issue
341
+ tracking or Datex II for transport systems.
342
+
343
+ ### Reuse of attribute types
344
+
345
+ When possible reuse [schema.org](http://schema.org/) data types (`Text`, `Number`, `DateTime`, `StructuredValue`, etc.).
346
+ Remember that `null` is not allowed in NGSI-LD and therefore should be avoided as a value.
347
+
348
+ ### How to specify attribute Units of Measurement
349
+
350
+ If your data use the default unit defined in the Data Model, you don't need to specify any. It is implied. Unless
351
+ explicitly stated otherwise, all FIWARE data models use the metric system of measurements by default. Regardless the
352
+ model specification include explicit reference to the scale adopted. If your data use a different unit, you will need to
353
+ use the `unitCode` metadata annotation in your data (and you will need to adopt the normalised representation). The code
354
+ used should be taken from those defined by
355
+ [UN/CEFACT](https://www.unece.org/fileadmin/DAM/cefact/recommendations/rec20/rec20_rev3_Annex3e.pdf). E.g.:
356
+
357
+ ```json
358
+ {
359
+ "object_id": "l",
360
+ "name": "length",
361
+ "type": "Integer",
362
+ "metadata": {
363
+ "unitCode": { "type": "Text", "value": "FOT" }
364
+ }
365
+ }
366
+ ```
367
+
368
+ ## Measurement persistence options
369
+
370
+ There are 2 different options to configure how the IoTAgent stores the measures received from the devices, depending on
371
+ the following parameters:
372
+
373
+ - `autoprovision`: If the device is not provisioned, the IoTAgent will create a new device and entity for it.
374
+ - `explicitAttrs`: If the measure element (object_id) is not defined in the mappings of the device or config group
375
+ provision, the measure is stored in the Context Broker by adding a new attribute to the entity with the same name of
376
+ the undefined measure element.
377
+
378
+ ### Autoprovision configuration (autoprovision)
379
+
380
+ By default, when a measure arrives to the IoTAgent, if the `device_id` does not match with an existing one, then, the
381
+ IoTA creates a new device and a new entity according to the config group. Defining the field `autoprovision` to `false`
382
+ when provisioning the config group, the IoTA to reject the measure at the southbound, allowing only to persist the data
383
+ to devices that are already provisioned. It makes no sense to use this field in device provisioning since it is intended
384
+ to avoid provisioning devices (and for it to be effective, it would have to be provisional). Further information can be
385
+ found in section [Devices](#devices)
386
+
387
+ ### Explicitly defined attributes (explicitAttrs)
388
+
389
+ If a given measure element (object_id) is not defined in the mappings of the device or config group, the measure is
390
+ stored in the Context Broker by adding a new attribute to the entity with the same name of the undefined measure
391
+ element. By adding the field `explicitAttrs` with `true` value to device or config group, the IoTAgent rejects the
392
+ measure elements that are not defined in the mappings of device or config group, persisting only the one defined in the
393
+ mappings of the provision. If `explicitAttrs` is provided both at device and config group level, the device level takes
394
+ precedence. Additionally `explicitAttrs` can be used to define which measures (identified by their attribute names, not
395
+ by their object_id) defined in JSON/JEXL array will be propagated to NGSI interface.
396
+
397
+ The different possibilities are summarized below:
398
+
399
+ Case 1 (default):
400
+
401
+ ```
402
+ "explicitAttrs": false
403
+ ```
404
+
405
+ every measure will be propagated to NGSI interface.
406
+
407
+ Case 2:
408
+
409
+ ```
410
+ "explicitAttrs": true
411
+ ```
412
+
413
+ just measures defined in active, static (plus conditionally TimeInstant) will be propagated to NGSI interface.
414
+
415
+ Case 3:
416
+
417
+ ```
418
+ "explicitAttrs": "['attr1','atrr2']"
419
+ ```
420
+
421
+ just NGSI attributes defined in the array (identified by their attribute names, not by their object_id, plus
422
+ conditionally TimeInstant) will be propagated to NGSI interface (note that in this case the value of `explicitAttrs` is
423
+ not a JSON but a JEXL Array that looks likes a JSON).
424
+
425
+ Case 4:
426
+
427
+ ```
428
+ "explicitAttrs": "['attr1','atrr2',{object_id:'active_id'}]"
429
+ ```
430
+
431
+ just NGSI attributes defined in the array (identified by their attribute names and/or by their object_id) will be
432
+ propagated to NGSI interface (note that in this case the value of `explicitAttrs` is not a JSON but a JEXL Array/Object
433
+ that looks likes a JSON). This is necessary when same attribute names are used within multiple entities.
434
+
435
+ Case 5:
436
+
437
+ ```
438
+ "explicitAtttr": "<JEXL expression resulting in bool or array>"
439
+ ```
440
+
441
+ depending on the JEXL expression evaluation:
442
+
443
+ - If it evaluates to `true` every measure will be propagated to NGSI interface (as in case 1)
444
+ - If it evaluates to `false` just measures defined in active, static (plus conditionally TimeInstant) will be
445
+ propagated to NGSI interface (as in case 2)
446
+ - If it evaluates to an array just measures defined in the array (identified by their attribute names, not by their
447
+ object_id) will be will be propagated to NGSI interface (as in case 3)
448
+
449
+ ### Differences between `autoprovision`, `explicitAttrs`
450
+
451
+ Since those configuration parameters are quite similar, this section is intended to clarify the relation between them.
452
+
453
+ If `autoprovision` is set to `true` (default case), the agent will perform an initial request creating a new entity into
454
+ the Context Broker with **only** the static and active attributes provisioned in the config group, and also a new Device
455
+ in the agent, every time a measure arrives with a new `device_id`. Otherwise, this measure is ignored. This is something
456
+ related to the **southbound**.
457
+
458
+ What `explicitAttrs` does is to filter from the southbound the parameters that are not explicitly defined in the device
459
+ provision or config group. That also would avoid propagating the measures to the Context Broker.
460
+
461
+ ## Expression language support
462
+
463
+ The IoTAgent Library provides an expression language for measurement transformation and other purposes. This expression
464
+ language is based on the [TomFrost/JEXL](https://github.com/TomFrost/Jexl) library. The common usage of this feature is
465
+ to adapt the information coming from the South Bound APIs to the information reported to the Context Broker. This is
466
+ really useful when you need to adapt measure (for example, to change the units, or to apply a formula to). All the usage
467
+ of expression in the IoT Agent are:
468
+
469
+ - [Measurement transformation](#measurement-transformation).
470
+ - Commands payload transformation (push and pull).
471
+ - Auto provisioned devices entity name. It is configured at config Group level by setting the `entityNameExp`
472
+ parameter. It defines an expression to generate the Entity Name for autoprovisioned devices.
473
+ - Dynamic `endpoint` definition. Configured at device level, it defines where the device listen for push http
474
+ commands. It can be either a static value or an expression.
475
+
476
+ The agent provides additional information, hereafter referred as **context**, in order to be used to evaluate the
477
+ expression. In all cases the following data is available to all expressions:
478
+
479
+ - `id`: device ID
480
+ - `entity_name`: NGSI entity Name (principal)
481
+ - `type`: NGSI entity type (principal)
482
+ - `service`: device service
483
+ - `subservice`: device subservice
484
+ - `staticAttributes`: static attributes defined in the device or config group
485
+
486
+ Additionally, for attribute expressions (`expression`, `entity_name`) and `entityNameExp` measures are avaiable in the
487
+ **context** used to evaluate them.
488
+
489
+ ### Examples of JEXL expressions
490
+
491
+ The following table shows expressions and their expected outcomes taking into account the following measures at
492
+ southbound interface:
493
+
494
+ - `value` with value 6 (number)
495
+ - `ts` with value 1637245214901 (unix timestamp)
496
+ - `name` with value `"DevId629"` (string)
497
+ - `object` with value `{name: "John", surname: "Doe"}` (JSON object)
498
+ - `array` with value `[1, 3]` (JSON Array)
499
+
500
+ | Expression | Expected outcome | Format | Playground |
501
+ | :-------------------------------------------- | :---------------------------------------- | ------------------- | ------------- |
502
+ | `5 * value` | `30` | Integer | [Example][6] |
503
+ | `(6 + value) * 3` | `36` | Integer | [Example][7] |
504
+ | `value / 12 + 1` | `1.5` | Float | [Example][8] |
505
+ | `(5 + 2) * (value + 7)` | `91` | Integer | [Example][9] |
506
+ | `value * 5.2` | `31.2` | Float | [Example][10] |
507
+ | `"Pruebas " + "De Strings"` | `"Pruebas De Strings"` | String | [Example][11] |
508
+ | `name + "value is " +value` | `"DevId629 value is 6"` | String | [Example][12] |
509
+ | `{coordinates: [value,value], type: 'Point'}` | `{"coordinates": [6,6], "type": "Point"}` | GeoJSON `Object` | [Example][13] |
510
+ | <code>ts&vert;toisodate</code> | `2021-11-18T14:20:14.901Z` | ISO 8601 `DateTime` | [Example][14] |
511
+
512
+ Support for `trim`, `length`, `substr` and `indexOf` transformations was added.
513
+
514
+ | Expression | Expected outcome | Playground |
515
+ | :-------------------------------------------------------- | :--------------- | ------------- |
516
+ | <code>" a "&vert; trim</code> | `a` | [Example][15] |
517
+ | <code>name&vert;length</code> | `8` | [Example][16] |
518
+ | <code>name&vert;indexOf("e")</code> | `1` | [Example][17] |
519
+ | <code>name&vert;substr(0,name&vert;indexOf("e")+1)</code> | `"De"` | [Example][18] |
520
+
521
+ ### Available functions
522
+
523
+ There are several predefined JEXL transformations available to be used at any JEXL expression. The definition of those
524
+ transformations and their JavaScript implementation can be found at jexlTransformsMap.js.
525
+
526
+ The library module also exports a method `iotAgentLib.dataPlugins.expressionTransformation.setJEXLTransforms(Map)` to be
527
+ used by specific IoT Agent implementations in order to incorporate extra transformations to this set. It is important to
528
+ remark that the lib `jexlTransformsMap` cannot be overwritten by the API additions. The idea behind this is to be able
529
+ to incorporate new transformations from the IoT Agent configuration file in a fast and tactical way.
530
+
531
+ Current common transformation set:
532
+
533
+ | JEXL Transformation | Equivalent JavaScript Function |
534
+ | ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------- |
535
+ | jsonparse: (str) | `JSON.parse(str);` |
536
+ | jsonstringify: (obj) | `JSON.stringify(obj);` |
537
+ | indexOf: (val, char) | `String(val).indexOf(char);` |
538
+ | length: (val) | `String(val).length;` |
539
+ | trim: (val) | `String(val).trim();` |
540
+ | substr: (val, int1, int2) | `String(val).substr(int1, int2);` |
541
+ | addreduce: (arr) | <code>arr.reduce((i, v) &vert; i + v));</code> |
542
+ | lengtharray: (arr) | `arr.length;` |
543
+ | typeof: (val) | `typeof val;` |
544
+ | isarray: (arr) | `Array.isArray(arr);` |
545
+ | isnan: (val) | `isNaN(val);` |
546
+ | parseint: (val) | `parseInt(val);` |
547
+ | parsefloat: (val) | `parseFloat(val);` |
548
+ | toisodate: (val) | `new Date(val).toISOString();` |
549
+ | timeoffset:(isostr) | `new Date(isostr).getTimezoneOffset();` |
550
+ | tostring: (val) | `val.toString();` |
551
+ | urlencode: (val) | `encodeURI(val);` |
552
+ | urldecode: (val) | `decodeURI(val);` |
553
+ | replacestr: (str, from, to) | `str.replace(from, to);` |
554
+ | replaceregexp: (str, reg, to) | `str.replace(new RegExp(reg), to);` |
555
+ | replaceallstr: (str, from, to) | `str.replaceAll(from, to);` |
556
+ | replaceallregexp: (str, reg, to) | `str.replaceAll(new RegExp(reg,"g"), to);` |
557
+ | split: (str, ch) | `str.split(ch);` |
558
+ | joinarrtostr: (arr, ch) | `arr.join(ch);` |
559
+ | concatarr: (arr, arr2) | `arr.concat(arr2);` |
560
+ | mapper: (val, values, choices) | <code>choices[values.findIndex((target) &vert; target == val)]);</code> |
561
+ | thmapper: (val, values, choices) | <code>choices[values.reduce((acc,curr,i,arr) &vert; (acc==0)&vert;&vert;acc?acc:val<=curr?acc=i:acc=null,null)];</code> |
562
+ | bitwisemask: (i,mask,op,shf) | <code>(op==="&"?parseInt(i)&mask: op==="&vert;"?parseInt(i)&vert;mask: op==="^"?parseInt(i)^mask:i)>>shf;</code> |
563
+ | slice: (arr, init, end) | `arr.slice(init,end);` |
564
+ | addset: (arr, x) | <code>{ return Array.from((new Set(arr)).add(x)) }</code> |
565
+ | removeset: (arr, x) | <code>{ let s = new Set(arr); s.delete(x); return Array.from(s) }</code> |
566
+ | touppercase: (val) | `String(val).toUpperCase()` |
567
+ | tolowercase: (val) | `String(val).toLowerCase()` |
568
+ | round: (val) | `Math.round(val)` |
569
+ | floor: (val) | `Math.floor(val)` |
570
+ | ceil: (val) | `Math.ceil(val)` |
571
+ | tofixed: (val, decimals) | `Number.parseFloat(val).toFixed(decimals)` |
572
+ | gettime: (d) | `new Date(d).getTime()` |
573
+ | toisostring: (d) | `new Date(d).toISOString()` |
574
+ | localestring: (d, timezone, options) | `new Date(d).toLocaleString(timezone, options)` |
575
+ | now: () | `Date.now()` |
576
+ | hextostring: (val) | `new TextDecoder().decode(new Uint8Array(val.match(/.{1,2}/g).map(byte => parseInt(byte, 16))))` |
577
+
578
+ You have available this [JEXL interactive playground][99] with all the transformations already loaded, in which you can
579
+ test all the functions described above.
580
+
581
+ ### Expressions with multiple transformations
582
+
583
+ When you need to apply multiples transformations to the same value, you can use the pipe character `|` to separate the
584
+ transformations. For example, if you want to apply the `trim` and `replacestr` transformations to a value, you can use
585
+ the following expression:
586
+
587
+ ```json
588
+ {
589
+ "expression": "variable | trim | replacestr('hello','hi')"
590
+ }
591
+ ```
592
+
593
+ If variable takes value `hello world`, the result of the previous expression will be `hi world`.
594
+
595
+ Another example using functions that return more than one value is the following:
596
+
597
+ ```json
598
+ {
599
+ "expression": "location | split(', ')[1] | parsefloat()"
600
+ }
601
+ ```
602
+
603
+ For a location value `"40.4165, -3.70256"`, the result of the previous expression will be `-3.70256`.
604
+
605
+ ## Measurement transformation
606
+
607
+ The IoTAgent Library provides support for measurement transformation using a
608
+ [Expression Language](#expression-language-support) This feature can be used to adapt the information coming from the
609
+ South Bound APIs to the information reported to the Context Broker. This is really useful when you need to adapt measure
610
+ (for example, to change the units, or to apply a formula to).
611
+
612
+ ### Measurement transformation definition
613
+
614
+ Measurement transformation can be defined for Active attributes, either in the Device provisioning or in the config
615
+ group provisioning. The following example shows a device provisioning payload with defined Measurement transformation:
616
+
617
+ ```json
618
+ {
619
+ "devices": [
620
+ {
621
+ "device_id": "45",
622
+ "protocol": "GENERIC_PROTO",
623
+ "entity_name": "WasteContainer:WC45",
624
+ "entity_type": "WasteContainer",
625
+ "attributes": [
626
+ {
627
+ "name": "location",
628
+ "type": "geo:json",
629
+ "expression": "{coordinates: [longitude,latitude], type: 'Point'}"
630
+ },
631
+ {
632
+ "name": "fillingLevel",
633
+ "type": "Number",
634
+ "expression": "level / 100"
635
+ },
636
+ {
637
+ "name": "level",
638
+ "type": "Number"
639
+ },
640
+ {
641
+ "name": "latitude",
642
+ "type": "Number"
643
+ },
644
+ {
645
+ "name": "longitude",
646
+ "type": "Number"
647
+ }
648
+ ]
649
+ }
650
+ ]
651
+ }
652
+ ```
653
+
654
+ [Interactive expression `{coordinates: [longitude,latitude], type: 'Point'}`][1]
655
+
656
+ [Interactive expression `level / 100`][2]
657
+
658
+ The value of the `expression` field defines the measure transformation. is a string that can contain any number of
659
+ expression patterns. In order to complete expression to be evaluated, all the expression patterns must be evaluable
660
+ (there must be a value in the measurement for all the variables of all the expression patterns).
661
+
662
+ Note that you need to include in the provision operation all the attributes required as inputs for the expressions. In
663
+ this example, they are `level`, `latitude` and `longitude`. Otherwise the device sending the measures will get
664
+ `{"name":"ATTRIBUTE_NOT_FOUND","message":"Some of the attributes does not exist"}` when it sends some of these and the
665
+ expression will not be calculated.
666
+
667
+ The exact same syntax works for Configuration and Device provisioning.
668
+
669
+ ### Measurement transformation execution
670
+
671
+ Whenever a new measurement arrives to the IoT Agent for a device with declared expressions, all of the expressions for
672
+ the device will be checked for execution: for all the defined active attributes containing expressions, the IoT Agent
673
+ will check which ones contain expressions whose variables are present in the received measurement. For all of those
674
+ whose variables are covered, their expressions will be executed with the received values, and their values updated in
675
+ the Context Broker.
676
+
677
+ E.g.: if a device with the following provisioning information is created in the IoT Agent:
678
+
679
+ ```json
680
+ {
681
+ "name":"location",
682
+ "type":"geo:point",
683
+ "expression": "longitude+', '+latitude"
684
+ },
685
+ {
686
+ "name":"fillingLevel",
687
+ "type":"Number",
688
+ "expression": "level / 100",
689
+ },
690
+ ```
691
+
692
+ [Interactive expression `longitude+', '+latitude`][3]
693
+
694
+ [Interactive expression `level / 100`][4]
695
+
696
+ and a measurement with the following values arrive to the IoT Agent:
697
+
698
+ ```text
699
+ latitude: 1.9
700
+ level: 85.3
701
+ ```
702
+
703
+ The only expression rule that will be executed will be that of the `fillingLevel` attribute. It will produce the value
704
+ `0.853` that will be sent to the Context Broker.
705
+
706
+ Note that expressions are only applied if the attribute name (as received by the IoT Agent in the southbound interface)
707
+ matches the expression variable. Otherwise, the southbound value is used directly. Let's illustrate with the following
708
+ example:
709
+
710
+ ```json
711
+ "consumption": {
712
+ "type": "String",
713
+ "value": "spaces | trim"
714
+ }
715
+ ```
716
+
717
+ - Case 1: the following measure is received at the southbound interface:
718
+
719
+ ```text
720
+ consumption: "0.44"
721
+ ```
722
+
723
+ As `spaces` attribute is not included, then the expression is not applied and the `consumption` measure value is
724
+ directly used, so the following is sent to CB:
725
+
726
+ ```json
727
+ "consumption": {
728
+ "type": "String",
729
+ "value": "0.44"
730
+ }
731
+ ```
732
+
733
+ - Case 2: the following measure is received at the southbound interface:
734
+
735
+ ```text
736
+ consumption: "0.44"
737
+ spaces: " foobar "
738
+ ```
739
+
740
+ As `spaces` attribute is included, then the expression is evaluated, so overriding the 0.44 value and sending the
741
+ following to CB:
742
+
743
+ ```json
744
+ "consumption": {
745
+ "type": "String",
746
+ "value": "foobar"
747
+ }
748
+ ```
749
+
750
+ [Interactive expression `spaces | trim`][5]
751
+
752
+ ### Multientity measurement transformation support (`object_id`)
753
+
754
+ To allow support for measurement transformation in combination with multi entity plugin, where the same attribute is
755
+ generated for different entities out of different incoming attribute values (i.e. `object_id`), we introduced support
756
+ for `object_id` in the expression context.
757
+
758
+ For example, the following device:
759
+
760
+ ```json
761
+ "WeatherStation": {
762
+ "commands": [],
763
+ "type": "WeatherStation",
764
+ "lazy": [],
765
+ "active": [
766
+ {
767
+ "object_id": "v1",
768
+ "name": "vol",
769
+ "expression" : "v1*100",
770
+ "type": "Number",
771
+ "entity_name": "WeatherStation1"
772
+ },
773
+ {
774
+ "object_id": "v2",
775
+ "name": "vol",
776
+ "expression" : "v2*100",
777
+ "type": "Number",
778
+ "entity_name": "WeatherStation2"
779
+ },
780
+ {
781
+ "object_id": "v",
782
+ "name": "vol",
783
+ "expression" : "v*100",
784
+ "type": "Number"
785
+ }
786
+ ]
787
+ }
788
+ ```
789
+
790
+ When receiving the measures `v`, `v1` and `v2` in a payload from a message received in the southbound (using as an
791
+ example a payload for the [IoT Agent JSON](https://github.com/telefonicaid/iotagent-json)):
792
+
793
+ ```json
794
+ {
795
+ "v": 0
796
+ },
797
+ {
798
+ "v1": 1
799
+ },
800
+ {
801
+ "v2": 2
802
+ }
803
+ ```
804
+
805
+ Will now generate the following NGSI v2 payload:
806
+
807
+ ```json
808
+ {
809
+ "actionType": "append",
810
+ "entities": [
811
+ {
812
+ "id": "ws9",
813
+ "type": "WeatherStation",
814
+ "vol": {
815
+ "type": "Number",
816
+ "value": 0
817
+ }
818
+ },
819
+ {
820
+ "vol": {
821
+ "type": "Number",
822
+ "value": 100
823
+ },
824
+ "type": "WeatherStation",
825
+ "id": "WeatherStation1"
826
+ },
827
+ {
828
+ "vol": {
829
+ "type": "Number",
830
+ "value": 200
831
+ },
832
+ "type": "WeatherStation",
833
+ "id": "WeatherStation2"
834
+ }
835
+ ]
836
+ }
837
+ ```
838
+
839
+ ## Timestamp Compression
840
+
841
+ This functionality changes all the timestamp attributes found in the entity, and all the timestamp metadata found in any
842
+ attribute, from the basic complete calendar timestamp of the ISO8601 (e.g.: 20071103T131805) to the extended complete
843
+ calendar timestamp (e.g.: +002007-11-03T13:18). The middleware expects to receive the basic format in updates and return
844
+ it in queries (and viceversa, receive the extended one in queries and return it in updates).
845
+
846
+ ## Timestamp Processing
847
+
848
+ The IOTA processes the entity attributes looking for a `TimeInstant` attribute. If one is found, for NGSI v2, the plugin
849
+ adds a `TimeInstant` attribute as metadata for every other attribute in the same request. With NGSI-LD, the Standard
850
+ `observedAt` property-of-a-property is used instead.
851
+
852
+ ## Overriding global Context Broker host
853
+
854
+ **cbHost**: Context Broker host URL. This option can be used to override the global CB configuration for specific types
855
+ of devices.
856
+
857
+ ## Multitenancy, FIWARE Service and FIWARE ServicePath
858
+
859
+ Every operation in the API require the `fiware-service` and `fiware-servicepath` to be defined; the operations are
860
+ performed in the scope of those headers. For the list case, the special wildcard servicepath can be specified, `/*`. In
861
+ this case, the operation applies to all the subservices of the service given by the `fiware-service` header.
862
+
863
+ ## Secured access to the Context Broker
864
+
865
+ For access to instances of the Context Broker secured with a
866
+ [PEP Proxy](https://github.com/telefonicaid/fiware-orion-pep), an authentication mechanism based in Keystone Trust
867
+ tokens is provided. A trust token is a way of Keystone to allow an user delegates a role to another user for a
868
+ subservice. It is a long-term token that can be issued by any user to give another user permissions to impersonate him
869
+ with a given role in a given project (subservice). Such impersonation itself is in turn based on a short-term access
870
+ token.
871
+
872
+ For the authentication mechanisms to work, the `authentication` attribute in the configuration has to be fully
873
+ configured, and the `authentication.enabled` subattribute should have the value `true`.
874
+
875
+ When the administrator of a service is configuring a set of devices or device types in the IoT Agent to use a secured
876
+ Context Broker, he should follow this steps:
877
+
878
+ - First, a Trust Token ID should be requested to Keystone, using the service administrator credentials, the role ID
879
+ and the IoT Agent User ID. The Trust token can be retrieved using the following request (shown as a curl command):
880
+
881
+ ```bash
882
+ curl http://${KEYSTONE_HOST}/v3/OS-TRUST/trusts \
883
+ -s \
884
+ -H "X-Auth-Token: $ADMIN_TOKEN" \
885
+ -H "Content-Type: application/json" \
886
+ -d '
887
+ {
888
+ "trust": {
889
+ "impersonation": false,
890
+ "project_id": "'$SUBSERVICE_ID'",
891
+ "roles": [
892
+ {"id": "'$ID_ROLE'"
893
+ }
894
+ ],
895
+ "trustee_user_id": "'$ID_IOTAGENT_USER'",
896
+ "trustor_user_id": "'$ID_ADM1'"
897
+ }
898
+ }'
899
+ ```
900
+
901
+ - Every device or type of devices configured to use a secured Context Broker must be provided with a Trust Token ID in
902
+ its configuration.
903
+ - Before any request is sent to a secured Context Broker, the IoT Agent uses the Trust Token ID to generate a
904
+ temporary access token, that is attached to the request (in the `X-Auth-token` header) (using Keystone API
905
+ https://developer.openstack.org/api-ref/identity/v3-ext/#consuming-a-trust).
906
+
907
+ Apart from the generation of the trust, the use of secured Context Brokers should be transparent to the user of the IoT
908
+ Agent.
909
+
910
+ Complete info on Keystone trust tokens could be found at:
911
+
912
+ - [Trusts concept](https://docs.openstack.org/keystone/stein/user/trusts)
913
+ - [Trusts API](https://docs.openstack.org/keystone/stein/api_curl_examples.html#post-v3-os-trust-trusts)
914
+
915
+ ## NGSI-LD Support
916
+
917
+ ### NGSI-LD `GeoProperty` support
918
+
919
+ For NGSI-LD only, the defined `type` of any GeoJSON attribute can be any set using any of the standard NGSI-v2 GeoJSON
920
+ types - (e.g. `geo:json`, `geo:point`). NGSI-LD formats such as `GeoProperty`, `Point` and `LineString` are also
921
+ accepted `type` values. If the latitude and longitude are received as separate measures,
922
+ [measurement transformation](#measurement-transformation) can be used to concatenate them into GeoJSON objects an array
923
+ of tuples or a string as shown
924
+
925
+ #### Encode as GeoJSON
926
+
927
+ ```json
928
+ {
929
+ "entity_type": "GPS",
930
+ "resource": "/iot/d",
931
+ "protocol": "PDI-IoTA-JSON",
932
+ ..etc
933
+ "attributes": [
934
+ {
935
+ "name": "location",
936
+ "type": "geo:json",
937
+ "expression": "{coordinates: [longitude,latitude], type: 'Point'}"
938
+ }
939
+ ]
940
+ }
941
+ ```
5
942
 
6
- ## About API
943
+ JEXL can be used to create GeoJSON objects directly. For `attributes` and `static_attributes` which need to be formatted
944
+ as GeoJSON values, three separate input formats are currently accepted. Provided the `type` is provisioned correctly,
945
+ the `value` may be defined using any of the following formats:
7
946
 
8
- A GET request to the `/iot/about` path, will return a payload similar to the following:
947
+ - a comma delimited string
9
948
 
10
949
  ```json
11
950
  {
12
- "libVersion": "2.7.0",
13
- "port": "4041",
14
- "baseRoot": "/",
15
- "version": "1.7.0"
951
+ "name": "location",
952
+ "value": "23, 12.5"
953
+ }
954
+ ```
955
+
956
+ - an array of numbers
957
+
958
+ ```json
959
+ {
960
+ "name": "location",
961
+ "value": [23, 12.5]
962
+ }
963
+ ```
964
+
965
+ - an fully formatted GeoJSON object
966
+
967
+ ```json
968
+ {
969
+ "name": "location",
970
+ "value": {
971
+ "type": "Point",
972
+ "coordinates": [23, 12.5]
973
+ }
974
+ }
975
+ ```
976
+
977
+ ### NGSI-LD Linked Data support
978
+
979
+ `static_attributes` may be supplied with an additional `link` data element when provisioning an IoT Agent to ensure that
980
+ active attributes from the provisioned IoT Device may be maintained in parallel with a linked data entity . Take for
981
+ example a temperature gauge placed within a building. The **Device** data model literally represents the IoT device
982
+ itself, but the `temperature` attribute also needs to be shared with the **Building** entity
983
+
984
+ A `link` between them can be provisioned as shown:
985
+
986
+ e.g.:
987
+
988
+ ```json
989
+ {
990
+ "entity_type": "Device",
991
+ "resource": "/iot/d",
992
+ "protocol": "PDI-IoTA-UltraLight",
993
+ ..etc
994
+ "attributes": [
995
+ {"object_id": "l", "name": "temperature", "type":"Float",
996
+ "metadata":{
997
+ "unitCode":{"type": "Text", "value" :"CEL"}
998
+ }
999
+ }
1000
+ ],
1001
+ "static_attributes": [
1002
+ {
1003
+ "name": "controlledAsset",
1004
+ "type": "Relationship",
1005
+ "value": "urn:ngsi-ld:Building:001",
1006
+ "link": {
1007
+ "attributes": ["temperature"],
1008
+ "name": "providedBy",
1009
+ "type": "Building"
1010
+ }
1011
+ }
1012
+ ]
1013
+ }
1014
+ ```
1015
+
1016
+ Whenever a `temperature` measure is received **Device** is updated, and entity `urn:ngsi-ld:Building:001` is also
1017
+ updated as shown:
1018
+
1019
+ ```json
1020
+ "temperature": {
1021
+ "type": "Property",
1022
+ "value": 27.6,
1023
+ "unitCode": "CEL",
1024
+ "providedBy": {
1025
+ "type": "Relationship",
1026
+ "object": "urn:ngsi-ld:Device:thermometer1"
1027
+ }
16
1028
  }
17
1029
  ```
18
1030
 
19
- the `version` field will be read from the `iotaVersion` field of the config, if it exists. It can be used as a heartbeat
20
- operation to check the health of the IoT Agent if required.
1031
+ #### NGSI-LD `datasetId` support
1032
+
1033
+ Limited support for parsing the NGSI-LD `datasetId` attribute is included within the library. A series of sequential
1034
+ commands for a single attribute can be sent as an NGSI-LD notification as follows:
1035
+
1036
+ ```json
1037
+ {
1038
+ "id": "urn:ngsi-ld:Notification:5fd0fa684eb81930c97005f3",
1039
+ "type": "Notification",
1040
+ "subscriptionId": "urn:ngsi-ld:Subscription:5fd0f69b4eb81930c97005db",
1041
+ "notifiedAt": "2020-12-09T16:25:12.193Z",
1042
+ "data": [
1043
+ {
1044
+ "lampColor": [
1045
+ {
1046
+ "type": "Property",
1047
+ "value": { "color": "green", "duration": "55 secs" },
1048
+ "datasetId": "urn:ngsi-ld:Sequence:do-this"
1049
+ },
1050
+ {
1051
+ "type": "Property",
1052
+ "value": { "color": "red", "duration": "10 secs" },
1053
+ "datasetId": "urn:ngsi-ld:Sequence:then-do-this"
1054
+ }
1055
+ ]
1056
+ }
1057
+ ]
1058
+ }
1059
+ ```
21
1060
 
22
- ## Service Group API
1061
+ This results in the following sequential array of attribute updates to be sent to the `NotificationHandler` of the IoT
1062
+ Agent itself:
23
1063
 
24
- For some services, there will be no need to provision individual devices, but it will make more sense to provision
25
- different service groups, each of one mapped to a different type of entity in the context broker. How the type of entity
26
- is assigned to a device will depend on the Southbound technology (e.g.: path, port, APIKey...). Once the device has an
27
- assigned type, its configuration values can be extracted from those of the type.
1064
+ ```json
1065
+ [
1066
+ {
1067
+ "name": "lampColor",
1068
+ "type": "Property",
1069
+ "datasetId": "urn:ngsi-ld:Sequence:do-this",
1070
+ "metadata": {},
1071
+ "value": { "color": "green", "duration": "55 secs" }
1072
+ },
1073
+ {
1074
+ "name": "lampColor",
1075
+ "type": "Property",
1076
+ "datasetId": "urn:ngsi-ld:Sequence:then-do-this",
1077
+ "metadata": {},
1078
+ "value": { "color": "red", "duration": "10 secs" }
1079
+ }
1080
+ ]
1081
+ ```
28
1082
 
29
- The IoT Agents provide two means to define those service groups:
1083
+ A `datasetId` is also maintained for each new attribute defined in the `reverse` field.
30
1084
 
31
- - Static **Type Configuration**: configuring the `ngsi.types` attribute within the `config.js` file.
32
- - Dynamic **Configuration API**: making use of the API URLs in the configuration URI, `/iot/services`. Please, note
33
- that the configuration API manage servers under a URL that requires the `server.name` parameter to be set (the name
34
- of the IoT Agent we are using). If no name is configured `default` is taken as the default one.
1085
+ # API Routes
35
1086
 
36
- Both approaches provide the same configuration information for the types and end up in the same configuration
37
- collection, they are described in the sections below.
1087
+ ## Config group API
38
1088
 
39
- The following sections show the available operations for the Configuration API. Every operation in the API require the
40
- `fiware-service` and `fiware-servicepath` to be defined; the operations are performed in the scope of those headers. For
41
- the list case, the special wildcard servicepath can be specified, `/*`. In this case, the operation applies to all the
42
- subservices of the service given by the `fiware-service` header.
1089
+ ### Config group datamodel
43
1090
 
44
- For every service group, the pair (resource, apikey) _must_ be unique (as it is used to identify which group to assign
45
- to which device). Those operations of the API targeting specific resources will need the use of the `resource` and
46
- `apikey` parameters to select the appropriate instance.
1091
+ Config group is represented by a JSON object with the following fields:
47
1092
 
48
- Note that there is a 1:1 correspondence between payload fields and DB fields (but with some changes in the attribute
49
- naming; e.g.: subservice -> service_path).
1093
+ | Field | Optional | Type | Expression | Definitiom |
1094
+ | ------------------------------ | -------- | -------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1095
+ | `service` | | string | | `FIWARE-Service` header to be used |
1096
+ | `subservice` | | string | | Subservice of the devices of this type. |
1097
+ | `resource` | | string | | string representing the Southbound resource that will be used to assign a type to a device (e.g.: pathname in the southbound port). |
1098
+ | `apikey` | | string | | API Key string. |
1099
+ | `timestamp` | ✓ | bool | | Optional flag about whether or not to add the `TimeInstant` attribute to the device entity created, as well as a `TimeInstant` metadata to each attribute, with the current timestamp. With NGSI-LD, the Standard `observedAt` property-of-a-property is created instead. |
1100
+ | `entity_type` | | string | | name of the Entity `type` to assign to the group. |
1101
+ | `trust` | ✓ | string | | trust token to use for secured access to the Context Broker for this type of devices (optional; only needed for secured scenarios). |
1102
+ | `cbHost` | ✓ | string | | Context Broker connection information. This options can be used to override the global ones for specific types of devices. |
1103
+ | `lazy` | ✓ | | | list of common lazy attributes of the device. For each attribute, its `name` and `type` must be provided. |
1104
+ | `commands` | ✓ | | | list of common commands attributes of the device. For each attribute, its `name` and `type` must be provided, additional `metadata` is optional. |
1105
+ | `attributes` | ✓ | | | list of common active attributes of the device. For each attribute, its `name` and `type` must be provided, additional `metadata` is optional. |
1106
+ | `static_attributes` | ✓ | | | this attributes will be added to all the entities of this group 'as is', additional `metadata` is optional. |
1107
+ | `internal_attributes` | ✓ | | | optional section with free format, to allow specific IoT Agents to store information along with the devices in the Device Registry. |
1108
+ | `explicitAttrs` | ✓ | string or bool | ✓ | optional field to support selective ignore of measures so that IOTA doesn’t progress. See details in [specific section](#explicitly-defined-attributes-explicitattrs) |
1109
+ | `entityNameExp` | ✓ | string | | optional field to allow use expressions to define entity name, instead default `id` and `type` |
1110
+ | `ngsiVersion` | ✓ | string | | optional string value used in mixed mode to switch between **NGSI-v2** and **NGSI-LD** payloads. Possible values are: `v2` or `ld`. The default is `v2`. When not running in mixed mode, this field is ignored. |
1111
+ | `defaultEntityNameConjunction` | ✓ | string | | optional string value to set default conjunction string used to compose a default `entity_name` when is not provided at device provisioning time. |
1112
+ | `autoprovision` | ✓ | bool | ✓? | optional boolean: If `false`, autoprovisioned devices (i.e. devices that are not created with an explicit provision operation but when the first measure arrives) are not allowed in this group. Default (in the case of omitting the field) is `true`. |
50
1113
 
51
- ### Type Configuration
1114
+ ### Config group operations
52
1115
 
53
- The IoT Agent can be configured to expect certain kinds of devices, with preconfigured sets of attributes, service
54
- information, security information and other attributes. The `types` attribute of the configuration is a map, where the
55
- key is the type name and the value is an object containing all the type information. Each type can has the following
56
- information configured:
1116
+ The following actions are available under the config group endpoint:
57
1117
 
58
- - **service**: service of the devices of this type.
59
- - **subservice**: subservice of the devices of this type.
60
- - **attributes**: list of active attributes of the device. For each attribute, its `name` and `type` must be provided,
61
- additional `metadata` is optional.
62
- - **lazy**: list of lazy attributes of the device. For each attribute, its `name` and `type` must be provided.
63
- - **commands**: list of commands attributes of the device. For each attribute, its `name` and `type` must be provided.
64
- - **internalAttributes**: optional section with free format, to allow specific IoT Agents to store information along
65
- with the devices in the Device Registry.
66
- - **staticAttributes**: this array of attributes will be added to every entity of this type 'as is'. `name` and `type`
67
- must be provided, additional `metadata` is optional.
68
- - **trust**: trust token to use for secured access to the Context Broker for this type of devices (optional; only
69
- needed for secured scenarios). Trust tokens may be called `access_tokens` by some Oauth2 providers.
70
- - **cbHost**: Context Broker host URL. This option can be used to override the global CB configuration for specific
71
- types of devices.
1118
+ #### Retrieve config groups `GET /iot/services`
72
1119
 
73
- ### Service Group Model
1120
+ List all the config groups for the given `fiware-service` and `fiware-servicepath`. If the `fiware-servicepath` header
1121
+ has the wildcard expression, `/*`, all the config groups for that `fiware-service` are returned. The config groups that
1122
+ match the `fiware-servicepath` are returned in any other case.
74
1123
 
75
- The table below shows the information held in the service group provisioning resource. The table also contains the
76
- correspondence between the API resource fields and the same fields in the database model.
1124
+ _**Request headers**_
77
1125
 
78
- | Payload Field | DB Field | Definition |
79
- | ------------------------------ | ------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
80
- | `service` | `service` | Service of the devices of this type |
81
- | `subservice` | `subservice` | Subservice of the devices of this type. |
82
- | `resource` | `resource` | string representing the Southbound resource that will be used to assign a type to a device (e.g.: pathname in the southbound port). |
83
- | `apikey` | `apikey` | API Key string. |
84
- | `timestamp` | `timestamp` | Optional flag about whether or not to add the `TimeInstant` attribute to the device entity created, as well as a `TimeInstant` metadata to each attribute, with the current timestamp. With NGSI-LD, the Standard `observedAt` property-of-a-property is created instead. | true |
85
- | `entity_type` | `entity_type` | name of the Entity `type` to assign to the group. |
86
- | `trust` | `trust` | trust token to use for secured access to the Context Broker for this type of devices (optional; only needed for secured scenarios). |
87
- | `cbHost` | `cbHost` | Context Broker connection information. This options can be used to override the global ones for specific types of devices. |
88
- | `lazy` | `lazy` | list of common lazy attributes of the device. For each attribute, its `name` and `type` must be provided. |
89
- | `commands` | `commands` | list of common commands attributes of the device. For each attribute, its `name` and `type` must be provided, additional `metadata` is optional. |
90
- | `attributes` | `attributes` | list of common active attributes of the device. For each attribute, its `name` and `type` must be provided, additional `metadata` is optional. |
91
- | `static_attributes` | `staticAttributes` | this attributes will be added to all the entities of this group 'as is', additional `metadata` is optional. |
92
- | `internal_attributes` | `internalAttributes` | optional section with free format, to allow specific IoT Agents to store information along with the devices in the Device Registry. |
93
- | `expressionLanguage` | `expresionLanguage` | optional boolean value, to set expression language used to compute expressions, possible values are: legacy or jexl. When not set or wrongly set, `legacy` is used as default value. |
94
- | `explicitAttrs` | `explicitAttrs` | optional field to support selective ignore of measures so that IOTA doesn’t progress. See details in [specific section](advanced-topics.md#explicitly-defined-attributes-explicitattrs) |
95
- | `entityNameExp` | `entityNameExp` | optional field to allow use expressions to define entity name, instead default `id` and `type` |
96
- | `ngsiVersion` | `ngsiVersion` | optional string value used in mixed mode to switch between **NGSI-v2** and **NGSI-LD** payloads. Possible values are: `v2` or `ld`. The default is `v2`. When not running in mixed mode, this field is ignored. |
97
- | `defaultEntityNameConjunction` | `defaultEntityNameConjunction` | optional string value to set default conjunction string used to compose a default `entity_name` when is not provided at device provisioning time. |
98
- | `autoprovision` | `autoprovision` | optional boolean: If `false`, autoprovisioned devices (i.e. devices that are not created with an explicit provision operation but when the first measure arrives) are not allowed in this group. Default (in the case of omitting the field) is `true`. |
1126
+ | Header | Optional | Description | Example |
1127
+ | -------------------- | -------- | ---------------------------------------------------------------------------------------------- | ---------- |
1128
+ | `Fiware-Service` | | Tenant or service. See subsection [Multi tenancy](#multi-tenancy) for more information. | `acme` |
1129
+ | `Fiware-ServicePath` | | Service path or subservice. See subsection [Service Path](#service-path) for more information. | `/project` |
99
1130
 
100
- ### Service Group Endpoint
1131
+ _**Response code**_
101
1132
 
102
- The following actions are available under the service group endpoint:
1133
+ - 200 OK if successful, returning a config group body.
1134
+ - 400 MISSING_HEADERS if any of the mandatory headers is not present.
1135
+ - 500 SERVER ERROR if there was any error not contemplated above.
103
1136
 
104
- ##### POST /iot/services
1137
+ _**Response headers**_
105
1138
 
106
- Creates a set of service groups for the given service and service path. The service and subservice information will
107
- taken from the headers, overwritting any preexisting values.
1139
+ Successful operations return `Content-Type` header with `application/json` value.
108
1140
 
109
- Body params:
1141
+ _**Response payload**_
110
1142
 
111
- - `services`: list of service groups to create. Each one adheres to the service group Model.
1143
+ A JSON object with a services field that contains an array of services that match the request. See the
1144
+ [config group datamodel](#service-group-datamodel) for more information.
112
1145
 
113
- E.g.:
1146
+ Example:
114
1147
 
115
1148
  ```json
116
1149
  {
@@ -132,246 +1165,213 @@ E.g.:
132
1165
  }
133
1166
  ],
134
1167
  "lazy": [{ "name": "status", "type": "Boolean" }]
1168
+ },
1169
+ {
1170
+ "resource": "/deviceTest2",
1171
+ "apikey": "A21323ASDG12312ASDN21LWQEJPO2J123",
1172
+ "type": "Switch",
1173
+ "trust": "8970A9078A803H3BL98PINEQRW8342HBAMS",
1174
+ "cbHost": "http://orion:1026",
1175
+ "commands": [{ "name": "on", "type": "order" }],
1176
+ "attributes": [
1177
+ {
1178
+ "name": "swithc_status",
1179
+ "type": "boolean"
1180
+ }
1181
+ ]
135
1182
  }
136
1183
  ]
137
1184
  }
138
1185
  ```
139
1186
 
140
- Returns:
141
-
142
- - 200 OK if successful, with no payload.
143
- - 400 MISSING_HEADERS if any of the mandatory headers is not present.
144
- - 400 WRONG_SYNTAX if the body doesn't comply with the schema.
145
- - 500 SERVER ERROR if there was any error not contemplated above.
146
-
147
- ##### GET /iot/services
1187
+ #### Create config group `POST /iot/services`
148
1188
 
149
- Retrieves service groups from the database. If the servicepath header has the wildcard expression, `/*`, all the
150
- subservices for the service are returned. The specific subservice parameters are returned in any other case.
1189
+ Creates a set of config groups for the given service and service path. The service and subservice information will taken
1190
+ from the headers, overwritting any preexisting values.
151
1191
 
152
- Returns:
1192
+ _**Request headers**_
153
1193
 
154
- - 200 OK if successful, returning a service group body.
155
- - 400 MISSING_HEADERS if any of the mandatory headers is not present.
156
- - 500 SERVER ERROR if there was any error not contemplated above.
1194
+ | Header | Optional | Description | Example |
1195
+ | -------------------- | -------- | ---------------------------------------------------------------------------------------------- | ---------- |
1196
+ | `Fiware-Service` | ✓ | Tenant or service. See subsection [Multi tenancy](#multi-tenancy) for more information. | `acme` |
1197
+ | `Fiware-ServicePath` | ✓ | Service path or subservice. See subsection [Service Path](#service-path) for more information. | `/project` |
157
1198
 
158
- ##### PUT /iot/services
1199
+ _**Request payload**_
159
1200
 
160
- Modifies the information for a service group configuration, identified by the `resource` and `apikey` query parameters.
161
- Takes a service group body as the payload. The body does not have to be complete: for incomplete bodies, just the
162
- existing attributes will be updated
1201
+ A JSON object with a `services` field. The value is an array of config groups objects to create. See the
1202
+ [config group datamodel](#service-group-datamodel) for more information.
163
1203
 
164
- E.g.:
1204
+ Example:
165
1205
 
166
1206
  ```json
167
1207
  {
168
- "trust": "8970A9078A803H3BL98PINEQRW8342HBAMS",
169
- "cbHost": "http://orion:1026"
1208
+ "services": [
1209
+ {
1210
+ "resource": "/deviceTest",
1211
+ "apikey": "801230BJKL23Y9090DSFL123HJK09H324HV8732",
1212
+ "type": "Light",
1213
+ "trust": "8970A9078A803H3BL98PINEQRW8342HBAMS",
1214
+ "cbHost": "http://orion:1026",
1215
+ "commands": [{ "name": "wheel1", "type": "Wheel" }],
1216
+ "attributes": [
1217
+ {
1218
+ "name": "luminescence",
1219
+ "type": "Integer",
1220
+ "metadata": {
1221
+ "unitCode": { "type": "Text", "value": "CAL" }
1222
+ }
1223
+ }
1224
+ ],
1225
+ "lazy": [{ "name": "status", "type": "Boolean" }]
1226
+ }
1227
+ ]
170
1228
  }
171
1229
  ```
172
1230
 
173
- Returns:
174
-
175
- - 200 OK if successful, returning the updated body.
176
- - 400 MISSING_HEADERS if any of the mandatory headers is not present.
177
- - 500 SERVER ERROR if there was any error not contemplated above.
1231
+ _**Response code**_
178
1232
 
179
- ##### DELETE /iot/services
1233
+ - `200` `OK` if successful, with no payload.
1234
+ - `400` `MISSING_HEADERS` if any of the mandatory headers is not present.
1235
+ - `400` `WRONG_SYNTAX` if the body doesn't comply with the schema.
1236
+ - `500` `SERVER ERROR` if there was any error not contemplated above.
180
1237
 
181
- Removes a service group configuration from the DB, specified by the `resource` and `apikey` query parameters.
1238
+ _**Response headers**_
182
1239
 
183
- Returns:
1240
+ Successful operations return `Content-Type` header with `application/json` value.
184
1241
 
185
- - 200 OK if successful.
186
- - 400 MISSING_HEADERS if any of the mandatory headers is not present.
187
- - 500 SERVER ERROR if there was any error not contemplated above.
1242
+ #### Modify config group `PUT /iot/services`
188
1243
 
189
- ## Device API
1244
+ Modifies the information of a config group, identified by the `resource` and `apikey` query parameters. Takes a service
1245
+ group body as the payload. The body does not have to be complete: for incomplete bodies, just the attributes included in
1246
+ the JSON body will be updated. The rest of the attributes will remain unchanged.
190
1247
 
191
- The IoT Agents offer a provisioning API where devices can be preregistered, so all the information about service and
192
- subservice mapping, security information and attribute configuration can be specified in a per device way instead of
193
- relaying on the type configuration. The following section specifies the format of the device payload; this will be the
194
- payload accepted by all the write operations and that will be returned by all the read operations. Take care of the
195
- exception of the POST operation: in this case, the device objects must be specified as an array, as multiple devices can
196
- be provided simultaneusly for the same service.
1248
+ _**Request query parameters**_
197
1249
 
198
- Two parameters in this payload are given a special treatment: service and subservice. This two parameters are needed to
199
- fill the `fiware-service` and `fiware-servicepath` mandatory headers that will be used in the interactions with the
200
- Context Broker. This parameters should not be passed along with the rest of the body, but they will be taken from the
201
- same headers, as received by the Device Provisioning API (this two headers are, thus, mandatory both for incoming and
202
- outgoing requests).
1250
+ | Parameter | Mandatory | Description | Example |
1251
+ | --------- | --------- | -------------------------------------------- | ----------------------------------------- |
1252
+ | resource | ✓ | Resource of the config group to be modified. | `/device` |
1253
+ | apikey | ✓ | Apikey of the config group to be modified. | `801230BJKL23Y9090DSFL123HJK09H324HV8732` |
203
1254
 
204
- Note that there is a 1:1 correspondence between payload fields and DB fields (but using a different capitalization, e.g.
205
- `service_path` vs. `servicePath`).
1255
+ _**Request headers**_
206
1256
 
207
- ### Relationship between service groups and devices
1257
+ | Header | Optional | Description | Example |
1258
+ | -------------------- | -------- | ---------------------------------------------------------------------------------------------- | ---------- |
1259
+ | `Fiware-Service` | ✓ | Tenant or service. See subsection [Multi tenancy](#multi-tenancy) for more information. | `acme` |
1260
+ | `Fiware-ServicePath` | ✓ | Service path or subservice. See subsection [Service Path](#service-path) for more information. | `/project` |
208
1261
 
209
- Devices may be associated to exisiting service groups (or not) based in `apiKey` matching or `type` matching (in the
210
- case `apiKey` matching fails). For instance, let's consider a situation in which a service group has been provisioned
211
- with `type=X`/`apiKey=111` and no other service group has been provisioned.
1262
+ _**Request payload**_
212
1263
 
213
- - IoT Agent receives an anonymous measure with `apiKey=111`. The matching `apiKey` means the entity inherits from
214
- service group. Device entity has `type=X` and `apiKey=111`
215
- - IoT Agent receives a provisioning request for an explicit device of `type=Y`/`apiKey=111`. The matching `apiKey`
216
- means the entity inherits from service group but type is overridden. Device entity has `type=Y` and `apiKey=111`
217
- - IoT Agent receives a provisioning request for an explicit device of `type=X`/`apiKey=222`. The matching `type` means
218
- the entity inherits from service group but `apiKey` is overridden. Device entity has `type=X` and `apiKey=222`.
219
- - IoT Agent receives a provisioning request for an explicit device of `type=Y`/`apiKey=222`. No matching. Device
220
- entity has `type=Y` and `apiKey=222` and no service group.
1264
+ A JSON object with the config group information to be modified. See the
1265
+ [config group datamodel](#service-group-datamodel) for more information.
221
1266
 
222
- ### Device model
1267
+ Example:
223
1268
 
224
- The table below shows the information held in the Device resource. The table also contains the correspondence between
225
- the API resource fields and the same fields in the database model.
1269
+ ```json
1270
+ {
1271
+ "trust": "8970A9078A803H3BL98PINEQRW8342HBAMS",
1272
+ "cbHost": "http://orion:1026"
1273
+ }
1274
+ ```
226
1275
 
227
- | Payload Field | DB Field | Definition | Example of value |
228
- | --------------------- | -------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------- |
229
- | `device_id` | `id` | Device ID that will be used to identify the device. | UO834IO |
230
- | `service` | `service` | Name of the service the device belongs to (will be used in the fiware-service header). | smartGondor |
231
- | `service_path` | `subservice` | Name of the subservice the device belongs to (used in the fiware-servicepath header). | /gardens |
232
- | `entity_name` | `name` | Name of the entity representing the device in the Context Broker | ParkLamplight12 |
233
- | `entity_type` | `type` | Type of the entity in the Context Broker | Lamplights |
234
- | `timezone` | `timezone` | Time zone of the sensor if it has any | America/Santiago |
235
- | `timestamp` | `timestamp` | Optional flag about whether or not to add the `TimeInstant` attribute to the device entity created, as well as a `TimeInstant` metadata to each attribute, with the current timestamp. With NGSI-LD, the Standard `observedAt` property-of-a-property is created instead. | true |
236
- | `apikey` | `apikey` | Optional Apikey key string to use instead of group apikey | 9n4hb1vpwbjozzmw9f0flf9c2 |
237
- | `endpoint` | `endpoint` | Endpoint where the device is going to receive commands, if any. | http://theDeviceUrl:1234/commands |
238
- | `protocol` | `protocol` | Name of the device protocol, for its use with an IoT Manager. | IoTA-UL |
239
- | `transport` | `transport` | Name of the device transport protocol, for the IoT Agents with multiple transport protocols. | MQTT |
240
- | `attributes` | `active` | List of active attributes of the device | `[ { "name": "attr_name", "type": "Text" } ]` |
241
- | `lazy` | `lazy` | List of lazy attributes of the device | `[ { "name": "attr_name", "type": "Text" } ]` |
242
- | `commands` | `commands` | List of commands of the device | `[ { "name": "attr_name", "type": "Text" } ]` |
243
- | `internal_attributes` | `internalAttributes` | List of internal attributes with free format for specific IoT Agent configuration | LWM2M mappings from object URIs to attributes |
244
- | `static_attributes` | `staticAttributes` | List of static attributes to append to the entity. All the updateContext requests to the CB will have this set of attributes appended. | `[ { "name": "attr_name", "type": "Text" } ]` |
245
- | `expressionLanguage` | `expresionLanguage` | optional boolean value, to set expression language used to compute expressions, possible values are: legacy or jexl. When not set or wrongly set, legacy is used as default value. |
246
- | `explicitAttrs` | `explicitAttrs` | optional field to support selective ignore of measures so that IOTA doesn’t progress. See details in [specific section](advanced-topics.md#explicitly-defined-attributes-explicitattrs) | (see details in specific section) |
247
- | `ngsiVersion` | `ngsiVersion` | optional 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. | `v2/ld` |
248
-
249
- #### Attribute lists
250
-
251
- In the group/device model there are three list of attributes that can be declared: attributes, lazy and commands. All of
252
- them have the same syntax, an object containing the following attributes:
1276
+ _**Response code**_
253
1277
 
254
- - **object_id** (optional): name of the attribute as coming from the device.
255
- - **name** (mandatory): ID of the attribute in the target entity in the Context Broker.
256
- - **type** (mandatory): name of the type of the attribute in the target entity.
257
- - **metadata** (optional): additional static metadata for the attribute in the target entity. (e.g. `unitCode`)
1278
+ - 200 OK if successful, returning the updated body.
1279
+ - 400 MISSING_HEADERS if any of the mandatory headers is not present.
1280
+ - 500 SERVER ERROR if there was any error not contemplated above.:
258
1281
 
259
- Some transformation plugins also allow the use of the following optional fields:
1282
+ #### Remove config group `DELETE /iot/services`
260
1283
 
261
- - **expression**: indicates that the value of the target attribute will not be the plain value or the measurement, but
262
- an expression based on a combination of the reported values. See the
263
- [Expression Language definition](expressionLanguage.md) for details
264
- - **entity_name**: the presence of this attribute indicates that the value will not be stored in the original device
265
- entity but in a new entity with an ID given by this attribute. The type of this additional entity can be configured
266
- with the `entity_type` attribute. If no type is configured, the device entity type is used instead. Entity names can
267
- be defined as expressions, using the [Expression Language definition](expressionLanguage.md).
268
- - **entity_type**: configures the type of an alternative entity.
269
- - **reverse**: add bidirectionality expressions to the attribute. See the **bidirectionality** transformation plugin
270
- in the [Data Mapping Plugins section](advanced-topics.md#bidirectionality-plugin-bidirectional) for details.
1284
+ Removes a config group, identified by the `resource` and `apikey` query parameters.
271
1285
 
272
- Additionally for commands (which are attributes of type `command`) the following fields are optional:
1286
+ _**Request query parameters**_
273
1287
 
274
- - **expression** indicates that the value of the target command will not be the plain value or the command, but an
275
- expression based on a combination of the returned values. See the
276
- [Expression Language definition](expressionLanguage.md) for details
277
- - **payloadType**: indicates how command payload will be transformed before be sent to device. Please have a look to
278
- particular IOTAs documentation for allowed values of this field in each case.
279
- - **contentType**: `content-type` header used when send command by HTTP transport (ignored in other kinds of
280
- transports)
1288
+ | Parameter | Mandatory | Description | Example |
1289
+ | --------- | --------- | ------------------------------------------- | ----------------------------------------- |
1290
+ | resource | ✓ | Resource of the config group to be removed. | `/device` |
1291
+ | apikey | ✓ | Apikey of the config group to be removed. | `801230BJKL23Y9090DSFL123HJK09H324HV8732` |
281
1292
 
282
- See the transformation plugins Section for more details.
1293
+ _**Request headers**_
283
1294
 
284
- #### Advice on Attribute defintions
1295
+ | Header | Optional | Description | Example |
1296
+ | -------------------- | -------- | ---------------------------------------------------------------------------------------------- | ---------- |
1297
+ | `Fiware-Service` | ✓ | Tenant or service. See subsection [Multi tenancy](#multi-tenancy) for more information. | `acme` |
1298
+ | `Fiware-ServicePath` | ✓ | Service path or subservice. See subsection [Service Path](#service-path) for more information. | `/project` |
285
1299
 
286
- ##### Reuse of attribute names
1300
+ _**Response code**_
287
1301
 
288
- Check for the existence of the same Attribute on any of the other models and reuse it, if pertinent. Have a look at
289
- schema.org trying to find a similar term with the same semantics. Try to find common used ontologies or existing
290
- standards well accepted by the Community, or by goverments, agencies, etc. For instance, Open311 for civic issue
291
- tracking or Datex II for transport systems.
1302
+ - `200` `OK` if successful.
1303
+ - `400` `MISSING_HEADERS` if any of the mandatory headers is not present.
1304
+ - `500` `SERVER ERROR` if there was any error not contemplated above.
292
1305
 
293
- ##### Reuse of attribute types
1306
+ ## Device API
294
1307
 
295
- When possible reuse [schema.org](http://schema.org/) data types (`Text`, `Number`, `DateTime`, `StructuredValue`, etc.).
296
- Remember that `null` is not allowed in NGSI-LD and therefore should be avoided as a value.
1308
+ ### Device datamodel
297
1309
 
298
- ##### How to specify attribute Units of Measurement
1310
+ The table below shows the information held in the Device resource. The table also contains the correspondence between
1311
+ the API resource fields and the same fields in the database model.
299
1312
 
300
- If your data use the default unit defined in the Data Model, you don't need to specify any. It is implied. Unless
301
- explicitly stated otherwise, all FIWARE data models use the metric system of measurements by default. Regardless the
302
- model specification include explicit reference to the scale adopted. If your data use a different unit, you will need to
303
- use the `unitCode` metadata annotation in your data (and you will need to adopt the normalised representation). The code
304
- used should be taken from those defined by
305
- [UN/CEFACT](https://www.unece.org/fileadmin/DAM/cefact/recommendations/rec20/rec20_rev3_Annex3e.pdf). E.g.:
1313
+ | Field | Optional | Type | Expression | Definitiom |
1314
+ | --------------------- | -------- | --------- | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1315
+ | `device_id` | | `string` | | Device ID that will be used to identify the device. |
1316
+ | `service` | | `string` | | Name of the service the device belongs to (will be used in the fiware-service header). |
1317
+ | `service_path` | | `string` | | Name of the subservice the device belongs to (used in the fiware-servicepath header). |
1318
+ | `entity_name` | | `string` | | Name of the entity representing the device in the Context Broker |
1319
+ | `entity_type` | | `string` | | Type of the entity in the Context Broker |
1320
+ | `timezone` | ✓ | `string` | | Timezone of the device if that has any |
1321
+ | `timestamp` | ✓ | `string` | | Flag about whether or not to add the `TimeInstant` attribute to the device entity created, as well as a `TimeInstant` metadata to each attribute, with the current timestamp. With NGSI-LD, the Standard `observedAt` property-of-a-property is created instead. |
1322
+ | `apikey` | ✓ | `string` | | Apikey key string to use instead of group apikey |
1323
+ | `endpoint` | ✓ | `string` | | Endpoint where the device is going to receive commands, if any. |
1324
+ | `protocol` | ✓ | `string` | | Pame of the device protocol, for its use with an IoT Manager |
1325
+ | `transport` | ✓ | `string` | | Transport protocol used by the device to send updates, for the IoT Agents with multiple transport protocols. |
1326
+ | `attributes` | ✓ | `array` | | List of attributes that will be stored in the Context Broker. |
1327
+ | `commands` | ✓ | `array` | | List of commands that will be stored in the Context Broker. |
1328
+ | `lazy` | ✓ | `array` | | List of lazy attributes that will be stored in the Context Broker. |
1329
+ | `static_attributes` | ✓ | `array` | | List of static attributes that will be stored in the Context Broker. |
1330
+ | `internal_attributes` | ✓ | `array` | | List of internal attributes with free format for specific IoT Agent configuration. |
1331
+ | `explicitAttrs` | ✓ | `boolean` | ✓ | Field to support selective ignore of measures so that IOTA doesn’t progress. See details in [specific section](#explicitly-defined-attributes-explicitattrs) |
1332
+ | `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. |
306
1333
 
307
- ```json
308
- {
309
- "object_id": "l",
310
- "name": "length",
311
- "type": "Integer",
312
- "metadata": {
313
- "unitCode": { "type": "Text", "value": "FOT" }
314
- }
315
- }
316
- ```
1334
+ ### Device operations
317
1335
 
318
- #### API Actions
1336
+ #### Retrieve devices /iot/devices `GET /iot/devices`
319
1337
 
320
- ##### POST /iot/devices
1338
+ List all the devices registered in the IoT Agent device registry with all their information for a given `fiware-service`
1339
+ and `fiware-servicepath`.
321
1340
 
322
- Provision a new device in the IoT Agent's device registry. Takes a Device in JSON format as the payload.
1341
+ _**Request query parameters**_
323
1342
 
324
- Returns:
1343
+ | Parameter | Mandatory | Description | Example |
1344
+ | --------- | --------- | --------------------------------------------------------- | ------- |
1345
+ | `limit` | | Maximum number of results to return in a single response. | `20` |
1346
+ | `offset` | | Number of results to skip from the original query. | `0` |
325
1347
 
326
- - 200 OK if successful.
327
- - 500 SERVER ERROR if there was any error not contemplated above.
1348
+ _**Request headers**_
328
1349
 
329
- Payload example:
1350
+ | Header | Optional | Description | Example |
1351
+ | -------------------- | -------- | ---------------------------------------------------------------------------------------------- | ---------- |
1352
+ | `Fiware-Service` | ✓ | Tenant or service. See subsection [Multi tenancy](#multi-tenancy) for more information. | `acme` |
1353
+ | `Fiware-ServicePath` | ✓ | Service path or subservice. See subsection [Service Path](#service-path) for more information. | `/project` |
330
1354
 
331
- ```json
332
- {
333
- "devices": [
334
- {
335
- "device_id": "DevID1",
336
- "entity_name": "urn:ngsi-ld:Device:TheDevice1",
337
- "entity_type": "Device",
338
- "attributes": [
339
- { "object_id": "t", "name": "temperature", "type": "Float" },
340
- { "object_id": "h", "name": "humidity", "type": "Float" }
341
- ],
342
- "lazy": [
343
- {
344
- "object_id": "l",
345
- "name": "percentage",
346
- "type": "Integer",
347
- "metadata": {
348
- "unitCode": { "type": "Text", "value": "P1" }
349
- }
350
- }
351
- ],
352
- "commands": [{ "object_id": "t", "name": "turn", "type": "Text" }],
353
- "static_attributes": [{ "name": "serialID", "value": "02598347", "type": "Text" }]
354
- }
355
- ]
356
- }
357
- ```
1355
+ _**Response code**_
358
1356
 
359
- ##### GET /iot/devices
1357
+ - `200` `OK` if successful.
1358
+ - `404` `NOT FOUND` if there are no devices for the given service and subservice.
1359
+ - `500` `SERVER ERROR` if there was any error not contemplated above.
360
1360
 
361
- Returns a list of all the devices in the device registry with all its data.
1361
+ _**Response headers**_
362
1362
 
363
- Query parameters:
1363
+ Successful operations return `Content-Type` header with `application/json` value.
364
1364
 
365
- - limit: if present, limits the number of devices returned in the list.
366
- - offset: if present, skip that number of devices from the original query.
1365
+ _**Response body**_
367
1366
 
368
- Returns:
1367
+ The response body contains a JSON object with the following fields:
369
1368
 
370
- - 200 OK if successful, and the selected Device payload in JSON format.
371
- - 404 NOT FOUND if the device was not found in the database.
372
- - 500 SERVER ERROR if there was any error not contemplated above.
1369
+ | Field | Type | Description |
1370
+ | --------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1371
+ | `count` | `integer` | Number of devices in the response. |
1372
+ | `devices` | `array` | List of devices in the response. Each device is represented by a JSON object. For more information about the device object, see the [Device datamodel](#device-datamodel) section. |
373
1373
 
374
- Example of return payload:
1374
+ Example:
375
1375
 
376
1376
  ```json
377
1377
  {
@@ -416,17 +1416,80 @@ Example of return payload:
416
1416
  }
417
1417
  ```
418
1418
 
419
- ##### GET /iot/devices/:deviceId
1419
+ ##### Create device `POST /iot/devices`
420
1420
 
421
- Returns all the information about a particular device.
1421
+ Provision a new device in the IoT Agent's device registry for a given `fiware-service` and `fiware-servicepath`. Takes a
1422
+ Device in JSON format as the payload.
422
1423
 
423
- Returns:
1424
+ _**Request headers**_
424
1425
 
425
- - 200 OK if successful, and the selected Device payload in JSON format.
426
- - 404 NOT FOUND if the device was not found in the database.
427
- - 500 SERVER ERROR if there was any error not contemplated above.
1426
+ | Header | Optional | Description | Example |
1427
+ | -------------------- | -------- | ---------------------------------------------------------------------------------------------- | ---------- |
1428
+ | `Fiware-Service` | ✓ | Tenant or service. See subsection [Multi tenancy](#multi-tenancy) for more information. | `acme` |
1429
+ | `Fiware-ServicePath` | ✓ | Service path or subservice. See subsection [Service Path](#service-path) for more information. | `/project` |
1430
+
1431
+ _**Request body**_
1432
+
1433
+ The body of the a JSON object with field named `devices` containing a list of devices to be provisioned. Each device is
1434
+ represented by device JSON object. For more information, see the [Device datamodel](#device-datamodel) section.
1435
+
1436
+ Example:
1437
+
1438
+ ```json
1439
+ {
1440
+ "devices": [
1441
+ {
1442
+ "device_id": "DevID1",
1443
+ "entity_name": "urn:ngsi-ld:Device:TheDevice1",
1444
+ "entity_type": "Device",
1445
+ "attributes": [
1446
+ { "object_id": "t", "name": "temperature", "type": "Float" },
1447
+ { "object_id": "h", "name": "humidity", "type": "Float" }
1448
+ ]
1449
+ }
1450
+ ]
1451
+ }
1452
+ ```
1453
+
1454
+ _**Response code**_
1455
+
1456
+ - `200` `OK` if successful.
1457
+ - `500` `SERVER ERROR` if there was any error not contemplated above.
1458
+
1459
+ #### Get device details `GET /iot/devices/:deviceId`
1460
+
1461
+ Returns all the information about a device in the IoT Agent's device registry for a given `fiware-service` and
1462
+ `fiware-servicepath`.
1463
+
1464
+ _**Request URL parameters**_
1465
+
1466
+ | Parameter | Mandatory | Description | Example |
1467
+ | ---------- | --------- | ----------- | -------- |
1468
+ | `deviceId` | ✓ | Device ID. | `DevID1` |
1469
+
1470
+ _**Request headers**_
1471
+
1472
+ | Header | Optional | Description | Example |
1473
+ | -------------------- | -------- | ---------------------------------------------------------------------------------------------- | ---------- |
1474
+ | `Fiware-Service` | ✓ | Tenant or service. See subsection [Multi tenancy](#multi-tenancy) for more information. | `acme` |
1475
+ | `Fiware-ServicePath` | ✓ | Service path or subservice. See subsection [Service Path](#service-path) for more information. | `/project` |
1476
+
1477
+ _**Response code**_
1478
+
1479
+ - `200` `OK` if successful.
1480
+ - `404` `NOT FOUND` if the device was not found in the database.
1481
+ - `500` `SERVER ERROR` if there was any error not contemplated above.
1482
+
1483
+ _**Response headers**_
428
1484
 
429
- Example of return payload:
1485
+ Successful operations return `Content-Type` header with `application/json` value.
1486
+
1487
+ _**Response body**_
1488
+
1489
+ The response body contains a device JSON object. For more information, see the [Device datamodel](#device-datamodel)
1490
+ section.
1491
+
1492
+ Example:
430
1493
 
431
1494
  ```json
432
1495
  {
@@ -452,29 +1515,32 @@ Example of return payload:
452
1515
  }
453
1516
  ```
454
1517
 
455
- ##### DELETE /iot/devices/:deviceId
1518
+ #### Modify device `PUT /iot/devices/:deviceId`
456
1519
 
457
- Remove a device from the device registry. No payload is required or received.
1520
+ Changes the stored values for the device with the provided Device payload. Neither the name, the type nor the ID of the
1521
+ device can be changed using this method (as they are used to link the already created entities in the Context Broker to
1522
+ the information in the device). `fiware-service` and `fiware-servicepath`, being taken from the headers, can't be
1523
+ changed also.
458
1524
 
459
- Returns:
1525
+ _**Request URL parameters**_
460
1526
 
461
- - 200 OK if successful, with no payload.
462
- - 404 NOT FOUND if the device was not found in the database.
463
- - 500 SERVER ERROR if there was any error not contemplated above.
1527
+ | Parameter | Mandatory | Description | Example |
1528
+ | ---------- | --------- | ----------------------- | -------- |
1529
+ | `deviceId` | ✓ | Device ID to be updated | `DevID1` |
464
1530
 
465
- ##### PUT /iot/devices/:deviceId
1531
+ _**Request headers**_
466
1532
 
467
- Changes the stored values for the device with the provided Device payload. Neither the name, the type nor the ID of the
468
- device can be changed using this method (as they are used to link the already created entities in the CB to the
469
- information in the device). Service and servicepath, being taken from the headers, can't be changed also.
1533
+ | Header | Optional | Description | Example |
1534
+ | -------------------- | -------- | ---------------------------------------------------------------------------------------------- | ---------- |
1535
+ | `Fiware-Service` | ✓ | Tenant or service. See subsection [Multi tenancy](#multi-tenancy) for more information. | `acme` |
1536
+ | `Fiware-ServicePath` | ✓ | Service path or subservice. See subsection [Service Path](#service-path) for more information. | `/project` |
470
1537
 
471
- Returns:
1538
+ _**Request body**_
472
1539
 
473
- - 200 OK if successful, with no payload.
474
- - 404 NOT FOUND if the device was not found in the database.
475
- - 500 SERVER ERROR if there was any error not contemplated above.
1540
+ The request body contains a device JSON object the values of which will be updated in the device registry. For more
1541
+ information, see the [Device datamodel](#device-datamodel) section.
476
1542
 
477
- Payload example:
1543
+ Example:
478
1544
 
479
1545
  ```json
480
1546
  {
@@ -489,23 +1555,142 @@ Payload example:
489
1555
  }
490
1556
  ```
491
1557
 
492
- ## Log API
1558
+ _**Response code**_
1559
+
1560
+ - `200` `OK` if successful.
1561
+ - `404` `NOT FOUND` if the device was not found in the database.
1562
+ - `500` `SERVER ERROR` if there was any error not contemplated above.
1563
+
1564
+ #### Remove device `DELETE /iot/devices/:deviceId`
1565
+
1566
+ Remove a device from the device registry. The device is identified by the Device ID as URL parameter.
1567
+
1568
+ _**Request URL parameters**_
1569
+
1570
+ | Parameter | Mandatory | Description | Example |
1571
+ | ---------- | --------- | ----------------------- | -------- |
1572
+ | `deviceId` | ✓ | Device ID to be deleted | `DevID1` |
1573
+
1574
+ _**Request headers**_
1575
+
1576
+ | Header | Optional | Description | Example |
1577
+ | -------------------- | -------- | ---------------------------------------------------------------------------------------------- | ---------- |
1578
+ | `Fiware-Service` | ✓ | Tenant or service. See subsection [Multi tenancy](#multi-tenancy) for more information. | `acme` |
1579
+ | `Fiware-ServicePath` | ✓ | Service path or subservice. See subsection [Service Path](#service-path) for more information. | `/project` |
1580
+
1581
+ _**Response code**_
1582
+
1583
+ - `200` `OK` if successful.
1584
+ - `404` `NOT FOUND` if the device was not found in the database.
1585
+ - `500` `SERVER ERROR` if there was any error not contemplated above.
493
1586
 
494
- The IoT Agent Library makes use of the [Logops logging library](https://github.com/telefonicaid/logops). This library is
495
- required in a `logger` object, shared between all of the modules. In order for the logging to be consistent across the
496
- different modules of an IoTAgent (i.e.: the ones provided by the IoTA Library as well as those created for the
497
- particular IoTAgent), the `logger` object is exported in the `logModule` property of the library. The agents should use
498
- this module for logging.
1587
+ ## Miscellaneous API
499
1588
 
500
- The IoT Agent Library also provides a configuration API that lets the administrator change and manage the log level in
501
- realtime. This API has the following two actions:
1589
+ ### Log operations
502
1590
 
503
- ##### PUT /admin/log
1591
+ The IoT Agent Library makes use of the [Logops logging library](https://github.com/telefonicaid/logops). The IoT Agent
1592
+ Library provides a configuration API that lets the administrator change and manage the log level in realtime.
504
1593
 
505
- This operation gets the new log level using the query parameter `level`. If the new level is a valid level for Logops
506
- (i.e.: one of the items in the array ['INFO', 'ERROR', 'FATAL', 'DEBUG', 'WARNING']), it will be automatically changed
507
- for future logs.
1594
+ #### Modify Loglevel `PUT /admin/log`
508
1595
 
509
- ##### PUT /admin/log
1596
+ This operation gets the new log level using the query parameter `level`. If the new level is a valid level, it will be
1597
+ automatically changed for future logs.
1598
+
1599
+ _**Request query parameters**_
1600
+
1601
+ | Parameter | Mandatory | Description | Example |
1602
+ | --------- | --------- | ------------------------------------------------------------------------------------------------------------------- | ------- |
1603
+ | `level` | ✓ | New log level. One of the following: `INFO`, `ERROR`, `FATAL`, `DEBUG`, `WARNING`. it will be automatically changed |
1604
+
1605
+ for future logs. | `DEBUG` |
1606
+
1607
+ _**Response code**_
1608
+
1609
+ - `200` `OK` if successful.
1610
+ - `500` `SERVER ERROR` if there was any error not contemplated above.
1611
+
1612
+ #### Retrieve log level `PUT /admin/log`
1613
+
1614
+ _**Response code**_
1615
+
1616
+ - `200` `OK` if successful.
1617
+ - `500` `SERVER ERROR` if there was any error not contemplated above.
1618
+
1619
+ _**Response body**_
510
1620
 
511
1621
  Returns the current log level, in a json payload with a single attribute `level`.
1622
+
1623
+ Example:
1624
+
1625
+ ```json
1626
+ {
1627
+ "level": "DEBUG"
1628
+ }
1629
+ ```
1630
+
1631
+ ### About operations
1632
+
1633
+ #### List IoTA Information `GET /iot/about`
1634
+
1635
+ Returns a useful information about component version and deployment information. It can be used as a heartbeat operation
1636
+ to check the health of the IoT Agent if required.
1637
+
1638
+ _**Response payload**_
1639
+
1640
+ The response is a JSON object with the following parameters:
1641
+
1642
+ - `libVersion`: This field is the iotagent-node-lib version with which the IoT Agent has been developed.
1643
+ - `port`: port where the IoT Agent will be listening as a Context Provider.
1644
+ - `baseRoot`: base root to prefix all the paths where the IoT Agent will be listening as a Context Provider.
1645
+ - `version`: This field is the IoT Agent version. It will be read from the `iotaVersion` field of the config, if it
1646
+ exists.
1647
+
1648
+ Example:
1649
+
1650
+ ```json
1651
+ {
1652
+ "libVersion": "2.7.0",
1653
+ "port": "4041",
1654
+ "baseRoot": "/",
1655
+ "version": "1.7.0"
1656
+ }
1657
+ ```
1658
+
1659
+ [1]:
1660
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22longitude%22%3A%205%2C%0A%20%20%22latitude%22%3A%2037%2C%0A%20%20%22level%22%3A223%0A%7D&input=%7Bcoordinates%3A%20%5Blongitude%2Clatitude%5D%2C%20type%3A%20'Point'%7D&transforms=%7B%0A%7D
1661
+ [2]:
1662
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22longitude%22%3A%205%2C%0A%20%20%22latitude%22%3A%2037%2C%0A%20%20%22level%22%3A223%0A%7D&input=level%2F100&transforms=%7B%0A%7D
1663
+ [3]:
1664
+ https://czosel.github.io/jexl-playground/#/?context=%7B%20%0A%20%20%22latitude%22%3A%201.9%2C%0A%20%20%22level%22%3A85.3%0A%7D&input=longitude%2B%22%2C%20%22%2Blatitude&transforms=%7B%0A%7D
1665
+ [4]:
1666
+ https://czosel.github.io/jexl-playground/#/?context=%7B%20%0A%20%20%22latitude%22%3A%201.9%2C%0A%20%20%22level%22%3A85.3%0A%7D&input=level%2F100&transforms=%7B%0A%7D
1667
+ [5]:
1668
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22spaces%22%20%3A%20%22%20%20foobar%20%20%22%0A%7D&input=spaces%20%7C%20trim&transforms=%7B%0A%20%20trim%3A%20(val)%20%3D%3E%20String(val).trim()%0A%7D
1669
+ [6]:
1670
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=5%20*%20value&transforms=%7B%0A%7D
1671
+ [7]:
1672
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=(6%20%2B%20value)%20*%203&transforms=%7B%0A%7D
1673
+ [8]:
1674
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=value%20%2F%2012%20%2B%201&transforms=%7B%0A%7D
1675
+ [9]:
1676
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=(5%20%2B%202)%20*%20(value%20%2B%207)&transforms=%7B%0A%7D
1677
+ [10]:
1678
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=value%20*%205.2&transforms=%7B%0A%7D
1679
+ [11]:
1680
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=%22Pruebas%20%22%20%2B%20%22De%20Strings%22&transforms=%7B%0A%7D
1681
+ [12]:
1682
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=name%20%2B%20%22value%20is%20%22%20%2Bvalue&transforms=%7B%0A%7D
1683
+ [13]:
1684
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=%7Bcoordinates%3A%20%5Bvalue%2Cvalue%5D%2C%20type%3A%20'Point'%7D&transforms=%7B%0A%7D
1685
+ [14]:
1686
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=ts%7Ctoisodate&transforms=%7B%0A%20%20%20%20jsonparse%3A%20(str)%20%3D%3E%20JSON.parse(str)%2C%0A%20%20%20%20jsonstringify%3A%20(obj)%20%3D%3E%20JSON.stringify(obj)%2C%0A%20%20%20%20indexOf%3A%20(val%2C%20char)%20%3D%3E%20String(val).indexOf(char)%2C%0A%20%20%20%20length%3A%20(val)%20%3D%3E%20String(val).length%2C%0A%20%20%20%20trim%3A%20(val)%20%3D%3E%20String(val).trim()%2C%0A%20%20%20%20substr%3A%20(val%2C%20int1%2C%20int2)%20%3D%3E%20String(val).substr(int1%2C%20int2)%2C%0A%20%20%20%20addreduce%3A%20(arr)%20%3D%3E%20arr.reduce((i%2C%20v)%20%3D%3E%20i%20%2B%20v)%2C%0A%20%20%20%20lengtharray%3A%20(arr)%20%3D%3E%20arr.length%2C%0A%20%20%20%20typeof%3A%20(val)%20%3D%3E%20typeof%20val%2C%0A%20%20%20%20isarray%3A%20(arr)%20%3D%3E%20Array.isArray(arr)%2C%0A%20%20%20%20isnan%3A%20(val)%20%3D%3E%20isNaN(val)%2C%0A%20%20%20%20parseint%3A%20(val)%20%3D%3E%20parseInt(val)%2C%0A%20%20%20%20parsefloat%3A%20(val)%20%3D%3E%20parseFloat(val)%2C%0A%20%20%20%20toisodate%3A%20(val)%20%3D%3E%20new%20Date(val).toISOString()%2C%0A%20%20%20%20timeoffset%3A%20(isostr)%20%3D%3E%20new%20Date(isostr).getTimezoneOffset()%2C%0A%20%20%20%20tostring%3A%20(val)%20%3D%3E%20val.toString()%2C%0A%20%20%20%20urlencode%3A%20(val)%20%3D%3E%20encodeURI(val)%2C%0A%20%20%20%20urldecode%3A%20(val)%20%3D%3E%20decodeURI(val)%2C%0A%20%20%20%20replacestr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replace(from%2C%20to)%2C%0A%20%20%20%20replaceregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replace(new%20RegExp(reg)%2C%20to)%2C%0A%20%20%20%20replaceallstr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replaceAll(from%2C%20to)%2C%0A%20%20%20%20replaceallregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replaceAll(new%20RegExp(reg%2C%20'g')%2C%20to)%2C%0A%20%20%20%20split%3A%20(str%2C%20ch)%20%3D%3E%20str.split(ch)%2C%0A%20%20%20%20mapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%20choices%5Bvalues.findIndex((target)%20%3D%3E%20target%20%3D%3D%3D%20val)%5D%2C%0A%20%20%20%20thmapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%0A%20%20%20%20%20%20%20%20choices%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20values.reduce((acc%2C%20curr%2C%20i)%20%3D%3E%20(acc%20%3D%3D%3D%200%20%7C%7C%20acc%20%3F%20acc%20%3A%20val%20%3C%3D%20curr%20%3F%20(acc%20%3D%20i)%20%3A%20(acc%20%3D%20null))%2C%20null)%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20bitwisemask%3A%20(i%2C%20mask%2C%20op%2C%20shf)%20%3D%3E%0A%20%20%20%20%20%20%20%20(op%20%3D%3D%3D%20'%26'%20%3F%20parseInt(i)%20%26%20mask%20%3A%20op%20%3D%3D%3D%20'%7C'%20%3F%20parseInt(i)%20%7C%20mask%20%3A%20op%20%3D%3D%3D%20'%5E'%20%3F%20parseInt(i)%20%5E%20mask%20%3A%20i)%20%3E%3E%0A%20%20%20%20%20%20%20%20shf%2C%0A%20%20%20%20slice%3A%20(arr%2C%20init%2C%20end)%20%3D%3E%20arr.slice(init%2C%20end)%0A%7D
1687
+ [15]:
1688
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=%22%20a%20%22%7Ctrim&transforms=%7B%0A%20%20%20%20jsonparse%3A%20(str)%20%3D%3E%20JSON.parse(str)%2C%0A%20%20%20%20jsonstringify%3A%20(obj)%20%3D%3E%20JSON.stringify(obj)%2C%0A%20%20%20%20indexOf%3A%20(val%2C%20char)%20%3D%3E%20String(val).indexOf(char)%2C%0A%20%20%20%20length%3A%20(val)%20%3D%3E%20String(val).length%2C%0A%20%20%20%20trim%3A%20(val)%20%3D%3E%20String(val).trim()%2C%0A%20%20%20%20substr%3A%20(val%2C%20int1%2C%20int2)%20%3D%3E%20String(val).substr(int1%2C%20int2)%2C%0A%20%20%20%20addreduce%3A%20(arr)%20%3D%3E%20arr.reduce((i%2C%20v)%20%3D%3E%20i%20%2B%20v)%2C%0A%20%20%20%20lengtharray%3A%20(arr)%20%3D%3E%20arr.length%2C%0A%20%20%20%20typeof%3A%20(val)%20%3D%3E%20typeof%20val%2C%0A%20%20%20%20isarray%3A%20(arr)%20%3D%3E%20Array.isArray(arr)%2C%0A%20%20%20%20isnan%3A%20(val)%20%3D%3E%20isNaN(val)%2C%0A%20%20%20%20parseint%3A%20(val)%20%3D%3E%20parseInt(val)%2C%0A%20%20%20%20parsefloat%3A%20(val)%20%3D%3E%20parseFloat(val)%2C%0A%20%20%20%20toisodate%3A%20(val)%20%3D%3E%20new%20Date(val).toISOString()%2C%0A%20%20%20%20timeoffset%3A%20(isostr)%20%3D%3E%20new%20Date(isostr).getTimezoneOffset()%2C%0A%20%20%20%20tostring%3A%20(val)%20%3D%3E%20val.toString()%2C%0A%20%20%20%20urlencode%3A%20(val)%20%3D%3E%20encodeURI(val)%2C%0A%20%20%20%20urldecode%3A%20(val)%20%3D%3E%20decodeURI(val)%2C%0A%20%20%20%20replacestr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replace(from%2C%20to)%2C%0A%20%20%20%20replaceregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replace(new%20RegExp(reg)%2C%20to)%2C%0A%20%20%20%20replaceallstr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replaceAll(from%2C%20to)%2C%0A%20%20%20%20replaceallregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replaceAll(new%20RegExp(reg%2C%20'g')%2C%20to)%2C%0A%20%20%20%20split%3A%20(str%2C%20ch)%20%3D%3E%20str.split(ch)%2C%0A%20%20%20%20mapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%20choices%5Bvalues.findIndex((target)%20%3D%3E%20target%20%3D%3D%3D%20val)%5D%2C%0A%20%20%20%20thmapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%0A%20%20%20%20%20%20%20%20choices%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20values.reduce((acc%2C%20curr%2C%20i)%20%3D%3E%20(acc%20%3D%3D%3D%200%20%7C%7C%20acc%20%3F%20acc%20%3A%20val%20%3C%3D%20curr%20%3F%20(acc%20%3D%20i)%20%3A%20(acc%20%3D%20null))%2C%20null)%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20bitwisemask%3A%20(i%2C%20mask%2C%20op%2C%20shf)%20%3D%3E%0A%20%20%20%20%20%20%20%20(op%20%3D%3D%3D%20'%26'%20%3F%20parseInt(i)%20%26%20mask%20%3A%20op%20%3D%3D%3D%20'%7C'%20%3F%20parseInt(i)%20%7C%20mask%20%3A%20op%20%3D%3D%3D%20'%5E'%20%3F%20parseInt(i)%20%5E%20mask%20%3A%20i)%20%3E%3E%0A%20%20%20%20%20%20%20%20shf%2C%0A%20%20%20%20slice%3A%20(arr%2C%20init%2C%20end)%20%3D%3E%20arr.slice(init%2C%20end)%0A%7D
1689
+ [16]:
1690
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=name%7Clength&transforms=%7B%0A%20%20%20%20jsonparse%3A%20(str)%20%3D%3E%20JSON.parse(str)%2C%0A%20%20%20%20jsonstringify%3A%20(obj)%20%3D%3E%20JSON.stringify(obj)%2C%0A%20%20%20%20indexOf%3A%20(val%2C%20char)%20%3D%3E%20String(val).indexOf(char)%2C%0A%20%20%20%20length%3A%20(val)%20%3D%3E%20String(val).length%2C%0A%20%20%20%20trim%3A%20(val)%20%3D%3E%20String(val).trim()%2C%0A%20%20%20%20substr%3A%20(val%2C%20int1%2C%20int2)%20%3D%3E%20String(val).substr(int1%2C%20int2)%2C%0A%20%20%20%20addreduce%3A%20(arr)%20%3D%3E%20arr.reduce((i%2C%20v)%20%3D%3E%20i%20%2B%20v)%2C%0A%20%20%20%20lengtharray%3A%20(arr)%20%3D%3E%20arr.length%2C%0A%20%20%20%20typeof%3A%20(val)%20%3D%3E%20typeof%20val%2C%0A%20%20%20%20isarray%3A%20(arr)%20%3D%3E%20Array.isArray(arr)%2C%0A%20%20%20%20isnan%3A%20(val)%20%3D%3E%20isNaN(val)%2C%0A%20%20%20%20parseint%3A%20(val)%20%3D%3E%20parseInt(val)%2C%0A%20%20%20%20parsefloat%3A%20(val)%20%3D%3E%20parseFloat(val)%2C%0A%20%20%20%20toisodate%3A%20(val)%20%3D%3E%20new%20Date(val).toISOString()%2C%0A%20%20%20%20timeoffset%3A%20(isostr)%20%3D%3E%20new%20Date(isostr).getTimezoneOffset()%2C%0A%20%20%20%20tostring%3A%20(val)%20%3D%3E%20val.toString()%2C%0A%20%20%20%20urlencode%3A%20(val)%20%3D%3E%20encodeURI(val)%2C%0A%20%20%20%20urldecode%3A%20(val)%20%3D%3E%20decodeURI(val)%2C%0A%20%20%20%20replacestr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replace(from%2C%20to)%2C%0A%20%20%20%20replaceregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replace(new%20RegExp(reg)%2C%20to)%2C%0A%20%20%20%20replaceallstr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replaceAll(from%2C%20to)%2C%0A%20%20%20%20replaceallregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replaceAll(new%20RegExp(reg%2C%20'g')%2C%20to)%2C%0A%20%20%20%20split%3A%20(str%2C%20ch)%20%3D%3E%20str.split(ch)%2C%0A%20%20%20%20mapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%20choices%5Bvalues.findIndex((target)%20%3D%3E%20target%20%3D%3D%3D%20val)%5D%2C%0A%20%20%20%20thmapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%0A%20%20%20%20%20%20%20%20choices%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20values.reduce((acc%2C%20curr%2C%20i)%20%3D%3E%20(acc%20%3D%3D%3D%200%20%7C%7C%20acc%20%3F%20acc%20%3A%20val%20%3C%3D%20curr%20%3F%20(acc%20%3D%20i)%20%3A%20(acc%20%3D%20null))%2C%20null)%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20bitwisemask%3A%20(i%2C%20mask%2C%20op%2C%20shf)%20%3D%3E%0A%20%20%20%20%20%20%20%20(op%20%3D%3D%3D%20'%26'%20%3F%20parseInt(i)%20%26%20mask%20%3A%20op%20%3D%3D%3D%20'%7C'%20%3F%20parseInt(i)%20%7C%20mask%20%3A%20op%20%3D%3D%3D%20'%5E'%20%3F%20parseInt(i)%20%5E%20mask%20%3A%20i)%20%3E%3E%0A%20%20%20%20%20%20%20%20shf%2C%0A%20%20%20%20slice%3A%20(arr%2C%20init%2C%20end)%20%3D%3E%20arr.slice(init%2C%20end)%0A%7D
1691
+ [17]:
1692
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=name%7CindexOf(%22e%22)&transforms=%7B%0A%20%20%20%20jsonparse%3A%20(str)%20%3D%3E%20JSON.parse(str)%2C%0A%20%20%20%20jsonstringify%3A%20(obj)%20%3D%3E%20JSON.stringify(obj)%2C%0A%20%20%20%20indexOf%3A%20(val%2C%20char)%20%3D%3E%20String(val).indexOf(char)%2C%0A%20%20%20%20length%3A%20(val)%20%3D%3E%20String(val).length%2C%0A%20%20%20%20trim%3A%20(val)%20%3D%3E%20String(val).trim()%2C%0A%20%20%20%20substr%3A%20(val%2C%20int1%2C%20int2)%20%3D%3E%20String(val).substr(int1%2C%20int2)%2C%0A%20%20%20%20addreduce%3A%20(arr)%20%3D%3E%20arr.reduce((i%2C%20v)%20%3D%3E%20i%20%2B%20v)%2C%0A%20%20%20%20lengtharray%3A%20(arr)%20%3D%3E%20arr.length%2C%0A%20%20%20%20typeof%3A%20(val)%20%3D%3E%20typeof%20val%2C%0A%20%20%20%20isarray%3A%20(arr)%20%3D%3E%20Array.isArray(arr)%2C%0A%20%20%20%20isnan%3A%20(val)%20%3D%3E%20isNaN(val)%2C%0A%20%20%20%20parseint%3A%20(val)%20%3D%3E%20parseInt(val)%2C%0A%20%20%20%20parsefloat%3A%20(val)%20%3D%3E%20parseFloat(val)%2C%0A%20%20%20%20toisodate%3A%20(val)%20%3D%3E%20new%20Date(val).toISOString()%2C%0A%20%20%20%20timeoffset%3A%20(isostr)%20%3D%3E%20new%20Date(isostr).getTimezoneOffset()%2C%0A%20%20%20%20tostring%3A%20(val)%20%3D%3E%20val.toString()%2C%0A%20%20%20%20urlencode%3A%20(val)%20%3D%3E%20encodeURI(val)%2C%0A%20%20%20%20urldecode%3A%20(val)%20%3D%3E%20decodeURI(val)%2C%0A%20%20%20%20replacestr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replace(from%2C%20to)%2C%0A%20%20%20%20replaceregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replace(new%20RegExp(reg)%2C%20to)%2C%0A%20%20%20%20replaceallstr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replaceAll(from%2C%20to)%2C%0A%20%20%20%20replaceallregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replaceAll(new%20RegExp(reg%2C%20'g')%2C%20to)%2C%0A%20%20%20%20split%3A%20(str%2C%20ch)%20%3D%3E%20str.split(ch)%2C%0A%20%20%20%20mapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%20choices%5Bvalues.findIndex((target)%20%3D%3E%20target%20%3D%3D%3D%20val)%5D%2C%0A%20%20%20%20thmapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%0A%20%20%20%20%20%20%20%20choices%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20values.reduce((acc%2C%20curr%2C%20i)%20%3D%3E%20(acc%20%3D%3D%3D%200%20%7C%7C%20acc%20%3F%20acc%20%3A%20val%20%3C%3D%20curr%20%3F%20(acc%20%3D%20i)%20%3A%20(acc%20%3D%20null))%2C%20null)%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20bitwisemask%3A%20(i%2C%20mask%2C%20op%2C%20shf)%20%3D%3E%0A%20%20%20%20%20%20%20%20(op%20%3D%3D%3D%20'%26'%20%3F%20parseInt(i)%20%26%20mask%20%3A%20op%20%3D%3D%3D%20'%7C'%20%3F%20parseInt(i)%20%7C%20mask%20%3A%20op%20%3D%3D%3D%20'%5E'%20%3F%20parseInt(i)%20%5E%20mask%20%3A%20i)%20%3E%3E%0A%20%20%20%20%20%20%20%20shf%2C%0A%20%20%20%20slice%3A%20(arr%2C%20init%2C%20end)%20%3D%3E%20arr.slice(init%2C%20end)%0A%7D
1693
+ [18]:
1694
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22value%22%20%3A%206%2C%0A%20%20%22ts%22%3A%201637245214901%2C%0A%20%22name%22%3A%20%22DevId629%22%2C%0A%20%22object%22%3A%7Bname%3A%20%22John%22%2C%20surname%3A%20%22Doe%22%7D%2C%0A%20%20%22array%22%3A%5B1%2C3%5D%0A%7D&input=name%7Csubstr(0%2Cname%7CindexOf(%22e%22)%2B1)&transforms=%7B%0A%20%20%20%20jsonparse%3A%20(str)%20%3D%3E%20JSON.parse(str)%2C%0A%20%20%20%20jsonstringify%3A%20(obj)%20%3D%3E%20JSON.stringify(obj)%2C%0A%20%20%20%20indexOf%3A%20(val%2C%20char)%20%3D%3E%20String(val).indexOf(char)%2C%0A%20%20%20%20length%3A%20(val)%20%3D%3E%20String(val).length%2C%0A%20%20%20%20trim%3A%20(val)%20%3D%3E%20String(val).trim()%2C%0A%20%20%20%20substr%3A%20(val%2C%20int1%2C%20int2)%20%3D%3E%20String(val).substr(int1%2C%20int2)%2C%0A%20%20%20%20addreduce%3A%20(arr)%20%3D%3E%20arr.reduce((i%2C%20v)%20%3D%3E%20i%20%2B%20v)%2C%0A%20%20%20%20lengtharray%3A%20(arr)%20%3D%3E%20arr.length%2C%0A%20%20%20%20typeof%3A%20(val)%20%3D%3E%20typeof%20val%2C%0A%20%20%20%20isarray%3A%20(arr)%20%3D%3E%20Array.isArray(arr)%2C%0A%20%20%20%20isnan%3A%20(val)%20%3D%3E%20isNaN(val)%2C%0A%20%20%20%20parseint%3A%20(val)%20%3D%3E%20parseInt(val)%2C%0A%20%20%20%20parsefloat%3A%20(val)%20%3D%3E%20parseFloat(val)%2C%0A%20%20%20%20toisodate%3A%20(val)%20%3D%3E%20new%20Date(val).toISOString()%2C%0A%20%20%20%20timeoffset%3A%20(isostr)%20%3D%3E%20new%20Date(isostr).getTimezoneOffset()%2C%0A%20%20%20%20tostring%3A%20(val)%20%3D%3E%20val.toString()%2C%0A%20%20%20%20urlencode%3A%20(val)%20%3D%3E%20encodeURI(val)%2C%0A%20%20%20%20urldecode%3A%20(val)%20%3D%3E%20decodeURI(val)%2C%0A%20%20%20%20replacestr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replace(from%2C%20to)%2C%0A%20%20%20%20replaceregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replace(new%20RegExp(reg)%2C%20to)%2C%0A%20%20%20%20replaceallstr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replaceAll(from%2C%20to)%2C%0A%20%20%20%20replaceallregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replaceAll(new%20RegExp(reg%2C%20'g')%2C%20to)%2C%0A%20%20%20%20split%3A%20(str%2C%20ch)%20%3D%3E%20str.split(ch)%2C%0A%20%20%20%20mapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%20choices%5Bvalues.findIndex((target)%20%3D%3E%20target%20%3D%3D%3D%20val)%5D%2C%0A%20%20%20%20thmapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%0A%20%20%20%20%20%20%20%20choices%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20values.reduce((acc%2C%20curr%2C%20i)%20%3D%3E%20(acc%20%3D%3D%3D%200%20%7C%7C%20acc%20%3F%20acc%20%3A%20val%20%3C%3D%20curr%20%3F%20(acc%20%3D%20i)%20%3A%20(acc%20%3D%20null))%2C%20null)%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20bitwisemask%3A%20(i%2C%20mask%2C%20op%2C%20shf)%20%3D%3E%0A%20%20%20%20%20%20%20%20(op%20%3D%3D%3D%20'%26'%20%3F%20parseInt(i)%20%26%20mask%20%3A%20op%20%3D%3D%3D%20'%7C'%20%3F%20parseInt(i)%20%7C%20mask%20%3A%20op%20%3D%3D%3D%20'%5E'%20%3F%20parseInt(i)%20%5E%20mask%20%3A%20i)%20%3E%3E%0A%20%20%20%20%20%20%20%20shf%2C%0A%20%20%20%20slice%3A%20(arr%2C%20init%2C%20end)%20%3D%3E%20arr.slice(init%2C%20end)%0A%7D
1695
+ [99]:
1696
+ https://czosel.github.io/jexl-playground/#/?context=%7B%0A%20%20%22text%22%20%3A%20%22%20%20foobar%7B%7D%20%20%22%0A%7D&input=text%20%7C%20replacestr(%22foo%22%2C%22FOO%22)%7Ctrim%7Curlencode&transforms=%7B%0A%20%20%20%20jsonparse%3A%20(str)%20%3D%3E%20JSON.parse(str)%2C%0A%20%20%20%20jsonstringify%3A%20(obj)%20%3D%3E%20JSON.stringify(obj)%2C%0A%20%20%20%20indexOf%3A%20(val%2C%20char)%20%3D%3E%20String(val).indexOf(char)%2C%0A%20%20%20%20length%3A%20(val)%20%3D%3E%20String(val).length%2C%0A%20%20%20%20trim%3A%20(val)%20%3D%3E%20String(val).trim()%2C%0A%20%20%20%20substr%3A%20(val%2C%20int1%2C%20int2)%20%3D%3E%20String(val).substr(int1%2C%20int2)%2C%0A%20%20%20%20addreduce%3A%20(arr)%20%3D%3E%20arr.reduce((i%2C%20v)%20%3D%3E%20i%20%2B%20v)%2C%0A%20%20%20%20lengtharray%3A%20(arr)%20%3D%3E%20arr.length%2C%0A%20%20%20%20typeof%3A%20(val)%20%3D%3E%20typeof%20val%2C%0A%20%20%20%20isarray%3A%20(arr)%20%3D%3E%20Array.isArray(arr)%2C%0A%20%20%20%20isnan%3A%20(val)%20%3D%3E%20isNaN(val)%2C%0A%20%20%20%20parseint%3A%20(val)%20%3D%3E%20parseInt(val)%2C%0A%20%20%20%20parsefloat%3A%20(val)%20%3D%3E%20parseFloat(val)%2C%0A%20%20%20%20toisodate%3A%20(val)%20%3D%3E%20new%20Date(val).toISOString()%2C%0A%20%20%20%20timeoffset%3A%20(isostr)%20%3D%3E%20new%20Date(isostr).getTimezoneOffset()%2C%0A%20%20%20%20tostring%3A%20(val)%20%3D%3E%20val.toString()%2C%0A%20%20%20%20urlencode%3A%20(val)%20%3D%3E%20encodeURI(val)%2C%0A%20%20%20%20urldecode%3A%20(val)%20%3D%3E%20decodeURI(val)%2C%0A%20%20%20%20replacestr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replace(from%2C%20to)%2C%0A%20%20%20%20replaceregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replace(new%20RegExp(reg)%2C%20to)%2C%0A%20%20%20%20replaceallstr%3A%20(str%2C%20from%2C%20to)%20%3D%3E%20str.replaceAll(from%2C%20to)%2C%0A%20%20%20%20replaceallregexp%3A%20(str%2C%20reg%2C%20to)%20%3D%3E%20str.replaceAll(new%20RegExp(reg%2C%20'g')%2C%20to)%2C%0A%20%20%20%20split%3A%20(str%2C%20ch)%20%3D%3E%20str.split(ch)%2C%0A%20%20%20%20mapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%20choices%5Bvalues.findIndex((target)%20%3D%3E%20target%20%3D%3D%3D%20val)%5D%2C%0A%20%20%20%20thmapper%3A%20(val%2C%20values%2C%20choices)%20%3D%3E%0A%20%20%20%20%20%20%20%20choices%5B%0A%20%20%20%20%20%20%20%20%20%20%20%20values.reduce((acc%2C%20curr%2C%20i)%20%3D%3E%20(acc%20%3D%3D%3D%200%20%7C%7C%20acc%20%3F%20acc%20%3A%20val%20%3C%3D%20curr%20%3F%20(acc%20%3D%20i)%20%3A%20(acc%20%3D%20null))%2C%20null)%0A%20%20%20%20%20%20%20%20%5D%2C%0A%20%20%20%20bitwisemask%3A%20(i%2C%20mask%2C%20op%2C%20shf)%20%3D%3E%0A%20%20%20%20%20%20%20%20(op%20%3D%3D%3D%20'%26'%20%3F%20parseInt(i)%20%26%20mask%20%3A%20op%20%3D%3D%3D%20'%7C'%20%3F%20parseInt(i)%20%7C%20mask%20%3A%20op%20%3D%3D%3D%20'%5E'%20%3F%20parseInt(i)%20%5E%20mask%20%3A%20i)%20%3E%3E%0A%20%20%20%20%20%20%20%20shf%2C%0A%20%20%20%20slice%3A%20(arr%2C%20init%2C%20end)%20%3D%3E%20arr.slice(init%2C%20end)%0A%7D