Lobaro Pressure Sensor

Reading from the Lobaro Pressure Sensor using the Hybrid Gateway can be done by setting the following parameters in the configuration:

ParamterValueComment
PlFmt5Sets the payload to a short format
MbCmd0 0/5 * * * *:R,9600,8N1:010300020003Reads the Registers 2 to 4, the cron can be changed, for more info see CRON Expressions


Sample upload from the Gateway:

0x000x00 0x070x00 0x030x02 0x11
Header, for more info see Hybrid Modbus Gateway (ext. Power)Unit is mH2O3 decimals precisionCurrent Value


The Value is transmitted as 16 bit signed int in Big Endian format with 3 decimals presicion.

The sample hex value of 0x0211 translates to 529 decimal. Considering the 3 decimals precision the value is 0,529 mH2O.


Sample Parser

function signed(val, bits) {
    // max positive value possible for signed int with bits:
    var mx = Math.pow(2, bits-1);
    if (val < mx) {
        // is positive value, just return
        return val;
    } else {
        // is negative value, convert to neg:
        return val - (2 * mx);
    }
}

function int16_BE(bytes, idx) {
    bytes = bytes.slice(idx || 0);
    return signed(bytes[0] << 8 | bytes[1] << 0, 2*8);
}

function uint16_BE(bytes, idx) {
    bytes = bytes.slice(idx || 0);
    return bytes[0] << 8 | bytes[1] << 0;
}


/**
 * TTN decoder function.
 */
function Decoder(bytes, port) {
    var vals = {};
    if( port == 20 ){
		// make sure that unit is mH2O and precision is 3 decimals
        if( (uint16_BE(bytes, 1)==7) && (uint16_BE(bytes, 3)==3)){
          if( int16_BE(bytes, 5)/10 < 0){
             vals["mH2O"] = "Err" // Most propably not under water
          }
          else{
            vals["mH2O"] = int16_BE(bytes, 5)/1000;
          }
        }
        else{
          vals["mH2O"] = "Invalid configuration";
        }
    }  
    return vals;
}

/**
 * TTN V3 Wrapper
 */
function decodeUplink(input) {
   return {
    data: {
      values: Decoder(input.bytes, input.fPort)
    },
    warnings: [],
    errors: []
  };
}


/**
 * LoRaServer decoder function.
 */
function Decode(fPort, bytes) {
    // wrap TTN Decoder:
    return Decoder(bytes, fPort);
}

/**
 * Lobaro Platform decoder function.
 */
function Parse(input) {
    var data = bytes(atob(input.data));
    var port = input.fPort;
   
    return Decoder(data, port);
}