5 Replies Latest reply on Jul 27, 2016 4:01 PM by pbaierl RSS
    pbaierl Creator

    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.

      • Re: Remote Property Detection
        meghan Communicator

        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

          • Re: Remote Property Detection
            carlesc Ninja

            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
                                      });
                                }
                            }
                        }
                    }
                }
             }
            
            • Re: Remote Property Detection
              pbaierl Creator

              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