Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Sample upload from the Gateway:

00
0x00
00 0700 0302 11
0x00 0x070x00 0x030x02 0x11
Header, see main documentationUnit 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

Code Block
languagejs
titleSample Parser
linenumberstrue
collapsetrue
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;
}

/**
 * LoRaServer decoder function.
 */
function Decode(fPort, bytes) {
    // wrap TTN Decoder:
    return Decoder(bytes, fPort);
}
function Parse(input) {
    var data = bytes(atob(input.data));
    var port = input.fPort;
    var fcnt = input.fCnt;
    var vals = {};
    if( port == 20 ){
        if( (uint16_BE(data, 1)==7) && (uint16_BE(data, 3)==3)){
          if( int16_BE(data, 5)/10 < 0){
             vals["mH2O"] = "Err" // Most propably not under water
          }
          vals["mH2O"] = int16_BE(data, 5)/1000;
        }
        else{
          vals["mH2O"] = "Invalid configuration";
        }
    }
    
    vals["port"] = port;
    vals["data"] = data;
    vals["fcnt"] = fcnt;
    var lastFcnt = Device.getProperty("lastFcnt");
    vals["reset"] = fcnt <= lastFcnt;
    Device.setProperty("lastFcnt", fcnt);
    return vals;
}