Garden environmental telemetry project – part 4

Garden environmental telemetry project – part 1 laid out plans for a simple maker / DIY IoT garden environmental telemetry system.

This article documents a change to the sensor configuration and payload formatter in preparation for another RS485-LN.

The sensors are now:

  • ID=1 air temperature and humidity;
  • ID=2 soil temperature and humidity.

The payload  contains a 8bit payload version number then four 16bit values for the four sensors. This is parsed by the TNN uplink formatter.

function decodeUplink(input) {
  var payver=input.bytes[0];
  switch(payver){
    case 1:
      return {
        data: {
          field3: ((input.bytes[3]<< 8)|input.bytes[4])/10,
          field4: ((input.bytes[1]<< 8)|input.bytes[2])/10,
          field5: ((input.bytes[7]<< 8)|input.bytes[8])/10,
          field6: ((input.bytes[5]<< 8)|input.bytes[6])/10
        },
      warnings: [], // optional
      errors: [] // optional (if set, the decoding failed)
      };
    case 2:
      break;
    }
  }

Above, is the Custom Javascript formatter which writes the measured values into variables fields3-field6 of the data object.

To be continued…