Converting MQTT location to GEOFENCE GPS

Hi

My understanding of Java is quite low, however, I would like some help writing a function.

My mqtt device tracker gives this payload:

12/10/2018, 11:47:33 AM[node: 978c90cb.73b7]
zanzito/shared_locations/my_cell : msg.payload : string[148]
{"battery_level":83,"longitude":143.5514104,"latitude":252122.447,"altitude":47.70000076293945,"gps_accuracy":22,"user":"my_cell","tst":1544406310}

I would like to extract the longitude and latitude and rename it to one of these 3 formats

msg.location.lat & msg.location.lon
msg.lat & msg.lon
msg.payload.lat & msg.payload.lon

Thanks in advance.

So what have you tried so far?

I may have just worked it out, not by using a function, however.

This was my function.

msg = {
location:{
lat:msg.data.latitude,
lon:msg.data.longitude
},
}
return msg;

That did not work.

I then used the following nodes:

  • JSON node to convert the string
  • Change node with the following rules
    • Set location.lat -> payload.latitude
    • Set location.lon -> payload.longitude

I am sure this could be written as a function, but it works.

The function now will be a mental exercise.

1 Like