decode #
This method must be implemented in order to decode the payload.
It has to return a promise resolving to a DeviceContent with the following information:
reference
: device identifiermeasures
: measures received in the payloadqos
: additional information about device state like battery, etc. (optional)
abstract decode (payload: JSONObject, request: KuzzleRequest): Promise<DeviceContent>
Arguments | Type | Description |
---|---|---|
payload | JSONObject | Raw payload received in the API action body |
request | KuzzleRequest | API request of origin |
Returns #
Returns a promise resolving to a DeviceContent
.
Usage #
Considering the following payload:
{
deviceEUI: '12345',
register55: 23.3,
batteryLevel: 0.8,
}
The following decode
method could be implemented:
import { JSONObject, KuzzleRequest } from 'kuzzle';
import { Decoder, DeviceContent } from 'kuzzle-plugin-device-manager';
class KarakoyDecoder extends Decoder {
// [...]
async decode (payload: JSONObject, request: KuzzleRequest): Promise<DeviceContent> {
const deviceContent: DeviceContent = {
reference: payload.deviceEUI,
measures: {
temperature: {
updatedAt: Date.now(),
value: payload.register55,
}
},
qos: {
battery: payload.batteryLevel * 100
}
};
return deviceContent;
}
}
Edit this page on Github(opens new window)