Needing help making a decoder for Moko LW004-PB

Hi all,

I’ve just purchased a few waterproof panic buttons; previously I have used Dragino units and they have been very helpful in providing a TTN decoder.

Mokosmart have only provided me example data and don’t provide the decoder, so hoping someone with smarts can help me; as I just cant work out how to count the bytes etc; hoping after seeing how this one is done I will learn for the future.

I managed to get this far but don’t know how to get to the value of 2838905 or 5334647 in their latitude/longitude example

function Decoder(bytes, port) {
  // Decode an uplink message from a buffer
  // (array) of bytes to an object of fields.
  var decoded = {};

  // if (port === 1) decoded.led = bytes[0];

  decoded.Battery = bytes[0]
  decoded.Alatm_STATUS = bytes[1]
  decoded.Latitude= bytes[2]+bytes[3]+bytes[4]+bytes[5]
  decoded.Longitude= bytes[6]+bytes[7]+bytes[8]+bytes[9]

  return decoded;
}

The example data is attached
image-2

So I need to get the 3 bytes next to each other, i.e. 306EA3 = 3174051
But I cant work out how to place the 3 bytes next to each other
bytes[4] bytes[3] bytes[2]

They sent me some more documentation, which unfortunately still does not help me
payload format

Hi, I managed to get the data using the following decode script.

function byteToHex(byte) {
  var unsignedByte = byte & 0xff;
  if (unsignedByte < 16) {
    return '0' + unsignedByte.toString(16);
  } else {
    return unsignedByte.toString(16);
  }
}

function Decoder(bytes, port) {
 
  var decoded = {};

  decoded.Battery = bytes[0]
  decoded.Alatm_STATUS = bytes[1]
  
  var parse_len = 2; //// start byte of gps
  decoded.Latitude = bytes[parse_len] + bytes[parse_len+1]*256 + bytes[parse_len+2]*256*256 + bytes[parse_len+3]*256*256*256;
  parse_len += 4;
  decoded.Longitude = bytes[parse_len] + bytes[parse_len+1]*256 + bytes[parse_len+2]*256*256 + bytes[parse_len+3]*256*256*256;
  parse_len += 4;

		if(decoded.Latitude>0x80000000)
			decoded.Latitude -= 0x100000000;
		if(decoded.Longitude>0x80000000)
			decoded.Longitude -= 0x100000000;
		decoded.Latitude = decoded.Latitude*90/8388607;
		decoded.Longitude = decoded.Longitude*180/8388607;
  
  decoded.btMac = byteToHex(bytes[10])+byteToHex(bytes[11])+byteToHex(bytes[12])+byteToHex(bytes[13])+byteToHex(bytes[14])+byteToHex(bytes[15]);
  decoded.btMac = decoded.btMac.toUpperCase();
  
  decoded.asix_x = bytes[16]*256 + bytes[17] +" mg";
  decoded.asix_y = bytes[18]*256 + bytes[19] +" mg";
  decoded.asix_z = bytes[20]*256 + bytes[21] +" mg";
  decoded.angular = bytes[22] + bytes[23];
  
  return decoded;
}
1 Like

Moko decoders can be found here