# Mr.Fill Bins Sensor Decoder

**URL:** <https://www.thethingsnetwork.org/forum/t/mr-fill-bins-sensor-decoder/64171>\
**Category:** Hardware\
**Created:** [August 1, 2023, 1:37pm UTC](https://www.thethingsnetwork.org/forum/t/mr-fill-bins-sensor-decoder/64171 "2023-08-01T13:37:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CyngorGwynedd](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cyngorgwynedd/32/44666_2.png) [@CyngorGwynedd](https://www.thethingsnetwork.org/forum/u/CyngorGwynedd)\
**Post date:** [August 1, 2023, 1:37pm UTC](https://www.thethingsnetwork.org/forum/t/mr-fill-bins-sensor-decoder/64171/1 "2023-08-01T13:37:48Z")

</div>

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.

```auto
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](https://www.thethingsnetwork.org/forum/uploads/default/original/3X/6/5/65a2f818d2cebc91823d7ad8f1b8ab6434731c35.png)

---

<div class="post-metadata">

**Author:** ![descartes](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/descartes/32/47220_2.png) [@descartes](https://www.thethingsnetwork.org/forum/u/descartes)\
**Post date:** [August 3, 2023, 6:26pm UTC](https://www.thethingsnetwork.org/forum/t/mr-fill-bins-sensor-decoder/64171/2 "2023-08-03T18:26:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CyngorGwynedd](https://www.thethingsnetwork.org/forum/user_avatar/www.thethingsnetwork.org/cyngorgwynedd/32/44666_2.png) [@CyngorGwynedd](https://www.thethingsnetwork.org/forum/u/CyngorGwynedd)\
**Post date:** [August 4, 2023, 1:18pm UTC](https://www.thethingsnetwork.org/forum/t/mr-fill-bins-sensor-decoder/64171/3 "2023-08-04T13:18:59Z")

</div>

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