Skip to main content
14-Alexandrite
June 4, 2018
Solved

Updating a Location type property over MQTT

  • June 4, 2018
  • 8 replies
  • 3219 views

Good day,

 

I am trying to update a location property using MQTT. I am able to update a json property using MQTT with the message body looking like this:

 

{"latitude":-25.82,"longitude":28.176,"elevation":0,"units":"WGS84"}

 

I get the error message: [Unable To Convert From java.lang.String to LOCATION]. When I create a subscription on data change of the json property that looks like this it works:

 

me.Location = me.JSONLocation; 

 

The location property updates correctly, which I am assuming means my format is correct.

 

Has anybody been able to update a location property using MQTT? It seems like it is not supported in the MQTT extension.

 

Thank you,

Johan Bester

Best answer by raluca_edu

Hi Johan,

 

Try to send the MQTT message in the following format: "-25.82,28.176,-10" (not JSON format)  to the Location property from Thingworx.

 

Thank you,

Raluca Edu

8 replies

22-Sapphire I
June 5, 2018

Since MQTT is text and Location is a Location Object, I think you will need to parse the location information and create the location object to assign to the property.

jbester14-AlexandriteAuthor
14-Alexandrite
June 5, 2018

Hi @PaiChung,

 

Thank you for the reply.

 

As I understand it the Location property is just a json type property with a specific format right? It makes sense that the parsing is the issue, but other property types do not have an issue to be parsed. Is the issue then on the location type property in Thingworx core that does not parse the string to json correctly except if you do it through a service? 

 

At the moment I am using the workaround, but I would prefer to not have the unnecessary properties if it can be avoided.

 

1-Visitor
June 5, 2018

Maybe you are missing:

 

me.Location = JSON.parse(yourMQTTLocationValue); 

raluca_edu
17-Peridot
June 7, 2018

Hi Johan,

 

Try to send the MQTT message in the following format: "-25.82,28.176,-10" (not JSON format)  to the Location property from Thingworx.

 

Thank you,

Raluca Edu