Skip to main content
1-Visitor
July 27, 2016
Solved

Remote Property Detection

  • July 27, 2016
  • 1 reply
  • 2882 views

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.

Best answer by CarlesColl

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

                          });

                    }

                }

            }

        }

    }

}

1 reply

5-Regular Member
July 27, 2016

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

1-Visitor
July 27, 2016

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

                          });

                    }

                }

            }

        }

    }

}