add ttn data decoder scripts
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
ffbe83511b
commit
dace837f70
|
@ -0,0 +1,45 @@
|
||||||
|
function Decoder(bytes, port) {
|
||||||
|
// Decode an uplink message from a buffer
|
||||||
|
// (array) of bytes to an object of fields.
|
||||||
|
var alarm=(bytes[6] & 0x40)?true:false; //Alarm status
|
||||||
|
value=((bytes[6] & 0x3f) <<8) | bytes[7];
|
||||||
|
var batV=value/1000; //Battery,units:Volts
|
||||||
|
value=bytes[8]<<8 | bytes[9];
|
||||||
|
if(bytes[8] & 0x80)
|
||||||
|
{
|
||||||
|
value |=0xFFFF0000;
|
||||||
|
}
|
||||||
|
var roll=value/100; //roll,units: °
|
||||||
|
value=bytes[10]<<8 | bytes[11];
|
||||||
|
if(bytes[10] & 0x80)
|
||||||
|
{
|
||||||
|
value |=0xFFFF0000;
|
||||||
|
}
|
||||||
|
var pitch=value/100; //pitch,units: °
|
||||||
|
var json={
|
||||||
|
roll:roll,
|
||||||
|
pitch:pitch,
|
||||||
|
batV:batV,
|
||||||
|
alarm:alarm
|
||||||
|
};
|
||||||
|
var value=bytes[0]<<16 | bytes[1]<<8 | bytes[2];
|
||||||
|
if(bytes[0] & 0x80)
|
||||||
|
{
|
||||||
|
value |=0xFFFFFF000000;
|
||||||
|
}
|
||||||
|
var value2=bytes[3]<<16 | bytes[4]<<8 | bytes[5];
|
||||||
|
if(bytes[3] & 0x80)
|
||||||
|
{
|
||||||
|
value2 |=0xFFFFFF000000;
|
||||||
|
}
|
||||||
|
if (value == 0x0FFFFF && value2 == 0x0FFFFF)
|
||||||
|
{
|
||||||
|
//gps disabled (low battery)
|
||||||
|
} else if (value === 0 && value2 === 0) {
|
||||||
|
//gps no position yet
|
||||||
|
} else {
|
||||||
|
json.latitude=value/10000; //gps latitude,units: °
|
||||||
|
json.longitude=value2/10000; //gps longitude,units: °
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
function Decoder(bytes, port) {
|
||||||
|
var obj = new Object();
|
||||||
|
|
||||||
|
//temp
|
||||||
|
var tempEncoded=(bytes[2]<<8)|(bytes[1]);
|
||||||
|
var tempDecoded=(tempEncoded*175.72/65536)-46.85;
|
||||||
|
obj.temp=tempDecoded.toFixed(2);
|
||||||
|
|
||||||
|
//humidity
|
||||||
|
var humEncoded=(bytes[3]);
|
||||||
|
var humDecoded=(humEncoded*125/256)-6;
|
||||||
|
obj.hum=humDecoded.toFixed(2);
|
||||||
|
|
||||||
|
//period
|
||||||
|
var periodEncoded=(bytes[5]<<8)|(bytes[4]);
|
||||||
|
var periodDecoded=(periodEncoded*2);
|
||||||
|
obj.period=periodDecoded+" sec";
|
||||||
|
|
||||||
|
//battery
|
||||||
|
var batteryEncoded=(bytes[8]);
|
||||||
|
var batteryDecoded=(batteryEncoded+150)*0.01;
|
||||||
|
obj.battery=batteryDecoded.toFixed(2);
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
Loading…
Reference in New Issue