I have tried to adapt a working codec for a differemnt device which does not have a published codec. The device is a Tek766 Oil Tank Sensor, and I have tried to understand and reuse some code, but I now get thrown an error that doesn’t seem to refer to the codec specifically, but rather to the script that uses the function defined in my codec.
I am not proficient in JS, my background is more Bash and Python, and so I am not sure what I have missed. If anyone could give me some pointers, that would be really useful.
I did paste the whole code from Notepad++ with only the LF newline in case the Windows line feed was an issue, but I am still getting the same error.
The Error is:
JS error: Error: unexpected token in expression: 'var' at eval_script:35:10
My code is as follows:
// Decode uplink function.
//
// Input is an object with the following fields:
// - bytes = Byte array containing the uplink payload, e.g. [255, 230, 255, 0]
// - fPort = Uplink fPort.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - data = Object representing the decoded payload.
const PORT_SONIC_MEASUREMENT = 0x10;
const PORT_STATUS = 0x30;
const PORT_ALARM_NOTOFICATION = 0x45;
function decodeUplink(input) {
var bytes = input.bytes;
var port = input.fPort;
var data = {};
if ( port===PORT_SONIC_MEASUREMENT && bytes.length === 20) {
var ullage0=bytes.readUInt16BE(4);
var temp0=bytes.readInt8(6);
data.TYPE="measurement",
data.ULLAGE=ullage0,
data.TEMP=temp0
return {
data: data,
};
} else if (port===PORT_STATUS && bytes.length === 18) {
data.TYPE="status",
var rssi=bytes.readUInt8(8);
data.RSSI=-rssi,
var battery=bytes.readUInt8(10);
data.BATTERYLEVEL=battery,
var ullage=bytes.readUInt16BE(14);
data.ULLAGE=ullage,
var temperature=bytes.readInt8(16);
data.TEMP=temperature,
return {
data: data,
}
}
}
// Encode downlink function.
//
// Input is an object with the following fields:
// - data = Object representing the payload that must be encoded.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - bytes = Byte array containing the downlink payload.
function encodeDownlink(input) {
return {
bytes: [225, 230, 255, 0]
};
}
If anyone can give me any ideas where my problem lies, I’d be grateful.