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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Remote Property Detection

pbaierl
1-Newbie

Remote Property Detection

Is there a way to pragmatically detect the parameters of a remote thing?

We allow the users to create/configure things using a database.  Parameters can be added or removed by users during the initial development.

I saw a post on how to create and add remote bindings using the scripting.  However, I would like to know how to create the bindings if I don't know the names of the all the properties.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi,

About using GetRemoteMetadata, here you have a sample code which I use to process it:

var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({

  infoTableName : "InfoTable",

  dataShapeName : "wupRemotePropertyDefinitionTS"

});

var isRemote = me.ImplementsShape({ thingShapeName: "Connectable" });

var isConnected = false;

var remoteProperties = [];

var ignore;

if (nameLike) nameLike = nameLike.toLowerCase(); // -- nameLike it's a parameter to filter properties by this name

if (isRemote) {

    isConnected = me.isConnected;

    if (isConnected) {       

        var metadata = me.GetRemoteMetadata()

    

        if (metadata) {

            var propertyDefinitions = metadata.propertyDefinitions;

            for (var property in propertyDefinitions) {

                if (propertyDefinitions.hasOwnProperty(property)) {

                    ignore = false;

                    if (nameLike) {

                        ignore = (property.toLowerCase().indexOf(nameLike)==-1);

                    }

                    if (remotePropertyName) {

                        ignore = (property!==remotePropertyName);

                    }

                    if (!ignore) {

                        result.AddRow({

                            name: property,

                            baseType: propertyDefinitions[property].baseType,

                            description: propertyDefinitions[property].description,

                            aspects: propertyDefinitions[property].aspects

                          });

                    }

                }

            }

        }

    }

}

View solution in original post

5 REPLIES 5
mhollenbach
5-Regular Member
(To:pbaierl)

Paul,

There is a service on a RemoteThing template in Composer that is called GetRemoteMetadata. This service is exercised whenever you click the "Manage Bindings" button on the Properties page. You should wrap this service in a custom service, parse the JSON that comes back to see what properties are available on the device, and then add your remote bindings from those values.

If you need an example of how to do this I can probably put something together, just let me know.

Meghan

Hi,

About using GetRemoteMetadata, here you have a sample code which I use to process it:

var result = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({

  infoTableName : "InfoTable",

  dataShapeName : "wupRemotePropertyDefinitionTS"

});

var isRemote = me.ImplementsShape({ thingShapeName: "Connectable" });

var isConnected = false;

var remoteProperties = [];

var ignore;

if (nameLike) nameLike = nameLike.toLowerCase(); // -- nameLike it's a parameter to filter properties by this name

if (isRemote) {

    isConnected = me.isConnected;

    if (isConnected) {       

        var metadata = me.GetRemoteMetadata()

    

        if (metadata) {

            var propertyDefinitions = metadata.propertyDefinitions;

            for (var property in propertyDefinitions) {

                if (propertyDefinitions.hasOwnProperty(property)) {

                    ignore = false;

                    if (nameLike) {

                        ignore = (property.toLowerCase().indexOf(nameLike)==-1);

                    }

                    if (remotePropertyName) {

                        ignore = (property!==remotePropertyName);

                    }

                    if (!ignore) {

                        result.AddRow({

                            name: property,

                            baseType: propertyDefinitions[property].baseType,

                            description: propertyDefinitions[property].description,

                            aspects: propertyDefinitions[property].aspects

                          });

                    }

                }

            }

        }

    }

}

Meghan,

Thanks for getting back to me on this.  I would really appreciate it if you could please post or send me an example on how to do this.

Thanks

Paul

Hi Paul, we crossed answers my post covers it

Thanks Carles!  I will try your example code and see if I can get it to work!

Top Tags