How to run a command in node-red node exec to enable a script for LCD

7,841 views
Skip to first unread message

Riyas

unread,
Oct 19, 2015, 4:45:45 PM10/19/15
to Node-RED


I have a script to bring a current time on LCD in Raspberry PI.

LCD is connected with Raspberry PI tested working fine.

I created a script name index.js inside ~/.node-red folder, and have installed LCD node module inside the same ~/.node-red folder using command : npm install lcd --save

cd ~/.node-red
pi@raspberrypi ~/.node-red $ sudo node index.js

When I tested inside using the command it brings the time on the LCD.

How to execute this index.js script in node-red node exec?

I have tried but does not work.

node-red connection picture

node exec config picture

[{"id":"49a533a9.b65acc","type":"inject","name":"","topic":"","payload":"1","payloadType":"string","repeat":"","crontab":"","once":false,"x":127,"y":97,"z":"5acd84ba.a5327c","wires":[["14f033d4.eb0fcc"]]},{"id":"14f033d4.eb0fcc","type":"exec","command":"sudo /home/pi/.node-red/node index.js","addpay":true,"append":"","useSpawn":"","name":"LCD","x":329.18345642089844,"y":107.16499328613281,"z":"5acd84ba.a5327c","wires":[[],[],[]]}]

In inject node I entered string 1 as payload

In exec node I entered command: sudo /home/pi/.node-red/node index.js

I tried in many ways to execute but no luck,

please check the pictures and help me in this issue.

Thanks a lot in advance



Dave C-J

unread,
Oct 19, 2015, 5:11:27 PM10/19/15
to node...@googlegroups.com

​Well there are a couple of things....
1) the flow has some extra path in the exec node that isn't the same as your command above...​
2) what user are you running Node-RED as ? You can't raise the access (or escalate privileges) by using sudo inside the runtime...
you can either not use sudo in your exec command...  or you can run the whole of Node-RED as sudo .... and then still not run sudo inside that exec :-)

If you need sudo to talk to the LCD then maybe investigate why that needs to be run as root... can you add yourself to some group that has the required privileges ?

Good luck

Riyas

unread,
Oct 19, 2015, 6:04:02 PM10/19/15
to Node-RED

Thanks for the reply. i log in as user pi, it is not a root or super user. 

Dave C-J

unread,
Oct 19, 2015, 6:48:49 PM10/19/15
to node...@googlegroups.com

So OK - you can't use sudo in an exec node.

Riyas

unread,
Oct 19, 2015, 7:44:21 PM10/19/15
to Node-RED
Hi , if not , is there a different way to execute the script in my case ?

Dave C-J

unread,
Oct 20, 2015, 3:35:46 AM10/20/15
to node...@googlegroups.com
as per my first reply you can either
run Node-RED as root user 
    sudo node-red
or find out why talking to the LCD needs root ... if on a pi - maybe read this and note the bit about the dialout group... http://elinux.org/RPi_Serial_Connection
You should be able to run your app (outside of Node-RED) without using sudo.

Peter Scargill

unread,
Aug 21, 2016, 1:52:15 PM8/21/16
to Node-RED
Lets say the only way was to run node-red as root - and you've stuffed all your new nodes in the pi/.node-red directory

How do you move everything so it all still works for the root node-red version....  I'm averse to going this but I'm losing the battle to get gpio access on some non-Pi boards without root.

Dave C-J

unread,
Aug 21, 2016, 2:03:01 PM8/21/16
to node...@googlegroups.com
Peter,
well - two options... 1) you can use the -u userdir param when you call Node-RED to point back to your normal .node-red location...
or 2 - if your gpio command you are exec-ing out to is a real command (and not a shell script) - you can look at setting suid - eg http://www.linuxnix.com/suid-set-suid-linuxunix/ - to set the app to run as root even though you call it as another user...  
(I would go with 2 :-)

Peter Scargill

unread,
Aug 21, 2016, 6:13:10 PM8/21/16
to node...@googlegroups.com

Tried the latter Dave – worked with C program written using WiringOp -  no problem – but that of course does now let me access PWM on non-PI


In this case- made no difference.

 

FAHW-Lib: Unable to open file /sys/class/gpio/gpio203/value

Etc

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/d2X4ilESMl0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
For more options, visit https://groups.google.com/d/optout.

Julian Knight

unread,
Aug 21, 2016, 7:35:49 PM8/21/16
to Node-RED, pe...@scargill.org
What owns the gpio folder? On the pi it is owned by root/gpio

If your non-pi boards own it as root/root, I recommend changing it to something else. Probably create a gpio group and then move the group ownership accordingly. Then the issues should go away. You just need to remember to add the steps to your master config script for when you do a major upgrade or OS reinstall.
Reply all
Reply to author
Forward
0 new messages