Skip to main content
1-Visitor
July 4, 2016
Question

Remote thing created using Java Edge SDK always shows as not connected

  • July 4, 2016
  • 2 replies
  • 3400 views

Hi,

I am trying to create and bind remote thing using java edge sdk. Following is an essential part of the code:

...

params = new ValueCollection();
params.SetStringValue("name", "MyThing");
params.SetStringValue("thingTemplateName", "RemoteThing");
client.invokeService(ThingworxEntityTypes.Resources, "EntityServices", "CreateThing", params,
0);

    client.invokeService(ThingworxEntityTypes.Things, "MyThing", "EnableThing",        params, 0);

client.invokeService(ThingworxEntityTypes.Things, "MyThing", "RestartThing",
params, 0);

params = new ValueCollection();
params.SetStringValue("name", "HelloService");
params.SetBooleanValue("remote", true);
params.SetStringValue("remoteServiceName", "HelloService");
client.invokeService(ThingworxEntityTypes.Things, "MyThing",
"AddServiceDefinition", params, 0);
       VrtualThing thing =
new MyThing("MyThing", "", "MyThing", client);
  client.bindThing(thing);
  client.start();

.......

MyThing class exists and extends VirtualThing.

I can see my thing created and HelloService added to it, however its isConnected property is always false and "lastConnection" date is set to Jan 1, 1970. If I try to invoke HelloService I get "Unable to Invoke Service HelloService on MyThing : No service handler defined for service HelloService on thing [MyThing]".

What am I missing?

Thanks,

Michael

2 replies

1-Visitor
July 5, 2016

Hi

It's unclear as to whether the code you have posted is from the platform or the edge. To me it looks like platform code, but I may be wrong... Can you explain the reason behind why you are trying to write the code in this way?

Is your Edge "device" showing up in the Unbound Remote Things page in composer? If it is, it should auto-bind as long as the name of your Edge Thing is the same as your ThingName on the platform.

Regards

Ian

mkreinin1-VisitorAuthor
1-Visitor
July 5, 2016

We have a server that has to connect to ThingWorx server and expose some parts of its data model as remote things - to be further used in mashup. The above code is executed on our server. I omitted the initialization part in my original post, here it is:

ClientConfigurator configurator = new ClientConfigurator();    

configurator.setUri("ws://localhost:8080/Thingworx/WS");   

SecurityClaims sc = SecurityClaims.fromCredentials("aaa", "bbb");   

configurator.setSecurityClaims(sc);   

configurator.setReconnectInterval(15);   

configurator.setAsSDKType();   

configurator.setName("MyServer");   

try {     

client = new ConnectedThingClient(configurator);     

client.connect();     

client.checkConnection();

......

Looking at remote things, MyServer shows up as connected "SDKGateway" thing with green icon while MyThing shows with red icon as unbound.

5-Regular Member
July 5, 2016

Michael, as Ian mentioned the Thing from the Unbound state will auto bind if you have a thing existing in the platform with the exact name, which in your case would be "MyThing"

Have you tried creating a Thing with that exact name?

5-Regular Member
July 6, 2016

Michael, by platform i meant the thingworx server. Concerning your next question there is a documentation and a sample available on working directly with the Services, not sure if you have already seen this. This code sample is from the Edge side, not sure if you have already gone through this :

@ThingworxServiceDefinition(name = "AddNumbers", description = "Add Two Numbers")
@ThingworxServiceResult(name = CommonPropertyNames.PROP_RESULT, description = "Result", baseType = "NUMBER")
public Double AddNumbers(@ThingworxServiceParameter(name = "a", description = "Value 1", baseType = "NUMBER") Double a, @ThingworxServiceParameter(name = "b", description = "Value 2", baseType = "NUMBER") Double b)throws Exception {
return a + b;
}

You can find more samples in the Java SDK samples and is covered under the documentation ThingWorx Java SDK Developer's Guide (which is part of the Java SDK)