If you are having to do the comparison and subtraction doesn't that just mean the value is sint32 not uint32? Or am I missing something?
I have pasted hexadecimal payload from my gateway's nw server into in thingpark api to check
to see the latitude and longitude coordinates
response_1605178950283.json (831 Bytes)
No @steve i am not 100% sure thats why i have referred the manual which is attached above.
{"applicationID":"1","applicationName":"cloud","data":"A0hkiAAMEOw9Ld8nBPZ5wQ==","devEUI":"20635f01d1000002","deviceName":"abeeway tracker","fCnt":11,"fPort":18,"rxInfo":[{"altitude":0,"latitude":0,"loRaSNR":10,"longitude":0,"mac":"24e124fffef0a78e","name":"24e124fffef0a78e","rssi":-59,"time":"2020-11-12T10:27:16.413008Z"}],"time":"2020-11-12T10:27:16.413008Z","txInfo":{"adr":true,"codeRate":"4/5","dataRate":{"bandwidth":125,"modulation":"LORA","spreadFactor":7},"frequency":865402500}}
Try this instead...
//combine bytes manually
var lat = (msg.payload.lat[0] << 24) + (msg.payload.lat[1] << 16) + (msg.payload.lat[2] << 8)
var lon = (msg.payload.lon[0] << 24) + (msg.payload.lon[1] << 16) + (msg.payload.lon[2] << 8)
if (lat > 0x7FFFFFFF) {
lat -= 0x100000000;
}
if (lon > 0x7FFFFFFF) {
lon -= 0x100000000;
}
lat /= 10000000;
lon /= 10000000;
msg.payload.latitude = lat;
msg.payload.longitude = lon;
return msg;
[{"id":"ec72da90.ce7808","type":"inject","z":"ac69cd26.4f506","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[3,72,94,140,0,12,16,236,55,45,223,38,4,245,106,62]","payloadType":"bin","x":350,"y":820,"wires":[["118cfc21.5bdf74"]]},{"id":"118cfc21.5bdf74","type":"buffer-parser","z":"ac69cd26.4f506","name":"Bulid Tags","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"byte","name":"lat","offset":6,"length":3,"offsetbit":0,"scale":1,"mask":""},{"type":"byte","name":"lon","offset":9,"length":3,"offsetbit":0,"scale":1,"mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"setTopic":true,"x":550,"y":820,"wires":[["30ec8af.4eae476"]]},{"id":"30ec8af.4eae476","type":"function","z":"ac69cd26.4f506","name":"","func":"var lat = (msg.payload.lat[0] << 24) + (msg.payload.lat[1] << 16) + (msg.payload.lat[2] << 8) \nvar lon = (msg.payload.lon[0] << 24) + (msg.payload.lon[1] << 16) + (msg.payload.lon[2] << 8) \n\nif (lat > 0x7FFFFFFF) { // 0x7FFFFFFF not 0x7FFFFFF\n lat -= 0x100000000;\n}\n// else << DONT DO IF ELSE HERE!\nif (lon > 0x7FFFFFFF) { // 0x7FFFFFFF not 0x7FFFFFF\n lon -= 0x100000000;\n}\n\nlat /= 10000000; //outside of the IF\nlon /= 10000000; //outside of the IF \n\nmsg.payload.latitude = lat;\nmsg.payload.longitude = lon;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":740,"y":820,"wires":[["e17a639a.c6e5"]]},{"id":"e17a639a.c6e5","type":"debug","z":"ac69cd26.4f506","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":820,"wires":[]}]
Thanks @steve works great,
calculated manually also getting exact results
2^24 * 16 +2^16 * 236 +2^8 * 55=268,435,456+15,466,496+14,080=283,916,032/10000000=28.3916032
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.