How to run a command in node-red node exec to enab

2019-08-09 19:29发布

问题:

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

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

回答1:

In the exec config node

  • Change the command to just /usr/bin/sudo
  • Uncheck the append message.payload box
  • Place the following in the extra input parameters: node /home/pi/.node-red/index.js

You don't need to put your index.js in the .node-red directory but since it's there this should work.