...
Code Block | ||
---|---|---|
| ||
// 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: // - output = Object representing the decoded payload. function decodeUplink(input) { return { data: Decode(input.fPort, input.bytes, input.variables) }; } function Decode(fPort, bytes) { var output = {}; switch (fPort) { case 1: { output.NTC1_Raw_Value = bytes[0] * 0.5; output.NTC1_Temperature = bytes[1] * 0.5; output.NTC2_Raw_Value = bytes[2] * 0.5; output.NTC2_Temperature = bytes[3] * 0.5; output.Battery_Low = bytes[4] >> 4 & 0x01; output.Radio_Communication_Error = bytes[4] >> 3 & 0x01; output.Received_Signal_Strength = bytes[4] >> 2 & 0x01; output.NTC2_Sensor_Error = bytes[4] >> 1 & 0x01; output.NTC1_Sensor_Error = bytes[4] >> 0 & 0x01; output.Storage_Voltage = Number((bytes[5] * 0.02).toFixed(2)); break; } case 2: { { var REV_Major = (bytes[0] & 0xF).toString(); var REV_Minor = ((bytes[0] >> 4) & 0xF).toString(16); output.REV = REV_Major + "." + REV_Minor; } { var HW_Major = (bytes[1] & 0xF).toString(); var HW_Minor = ((bytes[1] >> 4) & 0xF).toString(); output.HW = HW_Major + "." + HW_Minor; } { var FW_Year = bytes[2].toString(); var FW_Month = bytes[3].toString(); var FW_Day = bytes[4].toString(); var FW_Minor = bytes[5].toString(); output.FW = "20" + FW_Year + "." + FW_Month + "." + FW_Day + "." + FW_Minor; break; } } default: return { errors: ['unknown FPort'], }; } return output; } |
Uplink Decoder Example
...
Chirpstack Downlink Encoder
...