javascript 如何在 node-red node exec 中运行命令来为 LCD 启用脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33222875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run a command in node-red node exec to enable a script for LCD
提问by rwahid
I have a script to bring a current time on LCD in Raspberry PI.
我有一个脚本可以在 Raspberry PI 的 LCD 上显示当前时间。
LCD is connected with Raspberry PI tested working fine.
LCD与Raspberry PI连接测试工作正常。
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
我在 ~/.node-red 文件夹中创建了一个脚本名称 index.js,并使用命令在同一个 ~/.node-red 文件夹中安装了 LCD 节点模块: 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.
当我使用该命令在内部进行测试时,它会在 LCD 上显示时间。
How to execute this index.js script in node-red node exec?
如何在 node-red node exec 中执行这个 index.js 脚本?
I have tried but does not work.
我试过了,但不起作用。
In inject node I entered string 1 as payload
在注入节点中,我输入了字符串 1 作为有效负载
In exec node I entered command: sudo /home/pi/.node-red/node index.js
在 exec 节点中,我输入了命令: 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
非常感谢提前
回答by hardillb
In the exec config node
在 exec 配置节点中
- 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
- 将命令更改为
/usr/bin/sudo
- 取消选中附加 message.payload 框
- 将以下内容放在额外的输入参数中:
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.
您不需要将 index.js 放在 .node-red 目录中,但因为它在那里,所以应该可以工作。