Extracting lat and long coordinates from payload

Payload
{"applicationID":"1","applicationName":"cloud","data":[3,72,94,140,0,12,16,236,55,45,223,38,4,245,106,62],"devEUI":"20635f01d1000002","deviceName":"abeeway tracker","fCnt":588,"fPort":18,"rxInfo":[{"altitude":0,"latitude":0,"loRaSNR":9.8,"longitude":0,"mac":"24e124fffef0a78e","name":"24e124fffef0a78e","rssi":-59,"time":"2020-11-12T07:01:22.759152Z"}],"time":"2020-11-12T07:01:22.759152Z","txInfo":{"adr":true,"codeRate":"4/5","dataRate":{"bandwidth":125,"modulation":"LORA","spreadFactor":7},"frequency":865402500}}

[{"id":"506b83c1.56ee6c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"57373220.09238c","type":"mqtt in","z":"506b83c1.56ee6c","name":"","topic":"bachloo.rahul@gmail.com/test","qos":"0","datatype":"json","broker":"55bef158.86a7c","x":210,"y":80,"wires":[["8606fe2a.c2499"]]},{"id":"d5396d84.2231e","type":"debug","z":"506b83c1.56ee6c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":140,"wires":[]},{"id":"8606fe2a.c2499","type":"base64","z":"506b83c1.56ee6c","name":"","action":"","property":"payload.data","x":343,"y":167,"wires":[["d5396d84.2231e","449795b6.55bf6c"]]},{"id":"449795b6.55bf6c","type":"buffer-parser","z":"506b83c1.56ee6c","name":"","data":"payload.data","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":1,"mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"setTopic":true,"x":420,"y":260,"wires":[[]]},{"id":"55bef158.86a7c","type":"mqtt-broker","name":"","broker":"maqiatto.com","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]




How to use buffer parser node for parsing the data attribute?

  • Add the 2 entries in the buffer parser with offset set to match your data (I assume offset 6 for the Lat & and offset 9 for the Lon).
  • Set these two items to Uint16BE or Uint16LE (depending on your data source)
  • Set a mask of 0XFFF0 for both of them
  • Add a function after the parser to do the MATH

Ii notice that the spec you provide show 16 bytes - but that you are receiving two packets - one of 16 bytes (OK) and one of 42 bytes... Are the first 16 bytes the same fields or something completely different ? You need to tell them apart before trying to decode them.

I have this manual i think it should be given in manual Abeeway_Tracker_Reference_Guide_FW2_0.pdf (1.5 MB)

Close. Set the mask as described and add a debug node to see whats coming out of the parser.

Also, add a function after the parser and do the maths as described & a debug after the function node to see if your math is good.

Good spot.

@bachloo.rahul As Dave said, which one of those 2 packets are the one containing your Lat/Lon data? You will need to identify which one of those 2 are providing the data you want otherwise it will fail 50% of the time. Looking at your screenshots, we can assume the 16 byte packet is the correct one.



check to see if code is correct in function node?

Does it work (It won't!)

As I said earlier in my screenshot, you don't need to do the bit shift because you took 4 bytes when asking for UINT32 & so the value was already shifted. I sometimes wonder why I bother to explain stuff.

Byte   6  7  8  9
Mask   F  F  F  0

The value is already shifted to MSB

As for return - you cannot return values like that. This is node-red basics.

Change last part of function

msg.payload.latittude = lat;
msg.payload.longitude = lon;
return msg;


There is some error

Check your spelling. payload vs paylaod.

yes :sweat_smile: very silly mistake


it is returning the same values in debug window as both the if and else if conditions does not meet.

Because your / 10000000 is inside the if and the value is < 0x7fffffff

read the screenshot you first posted.

yes that means the code in function is working perfectly fine as per the screenchot?

no, obviously not!

Take the / 10000000 out of the if

If you posted actual function code instead of screenshots I might feel compelled to give you the fix, as it stands, I am not going to read from a screenshot & re-type your code.

var lat=msg.payload.lat;
var lon=msg.payload.lon;

if (lat>0X7FFFFFF){
    lat-=0x100000000;
}
else if (lon>0x7FFFFFF){
    lon-=0x100000000;
}
msg.payload.latitude = lat;
msg.payload.longitude = lon;
return msg;

sorry was in a bit hurry ,i have removed both /1000000

Hi, in order to make code more readable and importable it is important to surround your code with three backticks
```
like this
```

You can edit and correct your post by clicking the pencil icon.

See this post for more details - How to share code or flow json

That is not what I meant. I meant move it outside of the if



This should be closer...

var lat = msg.payload.lat;
var lon = msg.payload.lon;

if (lat > 0x7FFFFFFF) { //  0x7FFFFFFF not 0x7FFFFFF
  lat -= 0x100000000;
}
// else  << DONT DO IF ELSE HERE!
if (lon > 0x7FFFFFFF) {  //  0x7FFFFFFF not 0x7FFFFFF
  lon -= 0x100000000;
}

lat /= 10000000; //outside of the IF
lon /= 10000000; //outside of the IF 

msg.payload.latitude = lat;
msg.payload.longitude = lon;
return msg;


this is the output but coordinates are not correct as i know it should be around 28 and 76.

3 things...

  1. Re-read my code & correct yours.
  2. Are you 100% certain the data going in to the parser has LAT at byte 6 and LON at byte 9?
  3. Are you 100% certain the data going in to the parser is Big Endian (BE). What happens if you use LE types in the buffer parser.

EDIT...
It might be you actually DO need to shift << 8 - give that a go too. Personally, I think your data might be byte swapped.