Sorry to hijack this thread. I might be completely stupid, but I indeed haven’t found a button (or other way) to create a new topic (strange).
I am also trying to migrate a simple tracking application from v2 to v3. I am having strange problems with the payload formatter. Maybe you can help me.
This is the formatter in v2:
function Decoder(bytes, port) {
// Decode an uplink message from a buffer
// (array) of bytes to an object of fields.
var latitude;//gps latitude,units: °
latitude=(bytes[0]<<24 | bytes[1]<<16 | bytes[2]<<8 | bytes[3])/1000000;//gps latitude,units: °
var longitude;
longitude=(bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7])/1000000;//gps longitude,units: °
var alarm=(bytes[8] & 0x40)?"TRUE":"FALSE";//Alarm status
var batV=(((bytes[8] & 0x3f) <<8) | bytes[9])/1000;//Battery,units:V
if((bytes[10] & 0xC0)==0x40)
{
var motion_mode="Move";
}
else if((bytes[10] & 0xC0) ==0x80)
{
motion_mode="Collide";
}
else if((bytes[10] & 0xC0) ==0xC0)
{
motion_mode="User";
}
else
{
motion_mode="Disable";
} //mode of motion
var led_updown=(bytes[10] & 0x20)?"ON":"OFF";//LED status for position,uplink and downlink
var Firmware = 160+(bytes[10] & 0x1f); // Firmware version; 5 bits
var roll=(bytes[11]<<8 | bytes[12])/100;//roll,units: °
var pitch=(bytes[13]<<8 | bytes[14])/100; //pitch,units: °
var hdop = 0;
if(bytes[15] > 0)
{
hdop =bytes[15]/100; //hdop,units: °
}
else
{
hdop =bytes[15];
}
var altitude =(bytes[16]<<8 | bytes[17]) / 100; //Altitude,units: °
return {
Latitude: latitude,
Longitude: longitude,
Roll: roll,
Pitch:pitch,
BatV:batV,
ALARM_status:alarm,
MD:motion_mode,
LON:led_updown,
FW:Firmware,
HDOP:hdop,
Altitude:altitude,
};
}
This is the migrated formatter. I kept it as much as possible identical.
function decodeUplink(input) {
var bytes;
bytes = input.bytes;
var port;
port = input.fport;
var latitude;//gps latitude,units: °
latitude=(bytes[0]<<24 | bytes[1]<<16 | bytes[2]<<8 | bytes[3])/1000000;//gps latitude,units: °
var longitude;
longitude=(bytes[4]<<24 | bytes[5]<<16 | bytes[6]<<8 | bytes[7])/1000000;//gps longitude,units: °
var alarm=(bytes[8] & 0x40)?"TRUE":"FALSE";//Alarm status
var batV=(((bytes[8] & 0x3f) <<8) | bytes[9])/1000;//Battery,units:V
if((bytes[10] & 0xC0)==0x40)
{
var motion_mode="Move";
}
else if((bytes[10] & 0xC0) ==0x80)
{
motion_mode="Collide";
}
else if((bytes[10] & 0xC0) ==0xC0)
{
motion_mode="User";
}
else
{
motion_mode="Disable";
} //mode of motion
var led_updown=(bytes[10] & 0x20)?"ON":"OFF";//LED status for position,uplink and downlink
var Firmware = 160+(bytes[10] & 0x1f); // Firmware version; 5 bits
var roll=(bytes[11]<<8 | bytes[12])/100;//roll,units: °
var pitch=(bytes[13]<<8 | bytes[14])/100; //pitch,units: °
var hdop = 0;
if(bytes[15] > 0)
{
hdop =bytes[15]/100; //hdop,units: °
}
else
{
hdop =bytes[15];
}
var altitude =(bytes[16]<<8 | bytes[17]) / 100; //Altitude,units: °
return {
data: {
Latitude: latitude,
Longitude: longitude,
Roll: roll,
Pitch:pitch,
BatV:batV,
ALARM_status:alarm,
MD:motion_mode,
LON:led_updown,
FW:Firmware,
HDOP:hdop,
Altitude:altitude
},
warnings: [],
errors: []
};
}
If the payload is
02D4D6C000807E9C0F4164
the v2 result is:
{
"ALARM_status": "FALSE",
"Altitude": 0,
"BatV": 3.905,
"FW": 164,
"LON": "ON",
"Latitude": 47.50304,
"Longitude": 8.42102,
"MD": "Move",
"Pitch": 0,
"Roll": 0
}
In V3 I get for the same payload:
"decoded_payload": {
"ALARM_status": "FALSE",
"BatV": 3.905,
"FW": 164,
"LON": "ON",
"MD": "Disable",
"Pitch": 0,
"Roll": 0,
"altitude": 0,
"hdop": null,
"latitude": 47.50304,
"longitude": 0
},
Any idea?