Converting MQTT location to GEOFENCE GPS


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]

I would like to extract the longitude and latitude and rename it to one of these 3 formats & msg.location.lon & msg.lon & 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 = {
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 -> 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