0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Watson IoT Platform - Node-RED - 閾値によって判断する

Last updated at Posted at 2016-05-22

#閾値によって判断する

  • センサーからの値など、ある値を超えた際にだけ後続の処理を行わせたい場合があります。
  • Node-REDのフローをコピーする方法を参照して、下記のフローをコピペします。
閾値によって判断する
[{"id":"d682710d.e25118","type":"function","z":"ad2e7b14.5fbf","name":"閾値判断","func":"if ( Math.abs(msg.payload) < 3 ) {\n    msg = \"\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":440,"wires":[["8788bb2e.f1407"]]},{"id":"9cc53fe5.5cf4","type":"debug","z":"ad2e7b14.5fbf","name":"","active":true,"console":"false","complete":"false","x":710,"y":460,"wires":[]},{"id":"2e2bbd21.d66d52","type":"inject","z":"ad2e7b14.5fbf","name":"","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"x":110,"y":460,"wires":[["d682710d.e25118"]]},{"id":"434d8c3c.dafe2c","type":"inject","z":"ad2e7b14.5fbf","name":"","topic":"","payload":"5","payloadType":"num","repeat":"","crontab":"","once":false,"x":110,"y":500,"wires":[["d682710d.e25118"]]},{"id":"87af1c05.3fd9c8","type":"debug","z":"ad2e7b14.5fbf","name":"","active":true,"console":"false","complete":"true","x":690,"y":400,"wires":[]},{"id":"284a0266.3214ae","type":"inject","z":"ad2e7b14.5fbf","name":"","topic":"","payload":"-1","payloadType":"num","repeat":"","crontab":"","once":false,"x":110,"y":420,"wires":[["d682710d.e25118"]]},{"id":"9e930281.5088f8","type":"inject","z":"ad2e7b14.5fbf","name":"","topic":"","payload":"-5","payloadType":"num","repeat":"","crontab":"","once":false,"x":110,"y":380,"wires":[["d682710d.e25118"]]},{"id":"8788bb2e.f1407","type":"template","z":"ad2e7b14.5fbf","name":"後続のノード","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"後続のノードは実行されました。","x":520,"y":440,"wires":[["9cc53fe5.5cf4","87af1c05.3fd9c8"]]}]

スクリーンショット 2016-05-22 17.14.49.png

  • 「1」や「-1」ではmsgが伝搬されず後続のノードが実行されないことを確認します。

  • 「5」や「-5」では後続のノードが実行されます。
    スクリーンショット 2016-05-22 17.14.41.png

  • 「閾値判断」functionノードのjsは以下の通りです。

閾値によって判断する
if ( Math.abs(msg.payload) < 3 ) {
    msg = "";
}
return msg;
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?