LoRa-Plugin DZG

Hi.

I’m trying to write a decoder for the Lora plug-in from DZG, but can’t get any further.
I get the payload as Base64 and can convert it to HEX.
But I can’t get any further, unfortunately I don’t have any experience with Javascript.

I am grateful for any help.

At the moment I am using the following code to get from base64 to hex:

function toHexString(bytes) {
    return bytes.map(function(byte) {
        return ("00" + (byte & 0xFF).toString(16)).slice(-2)
      }).join('')
}

function Decode(fPort, bytes) {

    var tohex = toHexString(bytes);
  
    return {
      Hex_Daten_voll:tohex,	// return = 0004a2b49e9d03dd21b3619941000000000000 (0004a2  b49e9d03  dd21b361  99410000  00000000)
   
      };

}

bsp

I finally did it myself.

Here is the decoder:

// Anzege der HEX Daten komplett!
function toHexString(bytes) {
    return bytes.map(function(byte) {
        return ("00" + (byte & 0xFF).toString(16)).slice(-2)
      }).join('')
  }
  
  function Decode(fPort, bytes) {
    var tohex = toHexString(bytes);				
    var header = tohex.slice(0,6);
    var first = tohex.slice(22,30);
       
    //Zählerstand --> HEX to LSB First (Hexwert von rechts nach links)
    if (header == "0004a2"){
    var lsb = parseInt('0x'+first.match(/../g).reverse().join(''));
    var stand = lsb / 100 +(" kWh");
    } else {
      stand = "wird aktualisiert!";
    }
  
    return {
      Zählerstand:stand,
      };
  }
  // ENDE
1 Like