DependableSystemsLab / ThingsJS

ThingsJS is a framework for running JavaScript applications on IoT devices such as Raspberry PIs. For more details, see below:
http://thingsjs.io
MIT License
16 stars 5 forks source link

Exporting the list of "output topics" for components (metadata) #21

Closed juliengs closed 6 years ago

juliengs commented 6 years ago

In order to make the dashboard more generic (i.e., so that output can be shown, for any component), we need a mechanism by which components can "announce" their relevant "output topics", and the type of contents that they publish. This should be done through the metadata.

Example: for the video streamer, one output topic could be defined: the video stream, the type of contents would be "PNG" images. For the motion detector, two output topics could be defined: the motion-video stream (PNG images type) and whether motion is detected (perhaps JSON or text output).

Common output types could be: PNG (sequence of PNG images -- can emulate a video stream), text, JSON, CSV (all text-based formats would all be displayed in a text-like format, for the moment) etc. Eventually we could add support for real video streams (more efficient than PNG sequences), audio, etc.

juliengs commented 6 years ago

@jungkumseok Do you know how we could add this to the metadata (do you have a sample JS file that shows how to declare metadata?)?

jungkumseok commented 6 years ago

Yes, this feature was added in this commit: 7060821e1335eaee896180eb6ff659775132a00f

One would provide metadata by writing a special block-comment at the top of the code. The block-comment must begin with /*things.meta and close on a new line with */. Inside the body of the block-comment, the user must provide metadata in valid YAML (significant white-space). Right now there is no schema for the metadata, so the user has total freedom over what information to include as metadata. The YAML data will simply be converted into a JSON object and will be available upon running the component.

See example below:

/*things.meta
outputs:
  things-js/motion-stream: video/mpeg
  things-js/alarm: text/plain
constraints:
  dynamic:
    - cpuUsage
    - memoryUsage
*/
var count = 0;
setInterval(function(){
    count ++;
}, 1000);

Here the metadata will be converted into the following JSON:

{
    "outputs": {
        "things-js/motion-stream": "video/mpeg",
        "things-js/alarm": "text/plain"
    },
    "constraints": {
        "dynamic": [ "cpuUsage", "memoryUsage" ]
    }
}

In the front-end (Dashboard), this object will be available as a property of the Program object - i.e. program.meta.extra.