Installation de Node.js et Node-RED sur Raspberry PI

=Installation de Node.js=

Lire http://raspberryalphaomega.org.uk/2014/06/11/installing-and-using-node-js-on-raspberry-pi/

Au 2014/10/15, la version 0.10.25 est la version la plus récente de Node.js qui fonctionne correctement sur Raspberry Pi

=Installation de Node-RED=

Lire http://nodered.org/docs/hardware/raspberrypi.html

Installez Wiring PI http://wiringpi.com/download-and-install/

Installez la dépendance rpi-gpio

Créez flow-gpio.json avec [{"id":"860e0da9.98757","type":"function","name":"Toggle LED on input","func":"\n// select wpi pin 0 = pin 11 on header (for v2)\nvar pin = 0;\n\n// initialise the wpi to use the global context\nvar wpi = context.global.wpi;\n\n// use the default WiringPi pin number scheme...\nwpi.setup;\n\n// initialise the state of the pin if not already set\n// anything in context. persists from one call to the function to the next\ncontext.state = context.state || wpi.LOW;\n\n// set the mode to output (just in case)\nwpi.pinMode(pin, wpi.modes.OUTPUT);\n\n// toggle the stored state of the pin\n(context.state == wpi.LOW) ? context.state = wpi.HIGH : context.state = wpi.LOW;\n\n// output the state to the pin\nwpi.digitalWrite(pin, context.state);\n\n// we don't \"need\" to return anything here but may help for debug\nreturn msg;","outputs":1,"x":333.16666412353516,"y":79.16666793823242,"wires":"574f5131.36d0f8"},{"id":"14446ead.5aa501","type":"inject","name":"tick","topic":"","payload":"","repeat":"1","once":false,"x":113.16666412353516,"y":59.16666793823242,"wires":"860e0da9.98757"},{"id":"574f5131.36d0f8","type":"debug","name":"","active":true,"x":553.1666641235352,"y":99.16666793823242,"wires":[]}]

Lancez Node

Naviguez sur http://192.168.0.10:1880

Extra: Banchement d'un Arduino
Installez la dépendance firmata si vous prévoyez de connecter un Arduino

Deployez ce Flow flow-blink.json [{"id":"d7663aaf.47194","type":"arduino-board","repeat":"25","device":"/dev/ttyUSB0"},{"id":"8c09ca6c.a975d","type":"arduino out","name":"","pin":"13","state":"OUTPUT","arduino":"d7663aaf.47194","x":509.16667556762695,"y":162.16666984558105,"wires":[]},{"id":"e37b6a97.610968","type":"inject","name":"tick","topic":"","payload":"","repeat":"0.5","once":false,"x":116.16668319702148,"y":62.16666507720947,"wires":"60b4aeaa.800d58"},{"id":"60b4aeaa.800d58","type":"function","name":"Toggle output on input","func":"\n// initialise level as a context variable if currently undefined \n// (context variables persist between calls to the function)\ncontext.level = context.level || false;\n\n// if it's a 0 make it a 1 else make it a 0...\ncontext.level = !context.level;\n\n// set the payload to the level and return\nmsg.payload = context.level;\nreturn msg;","outputs":1,"x":298.1666793823242,"y":113.16665458679199,"wires":"8c09ca6c.a975d"}]

Naviguez sur http://192.168.0.10:1880

=Configuration de Node-RED en service=

Lire la section Making Node-RED autostart on boot (optional) dans http://nodered.org/docs/hardware/raspberrypi.html

Copiez le script https://gist.github.com/Belphemur/cf91100f81f2b37b3e94 dans /etc/init.d/node-red