-
Notifications
You must be signed in to change notification settings - Fork 88
/
iotagent.apib
445 lines (309 loc) · 16.7 KB
/
iotagent.apib
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
FORMAT: 1A
HOST: http://idas.lab.fiware.org
TITLE: FIWARE IoT Agents API
DATE: December 2016
VERSION: stable
APIARY_PROJECT: telefonicaiotiotagents
SPEC_URL: https://telefonicaid.github.io/iotagent-node-lib/api/
GITHUB_SOURCE: https://github.com/telefonicaid/iotagent-node-lib
## Copyright
Copyright (c) 2014-2016 Telefonica Investigacion y Desarrollo
## License
This specification is licensed under the
[FIWARE Open Specification License (implicit patent license)](https://forge.fiware.org/plugins/mediawiki/wiki/fiware/index.php/Implicit_Patents_License).
# IoT Agent Provision API Documentacion
An [IoT Agent](https://github.com/telefonicaid/fiware-IoTAgent-Cplusplus) is a component that mediates between a set of Devices using their own native protocols and a NGSI compliant Context Provider (i.e. Fiware Context Broker).
This documentation covers the IoT Agent Provision API and the resources you can manipulate on an IoT Agent in order to publish custom information in IoT Platform. The IoT Agent Provision API is based on REST principles.
|Allowed HTTPs requests | |
|:---------------------------|:----------------------------------------|
|POST: |Creates a resource or list of resources |
|PUT: |Updates a resource |
|GET: |Retrieves a resource or list of resources|
|DELETE: |Delete a resource |
|Server Responses | |
|:---------------------------|:--------------------------------------------------------------------------------------------------|
|200 OK |The request was succesful (some API calls may return 201 instead) |
|201 Created |The request was succesful and a resource or list of resources was created |
|204 No Content |The request was succesful but there is no representation to return (that is, the response is empty)|
|400 Bad Request |The request could not be understood or was missing required parameters |
|401 Unauthorized |Authentication failed |
|403 Forbidden |Access denied |
|404 Not Found |Resource was not found |
|409 Conflict |A resource cannot be created because it already exists |
|500 Internal Server Error |Generic error when server has a malfunction. This error will be removed |
Responses related with authentication and authorization depends on this feature is configured and a Keystone OpenStack sytem is present.
When an error is returned, a representation is returned as:
```json
{
"reason": "contains why an error is returned",
"details": "contains specific information about the error, if possible"
}
```
## Authentication and Authorization
If the IoT Agent is in authenticated environment, this API requires a token, which you obtain from authentication system. This system and its API is out of scope of present documentation. In this environment, a mandatory header is needed: `X-Auth-Token`.
## Mandatory HTTP Headers
The API needs two headers in order to manage requests:
|Http Header |Level |If not present |Observations |
|:---------------------------|:-----------------------------------------------------------------------------------------------------------------------------|:------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------|
|<b>Fiware-Service</b> |Represents a tenant. Higher level in resources hierachy in IoT Platform |An error is returned |Must only contain less than 50 Underscores and Alphanumeric lowercase characters |
|<b>Fiware-ServicePath</b> |Represents the second level |We assume '/'. Allowed operation '/*'|Must only contain less than 50 Underscores and Alphanumeric characters. Must start with character '/'. Max. length is 51 characters (with /)|
## API Access
All API base URLs are relative and depend on where the IoT Agent is listening (depends on each service).
For example, `http://127.0.0.1:8080/iot/`.
# Configuration Group API
## Services [/services{?limit,offset,resource,apikey,device}]
Configuration group for iotagents.
Fields in JSON object representing a configuration group are:
|Fields in JSON Object | |
|:-----------------------|:------------------------------------------------------------|
|`apikey` |It is a key used for devices belonging to this service. If "", service does not use apikey, but it must be specified.|
|`token` |If authentication/authorization system is configured, IoT Agent works as user when it publishes information. That token allows that other components to verify the identity of IoT Agent. Depends on authentication and authorization system.|
|`cbHost` |Context Broker endpoint assigned to this service, it must be a real uri.|
|`outgoing_route` |It is an identifier for VPN/GRE tunnel. It is used when device is into a VPN and a command is sent.|
|`resource` |Path in IoTAgent. When protocol is HTTP a device could send information to this uri. In general, it is a uri in a HTTP server needed to load and execute a module.|
|`entity_type` |Entity type used in entity publication (overload default).|
|`attributes` |Mapping for protocol parameters to entity attributes.<br> `object_id` (string, mandatory): protocol parameter to be mapped.<br> `name` (string, mandatory): attribute name to publish.<br> `type`: (string, mandatory): attribute type to publish.|
|`static_attributes` |Attributes published as defined.<br> `name` (string, mandatory): attribute name to publish.<br> `type` (string, mandatory): attribute type to publish.<br> `value` (string, mandatory): attribute value to publish.|
| `timestamp`. |(optional, boolean): This field indicates if an attribute 'TimeInstant' will be added (true) or not (false). If this field is omitted, the global IotAgent configuration timestamp will be used.|
| `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`.|
Mandatory fields are identified in every operation.
`static_attributes` and `attributes` are used if device has not this information.
### Retrieve a configuration group [GET]
Retrieve a configuration group.
+ Parameters [limit, offset, resource]
+ `limit` (optional, number). In order to specify the maximum number of services (default is 20, maximun allowed is 1000).
+ `offset` (optional, number). In order to skip a given number of elements at the beginning (default is 0) .
+ `resource` (optional, string). URI for the iotagent, return only services for this iotagent.
+ Request (application/json)
+ Headers
Fiware-Service: testservice
Fiware-ServicePath: /*
+ Response 200
+ Body
{
"count": 1,
"services": [
{
"apikey": "apikey3",
"service": "service2",
"service_path": "/srvpath2",
"token": "token2",
"cbHost": "http://127.0.0.1:1026",
"entity_type": "thing",
"resource": "/iot/d"
}
]
}
+ Request (application/json)
+ Headers
Fiware-Service: testservice
Fiware-ServicePath: /TestSubservice
+ Response 200
+ Body
{
"count": 1,
"services": [
{
"apikey": "apikey3",
"service": "service2",
"service_path": "/srvpath2",
"token": "token2",
"cbHost": "http://127.0.0.1:1026",
"entity_type": "thing",
"resource": "/iot/d"
}
]
}
### Create a configuration group [POST]
Create a new configuration group. From service model, mandatory fields are: apikey, resource (cbHost field is temporary mandatory).
+ Request (application/json)
+ Headers
Fiware-Service: testservice
Fiware-ServicePath: /TestSubservice
+ Body
{
"services": [
{
"apikey": "apikey3",
"token": "token2",
"cbHost": "http://127.0.0.1:1026",
"entity_type": "thing",
"resource": "/iot/d"
}
]
}
+ Response 201
### Update a configuration group [PUT]
If you want modify only a field, you can do it. You cannot modify an element into an array field, but whole array. ("/*" is not allowed).
+ Parameters [apikey, resource]
+ `apikey` (optional, string). If you don't specify, apikey=" " is applied.
+ `resource` (mandatory, string). URI for service into iotagent.
+ Request (application/json)
+ Headers
Fiware-Service: testservice
Fiware-ServicePath: /TestSubservice
+ Body
{
"entity_type": "entity_type"
}
+ Response 204
### Remove a configuration group [DELETE]
Remove a configuration group.
+ Parameters [apikey, resource, device]
+ `apikey` (optional, string). If you don't specify, apikey="" is applied.
+ `resource` (mandatory, string). URI for service into iotagent.
+ `device` (optional, boolean). Default value is false. Remove devices in service/subservice. This parameter is not valid when Fiware-ServicePath is '/*' or '/#'.
+ Request (application/json)
+ Headers
Fiware-Service: testservice
Fiware-ServicePath: /TestSubservice
+ Response 204
## Devices [/devices{?limit,offset,detailed,protocol,entity}]
A device is a resource that publish information to IoT Platform and it uses the IoT Agent.
### Device Model
- `device_id`. Unique identifier into a service.
- `protocol`. Protocol assigned to device. This field is easily provided by IoTA Manager if it is used. Every module implmenting a protocol has an identifier.
- `entity_name`. Entity name used for entity publication (overload default)
- `entity_type`. Entity type used for entity publication (overload entity_type defined in service).
- `timezone`. Used to automatically generate timestamps attributes for the entity publication.
- `attributes`. Mapping for protocol parameters to entity attributes.
`object_id` (string, mandatory): protocol parameter to be mapped.
`name` (string, mandatory): attribute name to publish.
`type`: (string, mandatory): attribute type to publish.
- `static_attributes` (optional, array). Attributes published as defined.
`name` (string, mandatory): attribute name to publish.
`type` (string, mandatory): attribute type to publish.
`value` (string, mandatory): attribute value to publish.
- `endpoint` (optional, string): when a device uses push commands.
- `commands` (optional, array). Attributes working as commands.
`name` (string, mandatory): command identifier.
`type` (string, mandatory). It must be 'command'.
`value` (string, mandatory): command representation depends on protocol.
- `timestamp`. (optional, boolean): This field indicates if an attribute 'TimeInstant' will be added (true) or not (false). If this field is omitted, the global IotAgent configuration timestamp will be used.
Mandatory fields are identified in every operation.
### Retrieve all devices [GET]
+ Parameters [limit, offset, detailed, entity, protocol]
+ `limit` (optional, number). In order to specify the maximum number of devices (default is 20, maximun allowed is 1000).
+ `offset` (optional, number). In order to skip a given number of elements at the beginning (default is 0) .
+ `detailed` (optional, string). `on` return all device information, `off` (default) return only name.
+ `entity` (optional, string). It allows get a device from entity name.
+ `protocol` (optional, string). It allows get devices with this protocol.
+ Request (application/json)
+ Headers
Fiware-Service: testService
Fiware-ServicePath: /TestSubservice
+ Response 200
+ Body
{
"count": 1,
"devices": [
{
"device_id": "device_id",
"protocol": "12345",
"entity_name": "entity_name",
"entity_type": "entity_type",
"timezone": "America/Santiago",
"attributes": [
{
"object_id": "source_data",
"name": "attr_name",
"type": "int"
}
],
"static_attributes": [
{
"name": "att_name",
"type": "string",
"value": "value"
}
]
}
]
}
### Create a device [POST]
From device model, mandatory fields are: device_id and protocol.
+ Request (application/json)
+ Headers
Fiware-Service: testservice
Fiware-ServicePath: /TestSubservice
+ Body
{
"devices": [
{
"device_id": "device_id",
"protocol": "12345",
"entity_name": "entity_name",
"entity_type": "entity_type",
"timezone": "America/Santiago",
"attributes": [
{
"object_id": "source_data",
"name": "attr_name",
"type": "int"
}
],
"static_attributes": [
{
"name": "att_name",
"type": "string",
"value": "value"
}
]
}
]
}
+ Response 201
+ Headers (only if ONE device is in request)
Location: /iot/devices/device_id
+ Response 400
{
"reason": "parameter limit must be an integer"
}
+ Response 404
## Device [/devices/{device_id}]
### Retrieve a device [GET]
+ Request (application/json)
+ Headers
Fiware-Service: testservice
Fiware-ServicePath: /TestSubservice
+ Response 200
+ Body
{
"device_id": "device_id",
"protocol": "121345",
"entity_name": "entity_name",
"entity_type": "entity_type",
"timezone": "America/Santiago",
"attributes": [
{
"object_id": "source_data",
"name": "attr_name",
"type": "int"
}
],
"static_attributes": [
{
"name": "att_name",
"type": "string",
"value": "value"
}
]
}
### Update a device [PUT]
If you want modify only a field, you can do it, except field `protocol` (this field, if provided it is removed from request).
+ Request (application/json)
+ Headers
Fiware-Service: testservice
Fiware-ServicePath: /TestSubservice
+ Body
{
"entity_name": "entity_name"
}
+ Response 204
### Remove a device [DELETE]
If specific device is not found, we work as deleted.
+ Request (application/json)
+ Headers
Fiware-Service: testservice
Fiware-ServicePath: /TestSubservice
+ Response 204