node-red / node-red-nodes

Extra nodes for Node-RED
Other
983 stars 592 forks source link

[error] [rpi-neopixels] TypeError: Cannot read property 'stdin' of null #636

Closed braghettos closed 4 years ago

braghettos commented 4 years ago

Which node are you reporting an issue on?

node-red-node-pi-neopixel

What are the steps to reproduce?

use docker image braghettos/makealedwheaterboard:latest source code is available at https://github.com/braghettos/makealedweatherboard.git

What happens?

The node is in "stopped" status. When the node receives a msg, the error in debug console is "[error] [rpi-neopixels:8c34d22e.037ad] TypeError: Cannot read property 'stdin' of null"

What do you expect to happen?

Status "running" for the node

Please tell us about your environment:

hardillb commented 4 years ago

This is most likely because you are using the Alpine based build (minimal) which doesn't look to include python, which is needed for the neopixel node.

Try will the full full docker container rather than the minimal build.

hardillb commented 4 years ago

OK, looks like you've installed python. What's in the node-red log when it fails, is there anything written to stdout?

braghettos commented 4 years ago

Hi @hardillb , nothing is written on startup of node red. Just when I try to send a msg in input.

hardillb commented 4 years ago

Yes, that's what I'm asking for, not the content of the debug sidebar, I want to see the section of the log around the failure.

braghettos commented 4 years ago

image

hardillb commented 4 years ago

No, As I said, not what's in the debug sidebar, I want to see the actual console output from node-red.

It will be in the container log as it all just ends up in stdout

braghettos commented 4 years ago

image

hardillb commented 4 years ago

log into the container, cd to /data/node_modules/node-red-node-pi-neopixel and then run:

./neopix 1 40 pcent 100 true

And let me know what the output is.

I am 99% sure this will be a problem with how you have set your container up.

Also check what the output of python --version is (I'm going to guess it's 2.x and you've built all the unicorn stuff with python3)

braghettos commented 4 years ago
bash-5.0# cd node-red-node-pi-neopixel
bash-5.0# pwd
/usr/src/node-red/node_modules/node-red-node-pi-neopixel
bash-5.0# ./neopix 1 40 pcent 100 true
sudo: setrlimit(RLIMIT_CORE): Operation not permitted
Can't open device file
: Operation not permitted
Traceback (most recent call last):
  File "./neopix.py", line 169, in <module>
    strip.begin()
  File "/usr/lib/python2.7/site-packages/rpi_ws281x/rpi_ws281x.py", line 130, in begin
    raise RuntimeError('ws2811_init failed with code {0} ({1})'.format(resp, str_resp))
RuntimeError: ws2811_init failed with code -9 (Failed to create mailbox device)
bash-5.0# python --version
Python 2.7.16
dceejay commented 4 years ago

So as the error says the user you are running as is not permitted to create that device - I'm not familiar with that script enough to know if just running it once with root would be enough to create the device so you then use it in node-red the next time or if it must be run as root the whole time.

hardillb commented 4 years ago

The neopix script is already running things with sudo

dceejay commented 4 years ago

and they have permissions up through docker to get to the host hardware ? I think the answer is don't use docker for direct hardware DMA support https://github.com/jgarff/rpi_ws281x/issues/210 Don't think there is anything we can do about it.

braghettos commented 4 years ago

Docker can talk directly with hw with the --device option or running in privilege mode. Which is the device to use in this case?

dceejay commented 4 years ago

Well the C code seems to say this

sprintf(filename, "/tmp/mailbox-%d", getpid());
   unlink(filename);
   if (mknod(filename, S_IFCHR|0600, makedev(100, 0)) < 0) {
      printf("Failed to create mailbox device %s: %m\n", filename);
      return -1;
   }

so it looks to be dynamic based on the pid. Good luck !

braghettos commented 4 years ago

After launching the Docker container in privileged mode: docker run -d -p 1880:1880 --name weatherledboardnodered --privileged --group-add dialout --device=/dev/spidev0.0 --device=/dev/spidev0.1 --device=/dev/serial0 --user=root --restart=always -e NODE_OPTIONS="--max_old_space_size=256" --log-opt max-file=2 --log-opt max-size=2k -e TZ="Europe/Rome" braghettos/makealedwheaterboard:latest

The following command doesn't return any error:

bash-5.0# ./neopix 1 40 pcent 100 true

image

Looks like I've been lucky!

dceejay commented 4 years ago

great - so OK to close this ? as nothing we are going to fix.

braghettos commented 4 years ago

Yes! if you want to add this configuration on the README would be helpful for others!