Payload Format / Decode for TM-901 / N1C2 sensor from KCS TraceME

Thanks for the explanation @arjanvanb

The device is a TM-901 / N1C2 sensor from KCS TraceME, linke here

The indexes such as bytes[19] took that from the PHP code, this was the PHP code where they split the payload and send by the vendor to me:

$compassX = convertToReal(hexdec(substr($payload,38,4)));
$compassY = convertToReal(hexdec(substr($payload,42,4)));
$compassZ = convertToReal(hexdec(substr($payload,46,4)));

The expected value is for also not clear what’s expected. For the byte shifting I’ll have to read this multiple times to understand :slight_smile: .

I took a dive in the PHP code what was sent by the vendor, there were two files:
1.NC1x_data.php
2.lora_decode_example.php

In the NC1x_data.php were lines for the compass:

private function CorrectCompassXYZ(&$a) { $g = $a['compassX'];
if ($g >= 0x8000) $g -= 0x10000;
$a['compassX'] = $g * 0.92;
$g = $a['compassY'];
if ($g >= 0x8000) $g -= 0x10000;
$a['compassY'] = $g * 0.92;
$g = $a['compassZ'];
if ($g >= 0x8000) $g -= 0x10000;
$a['compassZ'] = $g * 0.92;
}

So it looks like I’ve multiple the values by 0.92.

And two parts that are not clear to me, looks like is only a check:

$a = unpack( "Cidentifier/ntimestamp/nts2/nlongitude/nlon2/nlatitude/nlat2/Cspeed/Cheading/CIO/caccelX/caccelY/caccelZ/vcompassX/vcompassY/vcompassZ/ntemp", $Data);
$this->CorrectTimestamp($a, $TimeStamp);
$this->CorrectLatLon($a);
$a['speed'] *= 1.852;
$this->CorrectAccelXYZ($a);
$this->CorrectCompassXYZ($a);
$this->CorrectTempCelsius($a);
$this->maProperties = $a;
return $this->mValid = true;

And the second part of the code:

$a = unpack( "Cidentifier/ntimestamp/nts2/nlongitude/nlon2/nlatitude/nlat2/Cspeed/Cheading/CIO/caccelX/caccelY/caccelZ/vcompassX/vcompassY/vcompassZ/ntemp/vbattery", $Data);
$this->CorrectTimestamp($a, $TimeStamp);
$this->CorrectLatLon($a);
$a['speed'] *= 1.852;
$this->CorrectAccelXYZ($a);
$this->CorrectCompassXYZ($a);
$this->CorrectTempCelsius($a);
$a['battery'] *= 0.006406;
$this->maProperties = $a;
return $this->mValid = true; 

And when I look in the second file (lora_decode_example.php) there are this code blocks:

if ($cN1cx_data->CanGetProperty("compassX")) 
    {
        $Payload_Compassx = $cN1cx_data->GetProperty("compassX", null);
        $Payload_Compassy = $cN1cx_data->GetProperty("compassY", null);
        $Payload_Compassz = $cN1cx_data->GetProperty("compassZ", null);
    }

For better understanding, I’ve added these PHP files as TXT to this post, PHP was not possible. So you have to change the exentsion back to .php

N1Cx_data.txt (11.6 KB) lora_decode_example.txt (14.7 KB) .