【问题标题】:Node-red daemon节点红色守护进程
【发布时间】:2019-07-28 23:26:53
【问题描述】:

我是使用 Node-red 和树莓派的新手。我有一个想要从 node-red 运行并接收 mag.payload 的 python 脚本。我无法在守护程序节点中找到正确的命令来启动 python 脚本。任何帮助表示赞赏。

当前 Python 脚本:

import time
import board
import busio
import adafruit_mprls
import RPi.GPIO as GPIO

try:
    import RPi.GPIO as GPIO
except RuntimeError:
    print("Error importing RPi.GPIO! This is probably because you need 
superuser privileges.")

i2c = busio.I2C(board.SCL, board.SDA)


mpr = adafruit_mprls.MPRLS(i2c, psi_min=0, psi_max=25)


"""
import digitalio
reset = digitalio.DigitalInOut(board.D5)
eoc = digitalio.DigitalInOut(board.D6)
mpr = adafruit_mprls.MPRLS(i2c, eoc_pin=eoc, reset_pin=reset,
                       psi_min=0, psi_max=25)
"""

while True:
    print((mpr.pressure,))
    time.sleep(1)

python脚本存放在home/pi/Document/pressure.py

我不确定 node-red 的守护程序节点中的命令和参数应该是什么。我试过了

命令:usr/bin/python

参数:home/pi/Documents/prressure.py

【问题讨论】:

  • 您尝试了什么以及遇到了什么错误。此外,没有关于脚本存储位置的信息,或者这个问题目前无法回答的参数是什么。编辑问题以添加更新。
  • 我没有询问脚本的内容,我询问了它在您的系统上的存储位置以及您已经尝试过的内容的描述。

标签: python daemon node-red


【解决方案1】:

首先路径需要以/开头

因此您需要将/usr/bin/python 放入命令中,并将/home/pi/Documents/prressure.py 放入参数中。

唯一的问题是脚本暗示它需要以 root 身份运行。除非您真的很清楚自己在做什么,否则您不应该以 root 身份运行 Node-RED。另一种选择是使用sudo 运行,在这种情况下,您可以将/usr/bin/sudo 放在命令中,将/usr/bin/python /home/pi/Documents/prressure.py 放在参数中。这仅适用于树莓派,因为pi 用户通常可以在没有密码的情况下使用sudo

【讨论】:

  • 尝试了您的响应并从调试中获得“命令未运行”。如何在 root 之外运行 Node-red?
  • 我也遇到了同样的错误。我在 pi 上运行它,python 文件不需要 sudo。命令:/usr/bin/python3 参数:/home/pi/gadget/Alexa-Gadgets-Raspberry-Pi-Samples/src/examples/kitchensink/kitchen_sink_gadget.py。任何帮助表示赞赏。
【解决方案2】:

如果您想从 node-red 运行程序/脚本/命令,我建议您检查 Exec Node

    Runs a system command and returns its output.
    The node can be configured to either wait until the command completes, or to send its output as the command generates it.
    The command that is run can be configured in the node or provided by the received message.

有关更多信息,请查看 Node-Red 中节点的信息选项卡

【讨论】:

  • exec 节点不是这里的正确答案。 exec 节点期望一个短期运行的应用程序将其输出打印到标准输出然后退出,然后它发送一条包含输出的消息。OPs 代码永远不会退出,它会运行并继续将其输出打印到标准输出。为此,OP 正确地选择了守护程序节点,它将在程序输出的每个新行上发送一条消息。
  • 您可以在进程运行时使用生成模式获取数据。
猜你喜欢
  • 2019-04-02
  • 2023-03-02
  • 1970-01-01
  • 2010-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多