Scripting examples
Script input and output
Encode Function
Input to the encoder is an object (for example, impactRequest). The following table lists the methods that are required in the script.
Method | Remark |
---|---|
utils.getRequestType(impactRequest); | var utils =
Java.type('com.nokia.adapter.transformation.utils.TranformerUtil'); This method is used to identify the request type. Supported values: write and read |
impactRequest.getCorrelatorId() | Returns the correlator ID of the request. |
impactRequest.getValue() | Returns value of the resource. |
impactRequest.getResource() | Returns the resource path for the request. |
The output of encode function is expected to be a json string. utils.createMqttEncodeResponse(response) method in utils form the return message.
Decode Function
The input to the decoder is an object (for example, decodeCtx). The following methods are used in the script.
Method | Remark |
---|---|
decodeCtx.getUplinkMessage(); | This returns an int8 array and contains the payload from the device of type PublishMessage. |
client.getEndpoint(); | Returns serial number of the device. |
PublishMessage
Parameters | Description |
---|---|
topic | Resource path published by the device. |
payload | Payload published by the device |
The output response of encode function is expected to be a json string.
utils.createMqttDecodeResponse(response) function must be called to create the decode function.