Open
Description
Example 1:
The error is in line 9; there is a missing ';' at the end. However, the error message incorrectly states that the issue is in line 10.
/** Decoder **/
// decode payload to string
var payloadStr = decodeToString(payload);
// decode payload to JSON
// var data = decodeToJson(payload);
var deviceName = payloadStr.substring(0,6)
var deviceType = payloadStr.substring(6,13);
// Result object with device/asset attributes/telemetry data
var result = {
deviceName: deviceName,
deviceType: deviceType,
attributes: {},
telemetry: {
temperature: parseFloat(payloadStr.substring(13, 17))
}
};
/** Helper functions 'decodeToString' and 'decodeToJson' are already built-in **/
return result;
Example 2:
The issue is in line 8, where a non-existing method is being called. However, the error message incorrectly states that the problem is in the first line.
/** Decoder **/
// decode payload to string
var payload= decodeToJson(payload);
var deviceName = payload["devName"];
var deviceType = payload.param1;
var param2 = payload.param2.someNonExistingMethod();
// Result object with device/asset attributes/telemetry data
var result = {
deviceName: deviceName,
deviceType: deviceType,
attributes: {},
telemetry: {
temperature: payload.param1,
temp: payload["param2"].test,
t: param2
}
};
/** Helper functions 'decodeToString' and 'decodeToJson' are already built-in **/
return result;
Metadata
Assignees
Labels
No labels