Changing the rain gauge resolution: decoding the MeteoHelix® message format

QUESTION: How do I change the rain gauge resolution in the JavaScript decoder code when implementing it in my own web platform?

ANSWER: If you are set at using 0.2 mm resolution rain gauges, you can change one line in the code by multiplying the rain output by 0.2 as shown below. For other rain gauge resolutions, use the appropriate value based on your rain gauge.

NOTE: The MeteoHelix® sends unitless rain values. It sends the number of accumulated clicks of the rain gauge mechanism as recorded by its rain gauge input. 99 % of all automatic rain gauges use a reed switch mechanism that sends a signal (called a click) when a rain amount equivalent to the rain gauge resolution accumulates in the rain gauge. An advanced version of this type of mechanism is also used in the MeteoRain Compact rain gauges.

Change rain gauge resolution by changing the highlighted line of code.

Change rain gauge resolution by changing the highlighted line of code.

 

Illustration of how to change the decoder JavaScript code follows:

//Original rain calculation without a resolution specified
    Rain = precisionRound(bitShift(8), 1);
//Updated rain calculation with 0.2 mm rain gauge resolution
    Rain = precisionRound(bitShift(8)*0.2, 1);
 
 

JavaScript decoder code with 0.2 mm rain gauge resolution implemented follows:

var pos = 0;
var bindata = "";

var ConvertBase = function (num) {
    return {
        from : function (baseFrom) {
            return {
                to : function (baseTo) {
                    return parseInt(num, baseFrom).toString(baseTo);
                }
            };
        }
    };
};

function pad(num) {
    var s = "0000000" + num;
    return s.slice(-8);
}

ConvertBase.dec2bin = function (num) {
    return pad(ConvertBase(num).from(10).to(2));
};

ConvertBase.bin2dec = function (num) {
    return ConvertBase(num).from(2).to(10);
};

function data2bits(data) {
    var binary = "";
    for(var i=0; i<data.length; i++) {
        binary += ConvertBase.dec2bin(data[i]);
    }
    return binary;
}

function bitShift(bits) {
    var num = ConvertBase.bin2dec(bindata.substr(pos, bits));
    pos += bits;
    return Number(num);
}

function precisionRound(number, precision) {
  var factor = Math.pow(10, precision);
  return Math.round(number * factor) / factor;
}

function Decoder(bytes, port) {
  bindata = data2bits(bytes);
  
  //if(bytes.length != 12) return {"status": "ERROR", "description": "11 bytes are required"}
    Type =  bitShift(2);
    Battery = precisionRound(bitShift(5)*0.05+3, 1);
    Temperature = precisionRound(bitShift(11)*0.1-100, 1);
    T_min = precisionRound(Temperature - bitShift(6)*0.1, 1);
    T_max = precisionRound(Temperature + bitShift(6)*0.1, 1);
    Humidity = precisionRound(bitShift(9)*0.2, 1);
    Pressure = bitShift(14)*5+50000;
    Irradiation = bitShift(10)*2;
    Irr_max = Irradiation + bitShift(9)*2;
    Rain = precisionRound(bitShift(8)*0.2, 1);
    CO2 = precisionRound(bitShift(8)*5+300, 1);
 
 
  decoded = {
    "Type": Type,
    "Battery": Battery,
    "Temperature": Temperature,
    "T_min": T_min ,
    "T_max": T_max,
    "Humidity": Humidity,
    "Pressure": Pressure,
    "Irradiation": Irradiation,
    "Irr_max": Irr_max,
    "Rain": Rain,
    "CO2": CO2
  };

  return decoded;
}