Fails on require('raspi-io');

330 views
Skip to first unread message

Alan UK

unread,
Dec 20, 2016, 3:21:18 PM12/20/16
to Node-RED
Hardware: Rasppberry Pi Model B+  Rev 1.2 with Pro HAT linked to 5 x DHT22 sensors, 1x BMP280, 3 xLEDs, 1x Buzzer, 1x Button & 2x Reed Switches
Software: fresh Raspbian Jessie (Linux 4.4.34+ arm LE), Node.js (4.4.3), Node-Red (0.15.2), Johnny Five (0.10.6), raspi-io (5.4.1), Wiring Pi (gpio) (2.3.6),
bcm2835 (1.50), node-red-contrib-gpio (0.9.1), npm (4.0.5), git (2.1.4)
Plus these 3 but didn't appear to be successful but may not be material to my problem: raspi, raspi-board, raspi-peripheral
Additional Nodes (from memory compared to initial install): gpio, johnny5, rpi dht22, rpi gpio (original?)
Running Node-Red by: sudo node-red-pi --max-old-space-size=128 --userDir $HOME/.node-red
Unit Testing: All sensors and other I/Os working OK with Python.
Node-Red Initial Testing: node gpio works to switch on an LED.

I then copied some example code into a function node but it fails on line 1:
    var raspi = require('raspi-io');

and that gives the error:
    ReferenceError: require is not defined (line 1, col 13)

From what I read, require() is built into node.js on the server so it is always available there. Any ideas what could be wrong?

Many thanks,
Alan

Nicholas O'Leary

unread,
Dec 20, 2016, 3:23:23 PM12/20/16
to Node-RED Mailing List
Hi Alan,

You cannot use 'require' in a function node - the node runs your code in a sandbox that restricts access to the full node.js environment.

The docs include an example of how to add modules to the sandbox - via your settings file.



Regards,
Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/163d6f78-d4d1-47ad-b2e1-d0629994602c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alan UK

unread,
Dec 20, 2016, 7:20:43 PM12/20/16
to Node-RED
Many thanks Nick for a speedy reply.

I added  raspiio: require('raspi-io'), to functionGlobalContext:

NR was then loaded and I made a change to my function code but when I run the flow then NR falls over.
Worse, every time I restart NR I get the same error so I am no longer able to correct the flow!

>> 21 Dec 00:06:59 - [red] Uncaught Exception:
21 Dec 00:06:59 - TypeError: Cannot read property 'type' of null
    at Function.Pins.normalize (/home/pi/.node-red/node_modules/johnny-five/lib/board.pins.js:91:24)
    at Led.Board.Component (/home/pi/.node-red/node_modules/johnny-five/lib/board.js:850:23)
    at new Led (/home/pi/.node-red/node_modules/johnny-five/lib/led/led.js:143:19)
    at Board.<anonymous> (evalmachine.<anonymous>:14:4)
    at emitNone (events.js:72:20)
    at Board.emit (events.js:166:7)
    at nextTickCallbackWith0Args (node.js:420:9)
    at process._tickDomainCallback (node.js:390:13)

NR conceptually seems wonderful but I'm getting despondent already as to how convoluted the installation is and how flaky and unforgiving NR is.

Alan

Luis Montes

unread,
Dec 20, 2016, 7:30:10 PM12/20/16
to node...@googlegroups.com
node-red is fine, the issue is that johnny-five is a bit of complex API to use in conjunction with it.  I specifically made the contrib-gpio nodes to try and deal with this.

We have a few issues.  The johnny-five plugin for raspberry pi (raspi-io) is not the easiest thing to install.  You have to install it as a non-root user, yet run it as root.  In addition to that, the latest version of raspi-io doesn't like being re-initialized for each flow deployment because it has a dependency on the latest serialport which locks the port by default on linux now.

Johnny-five itself doesn't like to be redeployed either, so I try and mitigate issues there by cleaning up the board instance in my gpio nodes.

You can try raspi-io version 5 installed as non-root, but running as root.  Then install the gpio nodes and use the johnny-five node.  The johnny-five node includes require.


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Alan UK

unread,
Dec 21, 2016, 9:39:15 AM12/21/16
to Node-RED
Thanks Luis. I will have to put this on hold until after Christmas but will then reinstall as you suggested. Have a good holiday time.

Alan
Reply all
Reply to author
Forward
0 new messages