cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Updating a Location type property over MQTT

SOLVED
Amethyst

Updating a Location type property over MQTT

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

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Updating a Location type property over MQTT

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 8

Re: Updating a Location type property over MQTT

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.

Re: Updating a Location type property over MQTT

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.

 

Re: Updating a Location type property over MQTT

Maybe you are missing:

 

me.Location = JSON.parse(yourMQTTLocationValue); 

Re: Updating a Location type property over MQTT

Hi Carles,

The parse is not required in the service to work. The location property updates correctly in the way I suggested it in my original question. It is however not possible to do it directly using MQTT. So I am assuming the correct parsing does not happen from string to json if you do not do it through a service inside Thingworx or a REST call where you define the message body as json.

Re: Updating a Location type property over MQTT

I don't get the point where you are updating it, but for the error you are getting it points out to the solution I've mentioned and you need an explicit JSON parse as written.

Re: Updating a Location type property over MQTT

Hi Carles,

 

That might be one reason in a different circumstance that the error message can occur. It is not the case in this scenario and the misconception is probably my fault because maybe I did not provide all of the necessary information. 

 

My scenario:

I have an edge device using MQTT to publish information. My Thingworx "Thing" with a MQTT template using automapping subscription on the topics receives the information. One of the properties it receives is a location json in the following format: {"latitude":-25.82,"longitude":28.176,"elevation":0,"units":"WGS84"}.

 

When the location value is received from the subscribe on the topic I receive the following error message: [Unable To Convert From java.lang.String to LOCATION]. Which as you mentioned is because of a parsing error.

 

Workaround:

I create a json property that subscribes on the location from the edge device. I then run a data change subscription that is only: me.Location = me.JSONLocation;

 

This works (without explicitly parsing it) without an error an error message.

 

The problem: 

The format of the json is not the problem I am assuming because it is the same format I use for updating using REST calls in a different project and because the service takes the format as is.

It does however then point to the parsing issue where the json message is published as string over MQTT and then the location property does not automatically parse it to json as with the other property types (string to integer, number, json or datetime). 

 

My question if the assumptions above are correct:

Is the issue in the Thingworx core in how location properties are updated. Is the issue in the MQTT extension and if there is a way to solve it without a workaround of additional properties. 

 

I have opened a support case with PTC, but I appreciate the input that I could better understand the issue.

 

Re: Updating a Location type property over MQTT

Now it's more clear :)

 

Then yes you are right, you have to open a support case ( or you can decompile MQTT extension and see it the error it's there ;) )

Re: Updating a Location type property over MQTT

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