Source: sensor

Sensor does not accept incoming signals, it watches the external world and send signals to your system. It is the signal source.

Signature

NS.sensor(comment : string, inputs : map, outputs : map, watch : function) : Node

Arguments

Arguement Type Description
comment string optional, the comment of the sensor
inputs map optional, the input description
outputs map optional, the output description
watch function the watch function

Return

Type Description
Node the sensor node

Create a sensor

const ns = collar.ns('collarjs.demo.sensor');
const sensor = ns.sensor(function(options) {
  setTimeout(() => {
    this.send({
      event : "timeout",
      delay : 10000
    })
  }, 10000);
});

// sensor starts to watch when it is created

Create a sensor with options

const sensor = ns.sensor(function(options) {
  var delay = 10000; // default delay
  if (options.delay)
    delay = options.delay;  // use delay in options
  else
    return; // if no delay defined, watch nothing

  setTimeout(() => {
    this.send({
      event : "timeout",
      delay : delay
    })
  }, delay);
});

sensor.watch({delay : 5000}); // start watch with options

results matching ""

    No results matching ""