Mr.Fill Bins Sensor Decoder

Hello,

I have created a decoder for the Mr. Fill Smart Bins. This is my first time creating a decoder and would like to check if it is correct / makes sense. This is the decoder below and also the documentation to go with it.

This is an example payload:

“frm_payload”: “5BLxIuQDzwAXAEI=”

Thank you.

function decodeUplink(input) {
  //Normal Communication
  if(input.bytes.length == 11)
  {
    //Byte 0
    var HatchClosed  = (input.bytes[0] & 0x80) > 0; //1 = closed
    var FillingPercentage = input.bytes[0] & 0x7F; //1-127
    //Byte 1 a 2
    var NumberOfHatchOpenings  = (input.bytes[1] << 8) + input.bytes[2];
    //Byte 3
    var NumberOfPressings  = input.bytes[3];
    //Byte 4
    var BinEmptied  = (input.bytes[4] & 0x80) > 0;//1 = emptied
    var BatteryPercentage  = input.bytes[4] & 0x7F; //1-127
    //Byte 5 a 6
    var SolarcurrentInmAh = (input.bytes[5] << 8) + input.bytes[6];
    //Byte 7 a 8
    var CurrentPlus = (input.bytes[7] << 8) + input.bytes[8];
    //Byte 9
    var SensorDefect              = (input.bytes[9] & 0x01) > 0;
    var BinIsFull                 = (input.bytes[9] & 0x02) > 0;
    var BinIsAlmostFull           = (input.bytes[9] & 0x04) > 0;
    var FullBySensor              = (input.bytes[9] & 0x08) > 0;
    var AlmostFullBySensor        = (input.bytes[9] & 0x10) > 0;
    var PressReturnCurrentExceded = (input.bytes[9] & 0x20) > 0;
    //Byte 10
    var BatteryLowError           = (input.bytes[10] & 0x01) > 0;
    var BackDoorReset             = (input.bytes[10] & 0x02) > 0;
    var BackDoorOpenError         = (input.bytes[10] & 0x04) > 0;
    var PressReturnTimeOutError   = (input.bytes[10] & 0x08) > 0;
    var CloseHatchTimeOutError    = (input.bytes[10] & 0x10) > 0;
    var OpenHatchTimeOutError     = (input.bytes[10] & 0x20) > 0;
    var OpenHatchCurrentError     = (input.bytes[10] & 0x40) > 0;
    var HatchOpenError            = (input.bytes[10] & 0x80) > 0;

    return {
      data: {
        HatchClosed: HatchClosed,
        FillingPercentage: FillingPercentage,
        NumberOfHatchOpenings: NumberOfHatchOpenings,
        NumberOfPressings: NumberOfPressings,
        BinEmptied: BinEmptied,
        BatteryPercentage: BatteryPercentage,
        SolarcurrentInmAh: SolarcurrentInmAh,
        CurrentPlus: CurrentPlus,
        //Byte 9
        SensorDefect: SensorDefect,
        BinIsFull: BinIsFull,
        BinIsAlmostFull: BinIsAlmostFull,
        FullBySensor: FullBySensor,
        AlmostFullBySensor: AlmostFullBySensor,
        PressReturnCurrentExceded: PressReturnCurrentExceded,
        //Byte 10
        BatteryLowError: BatteryLowError,
        BackDoorReset: BackDoorReset,
        BackDoorOpenError: BackDoorOpenError,
        PressReturnTimeOutError: PressReturnTimeOutError,
        CloseHatchTimeOutError: CloseHatchTimeOutError,
        OpenHatchTimeOutError: OpenHatchTimeOutError,
        OpenHatchCurrentError: OpenHatchCurrentError,
        HatchOpenError: HatchOpenError
      },
      warnings: [],
      errors: []
    };
  }
  else {
    return {
      errors: ["Error - Wrong Number of Bytes"]
    };
  }
}

image

Looks good - maybe use const instead of var and I’m not sure about the minutia detail of the efficiency of > 0 rather than == 0 or !=0, but this is very literally nitpicking.

You could also put the results directly in to an object, but again, that’s more style than functionality.

Thanks for the reply Nick. Ill do these changes now. Cheers for the feedback!