Tiny Core Linux
Tiny Core Base => Raspberry Pi => Topic started by: joef on March 11, 2019, 10:08:08 AM
-
Hey guys!
I have a python script that flashes an LED via the GPIO pins on the Pi.
This works perfectly fine when ran directly using:
sudo python flashLed.py
For example sake, I have a node server that calls the same command via node-cmd using:
cmd.run("sudo python flashLed.py")
When I run that node server manually, the led flashes away perfectly. However if I start that node server from bootlocal.sh I get no flashing led (the server is running correctly as i can hit it remotely).
bootlocal.sh has the following and doesn't led doesnt flash:
sudo node /home/tc/server.js
Strangely running the following in bootlocal.sh works:
sudo python flashLed.py
So I think it's something to do with node being started from bootlocal.sh not having root when it runs the python command, even though I'm running it with sudo.
Any ideas?
Thanks!
-
Hi joef
... So I think it's something to do with node being started from bootlocal.sh not having root when it runs the python command, even though I'm running it with sudo. ...
Using sudo is not required for bootlocal.sh because it already runs as root.
-
Thanks Rich!
Possibly something to do with it running in the background and not having access to GPIO perhaps?
-
Does node require network? The network is typically not fully ready when bootlocal.sh runs.
-
Hi joef
Paul_123 makes a very good point. Easy enough to confirm. Create a file called flasher.sh in your home directory containing:
#!/bin/sh
# Wait for network to come up
SEC=60
while [ $SEC -gt 0 ]
do
$(( SEC-- ))
ifconfig | grep -q "Bcast:" && break
sleep 1
done
node /home/tc/server.js
Make the file executable. In your bootlocal.sh file replace the sudo node /home/tc/server.js line with:
/home/tc/flasher.sh &
-
Thanks! I tried this, didn't make any difference I'm afraid.
Node is definitely starting up fine as I can hit the server remotely, when I hit the server it should flash the led, I get a response from node no problem, but no led flash!
If I start the server manually and not from bootlocal.sh, it all works fine.
-
Hi joef
Is running node /home/tc/server.js supposed to flash the LED? Or do you need to also run cmd.run("sudo python flashLed.py")?
If that's the case, then it should have been:
#!/bin/sh
# Wait for network to come up
SEC=60
while [ $SEC -gt 0 ]
do
$(( SEC-- ))
ifconfig | grep -q "Bcast:" && break
sleep 1
done
node /home/tc/server.js
cmd.run("sudo python flashLed.py")
-
Hey Rich,
node /home/tc/server.js has logic that runs cmd.run("sudo python flashLed.py") when certain endpoints on the server have been hit. E.g every time a certain url is loaded, the led should flash, so it needs to be part of the node app and not separated out.
Thanks!