#はじめに
RaspberryPiでNode-REDが標準パッケージになったと聞いたので早速入れてみました。
参考サイト
#準備
RaspberryPiを用意します。
今回はRaspberryPi2を使いました。
基本のセットアップはこんなかんじ
#インストール
Raspbian-Jessieのフル版をインストールするとNode-REDがついてきます。
別のバージョン/Lite版の場合は、apt-getで入手します。
#起動
node-red-start
コマンドを実行すると、ブラウザからアクセスできるURLがコンソールに表示されます。
pi@raspberrypi:~$ node-red-start
Once Node-RED has started, point a browser at http://192.168.128.59:1880
To stop Node-RED use the command node-red-stop
Starting nodered (via systemctl): nodered.service.
Node-RED service start: Sat 12 Dec 11:17:21 UTC 2015
Welcome to Node-RED
===================
12 Dec 11:17:26 - [info] Node-RED version: v0.12.1
12 Dec 11:17:26 - [info] Node.js version: v0.10.29
12 Dec 11:17:26 - [info] Loading palette nodes
12 Dec 11:17:36 - [info] Settings file : /home/pi/.node-red/settings.js
12 Dec 11:17:36 - [info] User directory : /home/pi/.node-red
12 Dec 11:17:36 - [info] Flows file : /home/pi/.node-red/flows_raspberrypi.json
12 Dec 11:17:36 - [info] Server now running at http://127.0.0.1:1880/
12 Dec 11:17:36 - [info] Creating new flow file
12 Dec 11:17:36 - [info] Starting flows
12 Dec 11:17:36 - [info] Started flows
http://192.168.128.59:1880
pi@raspberrypi:~$
RaspberryPi用のノードとかもあります。
#GPIO制御してみる
Lチカ
tweetに"raspberrypi"が含まれるor含まれない を条件にしてLチカします。
#NodeREDのフローはこちら
[{"id":"62948a9a.228c6c","type":"rpi-gpio out","z":"5015cd83.a920ac","name":"GPIO26","pin":"37","set":true,"level":"0","out":"out","x":605,"y":241,"wires":[]},{"id":"71ecf63e.cbe82","type":"twitter in","z":"5015cd83.a920ac","twitter":"","tags":"#GPIO","user":"false","name":"GPIO talk","topic":"tweets","x":99,"y":237,"wires":[["bec1e157.58b2e8"]]},{"id":"bf83350c.f74878","type":"debug","z":"5015cd83.a920ac","name":"","active":true,"console":"false","complete":"payload","x":603,"y":143,"wires":[]},{"id":"bec1e157.58b2e8","type":"switch","z":"5015cd83.a920ac","name":"text match","property":"payload","rules":[{"t":"cont","v":"raspberrypi"},{"t":"else"}],"checkall":"true","outputs":2,"x":257,"y":239,"wires":[["651ad091.1f3238"],["1445b39.2a5edcc"]]},{"id":"651ad091.1f3238","type":"function","z":"5015cd83.a920ac","name":"return 1","func":"return {payload:1};\n","outputs":1,"noerr":0,"x":426,"y":210,"wires":[["62948a9a.228c6c","bf83350c.f74878"]]},{"id":"1445b39.2a5edcc","type":"function","z":"5015cd83.a920ac","name":"return 0","func":"return {payload:0};\n","outputs":1,"noerr":0,"x":432,"y":267,"wires":[["62948a9a.228c6c","2aa75411.36e92c"]]},{"id":"2aa75411.36e92c","type":"debug","z":"5015cd83.a920ac","name":"","active":true,"console":"false","complete":"false","x":601,"y":362,"wires":[]}]