4 Replies Latest reply on Apr 20, 2016 3:13 AM by hpulkkinen RSS
    hpulkkinen Explorer

    Creating a steam programatically

    I have been creating new stream with the following service:

     

    // Example: For Node1 the stream will be named Node1Stream

    var streamName = nodeName + "Stream";

     

    var newStreamParams = {

        name: streamName,

        description: undefined,

        thingTemplateName: "NodeStreamTemplate",

        tags: undefined

    };

     

    var dataShapeParams = {

        name: "NodeDataShape" /* DATASHAPENAME */

    };

     

     

    try{

        // Create new Stream

        Resources["EntityServices"].CreateThing(newStreamParams);

      

        // Set datashape

        Things[streamName].SetDataShape(dataShapeParams);

     

     

        Things[streamName].EnableThing();

        Things[streamName].RestartThing();

    }

    catch(e){

        logger.error("Unable to create Thing:" + streamName);

        var params = {

            name: streamName

        };

        Resources["EntityServices"].DeleteThing(params);

    }

     

    This seems to work fine, but it gives an error to the log:

     

     

    2016-01-28 10:14:36

     

     

     

    ERROR

     

    Invalid DataShape [] assigned to stream Node1Stream

     

     

    <my email>

     

     

    c.t.s.StreamThing

     

     

    Is there a better way to do this and avoid the error message? Is it possible to define the data shape directly when the new stream thing is created?