Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X
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?
Solved! Go to Solution.
Instead of creating a new stream from scratch, I have an existing prototype stream that I clone.
var streamName = nodeName+"Stream";
try
{
Resources.EntityServices.CloneThing({
sourceThingName : "_Prototype_NodeDataStream",
name : streamName
});
var thing = Things[streamName];
thing.EnableThing();
thing.RestartThing();
}
catch (error)
{
logger.error("Unabled to create stream: "+streamName);
}
Instead of creating a new stream from scratch, I have an existing prototype stream that I clone.
var streamName = nodeName+"Stream";
try
{
Resources.EntityServices.CloneThing({
sourceThingName : "_Prototype_NodeDataStream",
name : streamName
});
var thing = Things[streamName];
thing.EnableThing();
thing.RestartThing();
}
catch (error)
{
logger.error("Unabled to create stream: "+streamName);
}
That solved it! Thanks!
Good answer, but what was wrong with the original javascript code? This seems to work as long as the Template and DataShape names are valid.
Since the data shape is set after the creation of the stream, that code gave me the error message every time it was ran. But you are right that it was working otherwise fine.