Skip to main content
1-Visitor
August 4, 2020
Solved

Java SDK Tutorial Creating a property and/or writing values to it

  • August 4, 2020
  • 5 replies
  • 1804 views

I have recently been doing some things in the Java SDK tutorial and I have gotten to a point where I can connect to the thingWorx hosted trial server, create a remoteThing, and bind it to a Thing that has been created in ThingWorx with the same name. What I am trying to do now is either..

A) add a property via Java code and then add values to it, this way I can update these every n seconds.

or

B) Simply add values to a property created in ThingWorx already.

For some reason when I use this code....

 

// Writing a property
///////////////////////////////////////////////////////////////

LocationPrimitive location = new LocationPrimitive(42.36, -71.06, 10.0);

// This will set the CurrentLocation property of the Thing to the GPS
// coordinates of Boston, MA.
client.writeProperty(ThingworxEntityTypes.Things, thingName, "CurrentLocation",
location, 5000);

 

I get this error...

 

com.thingworx.common.exceptions.GenericHTTPException: Entity TunnelExample does not exist or is not yet associated with a Thing

 

I am not sure how I am getting this error because if I remove the code above, everything connects fine in Java and ThingWorx. I made sure the code was executing after connecting so I am unsure why it says. Any help would be greatly appreciated as it will probably solve a number of other issues I will run into when doing this for services, events, etc...

Best answer by justinoberle

I finally got this to work. The tutorials are a bit confusing and on top of that I had some corruption in my project configuration in Eclipse. Basically, if you have this issue, start over from scratch and use the correct import. There are 2 imports and the tutorial only shows one. I loaded both to src dir and it is working now. Also, MAKE SURE TO IMPORT THE XML INTO THINGWORX. This was the main reason mine was failing because I tried to make everything from scratch. Use the default user's app key and everything should work fine.

5 replies

Support
August 5, 2020

Hi @justinoberle.

 

Could you please provide a link to the tutorial you're using?

 

Regards.

 

--Sharon

1-Visitor
August 5, 2020

It is one of the example java scripts in the "java SDK tutorial". It is not directly part of this tutorial but the script is included.

1-Visitor
August 5, 2020

The code looks like this...

 

//
// Writing a property
///////////////////////////////////////////////////////////////
LocationPrimitive location = new LocationPrimitive(42.36, -71.06, 10.0);
// This code sets the CurrentLocation property of the Thing to the GPS
// coordinates of Boston, MA.
client.writeProperty(ThingworxEntityTypes.Things, ThingName, "CurrentLocation",
location, 5000);
LOG.info("Wrote to the property 'CurrentLocation' of Thing {}. value: {}",
ThingName, location.toString());