Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
Is it possible (and, if so, how) to create things and remote things by code?
I have thing template "SimulationTemplate" which has 3 properties: Prop1, Prop2, Prop3
I want 25 things called "Simulation-TH_1"... "Simulation-TH_25" and 25 remote things "Simulation-RT_1"..."Simulation-RT_25" and I want the properties to be bind.
How can I do this by code instead of doing it one by one?
Solved! Go to Solution.
Yes it's possible.
To create things:
Resources["EntityServices"].CreateThing({ name:, description:, thingTemplateName:,tags:});
To Bind remote properties:
me.SetRemotePropertyBinding({...});
To Bind local properties:
me.SetLocalPropertyBinding({...});
Yes it's possible.
To create things:
Resources["EntityServices"].CreateThing({ name:, description:, thingTemplateName:,tags:});
To Bind remote properties:
me.SetRemotePropertyBinding({...});
To Bind local properties:
me.SetLocalPropertyBinding({...});
Thank you.
And what about for duplicate?
If I want to duplicate 50 times my Thing called TH1 to "TH2"..."TH50" is it possible to do it by code?
Because I've seen CloneThings but it doesn't seem to work
For this, CloneThing should do the trick, but I never used it ( I don't like Copy&Paste when programing )
I am actually trying it but it doesn't seem to work
I'm creating a thing called DS-TH_prova and a Remote thing called DS-RemTH_prova. I want to bind remotething's property PropNum_4 to things property Temperature.
That's my code
var thingName = "DS-TH_prova";
var remThingName = "DS-RemTH_prova";
var paramsTH = {
name: thingName,
thingTemplateName: 'DeviceSimulatorTemplate',
};
Resources["EntityServices"].CreateThing(paramsTH);
var paramsRemTH = {
name: remThingName,
thingTemplateName: 'DeviceSimulatorRemoteTemplate',
};
Resources["EntityServices"].CreateThing(paramsRemTH);
var props = {
propertyName: "PropNum_4",
sourceThingName: thingName,
sourcePropertyName: "Temperature"
};
Things[remThingName].SetLocalPropertyBinding(props);
This will create the two things but not the binding.
Hi Fabio,
When you say that it doesn't works, what you mean?
Carles.
It means that the code I wrote will create a Thing and a Remote thing but it doesn't bind the properties
Hi Fabio,
I can't see what's wrong, if the referenced properties on SetLocalPropertyBinding did exist, did you looked at Logs to see if there's any error?
I am guessing that you want the properties from remote thing to reflect into thing, if that is the case, I think the source should be the remote thing in the last step.
...
var props = {
propertyName: "Temperature",
sourceThingName: remThingName,
sourcePropertyName: "PropNum_4"
};
Things[thingName].SetLocalPropertyBinding(props);
Hope this helps.