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

Create n things, remote things and bind properties by code

fmanniti
9-Granite

Create n things, remote things and bind properties by code

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?

1 ACCEPTED SOLUTION

Accepted Solutions

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({...});

View solution in original post

8 REPLIES 8

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.

Top Tags