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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Remote Binding Example

vieirac1
9-Granite

Remote Binding Example

Team,

Our customer would like to create a service on the thing template that would allow them to create a thing and also do a remote binding to a kepware device,
Please, any code example that we can use for that thing creation and remote binding?

Tks
Chris
1 ACCEPTED SOLUTION

Accepted Solutions
amittal-3
13-Aquamarine
(To:vieirac1)

Hi,

What you are trying to achieve, I hope you have tried it using manual steps.

So in that case you just need a way to do that programatically, it could be a tricky process, but to answer your question in a precise manner it would need a little more understanding of your model.

However at this point I can point you to some services which you can try, evaluate and then build your own code using it.

1) For dynamically creating a thing you can use - 

var params = {
    name: "MyThing" /* STRING */,
    description: "Thing Description" /* STRING */,
    thingTemplateName: "generic" /* THINGTEMPLATENAME */,
    tags: <tags> /* TAGS */
};
// no return
try
{
    Resources["EntityServices"].CreateThing(params);
    Things["MyThing"].EnableThing();
    Things["MyThing"].RestartThing();
}
catch(err)
{
    logger.debug("Unable to create thing; err: " + String(err));
    Resources["EntityServices"].DeleteThing({name: "MyThing"});
}

2) For Remote binding use the service "SetRemotePropertyBinding" which is available in GenericThing template

You can also refer to 

https://community.ptc.com/t5/ThingWorx-Developers/Binding-KEPServer-Tags-to-Thing-Properties/m-p/573080#M31158 

Hope it helps.

Regards

Aditya

View solution in original post

1 REPLY 1
amittal-3
13-Aquamarine
(To:vieirac1)

Hi,

What you are trying to achieve, I hope you have tried it using manual steps.

So in that case you just need a way to do that programatically, it could be a tricky process, but to answer your question in a precise manner it would need a little more understanding of your model.

However at this point I can point you to some services which you can try, evaluate and then build your own code using it.

1) For dynamically creating a thing you can use - 

var params = {
    name: "MyThing" /* STRING */,
    description: "Thing Description" /* STRING */,
    thingTemplateName: "generic" /* THINGTEMPLATENAME */,
    tags: <tags> /* TAGS */
};
// no return
try
{
    Resources["EntityServices"].CreateThing(params);
    Things["MyThing"].EnableThing();
    Things["MyThing"].RestartThing();
}
catch(err)
{
    logger.debug("Unable to create thing; err: " + String(err));
    Resources["EntityServices"].DeleteThing({name: "MyThing"});
}

2) For Remote binding use the service "SetRemotePropertyBinding" which is available in GenericThing template

You can also refer to 

https://community.ptc.com/t5/ThingWorx-Developers/Binding-KEPServer-Tags-to-Thing-Properties/m-p/573080#M31158 

Hope it helps.

Regards

Aditya

Top Tags