Edge actions - how to return values and "see" the stream

A simple edge action example

function(event) {
  var accelValue = 25;

  return {
    // "cl://accelValue": [ accelValue ] //  --- stream :default {"value":25}
    // "cl://": {                        //  --- Run error: TypeError: wrong type of argument"
    //   key1 : [ 1, 2, 1000],
    //   key2 : [23 ]
    // }
     "cl://john": [{                    //  --- works but I don't know where the data is going
      key1 : [ 1, 2, 1000],
      key2 : [23 ]
    }]
  }

Questions

  • Do I have the event return format correct?
  • where is the doc for the event handler?
  • what do I need to do see the device stream “john” ?

Thanks
John

Ok so I had a think - maybe the payload array can only contain ints, floats and strings
But maybe the server understands JSON in string form

Quick test -

function(event) {
  var obj = { name: "John", age: 30, city: "New York" };
  var myJSON = JSON.stringify(obj);
  console.log(myJSON);
  return {
    "cl://result1" : [myJSON]
  };
}

This seems to be better - device > streams > mydevice > :default I see

14:48:51 13-11-2019
14:48:10 13-11-2019
{"age":30,"city":"New York","name":"John"}
{
  "creationDate": 1573656531579,
  "creatorId": "i000000000000000000000001",
  "elems": {
    "age": 30,
    "city": "New York",
    "name": "John"
  },
  "generatedDate": 1573656490349,
  "hash": null,
  "id": "e5dcc17d31d6bd70a67dea02b",
  "lastEditDate": null,
  "location": null,
  "metadata": null,
  "path": "/iinnovate/devices/john_test_yellow/:default",
  "streamId": "s5db01378b8c3502a9e5c1f35",
  "tags": {
  }
}

Which looks like sensible data to me.

So the next question is how do I stop using :default and use a stream I created?
Should I ask this in a new thread?

PS
note the first time I posted this I missed the “;” of the console.log (too much python lately) the event handler ran twice but then croaked on subsequent calls by the Octave system

For an answer to the :default stream question also see

Hello John,
In the past, you could create a stream on the fly from an edge action. This is not possible anymore due to mess created by folks in development mode. You have to actually create a stream via the UI or via Octave API.

You can then point your edge action to the stream that has been created.

As fyi, streams can be created under the device or under your account. Streams not created under the device, can be seen in UI via the cloud - streams folder in Octave

1 Like