Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/2/controllers/decoders/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
code: true
type: branch
title: decoders
description: Kuzzle IoT Platform - Device Manager - Decoders Controller
---
59 changes: 59 additions & 0 deletions doc/2/controllers/decoders/list/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
code: true
type: page
title: list
description: List registered decoders
---

# list

List registered decoders.

## Query Syntax

### HTTP

```http
URL: http://kuzzle:7512/_/device-manager/decoders
Method: GET
```

### Other protocols

```js
{
"controller": "device-manager/decoders",
"action": "list",
}
```

---

## Response

```js
{
"status": 200,
"error": null,
"controller": "device-manager/decoders",
"action": "list",
"requestId": "<unique request identifier>",
"result": {
"decoders":[
{
"action":"AdeunisComfort",
"deviceModel":"AdeunisComfortCo2",
"measures":[
{
"name":"environmentalQuality",
"type":"environmentalQuality"
}
]
},
{
...
}
]
}
}
```
57 changes: 57 additions & 0 deletions doc/2/controllers/decoders/prune-payloads/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
code: true
type: page
title: prunePayloads
description: Clean payload collection for a time period
---

# Prune payloads

Clean payload collection for a time period.

## Query Syntax

### HTTP

```http
URL: http://kuzzle:7512/_/device-manager/decoders/_prunePayloads
Method: DELETE
```

### Other protocols

```js
{
"controller": "device-manager/decoders",
"action": "prunePayloads",
"body":{
"days":number,
"deviceModel":string,
"onlyValid":boolean
}
}
```
---

## Body Arguments

- `days`: number of days of payloads to preserve
- `deviceModel`: (optional) specific device model filter for the payloads to delete
- `onlyValid`: (default true) should delete only valid payloads

---

## Response

```js
{
"status": 200,
"error": null,
"controller": "device-manager/decoders",
"action": "prunePayloads",
"requestId": "<unique request identifier>",
"result": {
"deleted":12
}
}
```
88 changes: 88 additions & 0 deletions doc/2/controllers/decoders/route/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
code: true
type: page
title: route
description: Redirect to corresponding decoder
---

# Route

Redirects payload to corresponding decoder determined by deviceModel.

## Query Syntax

### HTTP

```http
URL: http://kuzzle:7512/_/device-manager/decoders/route
Method: POST
```

### Other protocols

```js
{
"controller": "device-manager/decoders",
"action": "route",
"body":{
"deviceModel":"string",
...rest of the device payload
}
}
```
---

## Body Arguments

- `deviceModel`: device model of the payload.

---

## Response

```js
{
"status": 200,
"error": null,
"controller": "device-manager/decoders",
"action": "route",
"requestId": "<unique request identifier>",
"result": {
"valid":true
}
}
```

## Implementation

This route is typically used when we need a unique endpoint for an IoT gateway.

It needs the field `deviceModel` to redirect the payload to the correct decoder, if you need to check the available device models of your application you can list them with the "device-manager/decoders:route" action.

If you can not configure your gateway to add this field you can use a pipe to enrich the payloads before they are treated by the controller.

In the following example a gateway refers the constructor and model of the device in a `metadata` object in every sent payload:

``` typescript
this.app.pipe.register(
'device-manager/decoders:beforeRoute',
async (request: KuzzleRequest) => {
const body = request.getBody();
// We build the deviceModel field from the metadata sent by the gateway
const constructor = body?.metadata.constructor;
const model = body?.metadata.model;
if (constructor && model) {
const deviceModel = constructor + model
this.app.log.info(`Identified device model: ${deviceModel}`);

// We then add this deviceModel to the body of the request
request.input.body.deviceModel = deviceModel;
} else {
this.app.log.warn(
`Could not find device model`,
);
}
return request;
},
);
```