节点守护程序

2024-06-13 05:05:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我是新使用节点红和树莓派。我有一个python脚本,它希望从节点red运行并接收有效载荷. 我无法在daemon节点中找到正确的命令来启动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中/压力.py在

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

命令:usr/bin/python

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


Tags: import命令boardadafruit脚本gpio节点i2c
2条回答

如果您想从节点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.

有关详细信息,请查看节点Red中节点的info选项卡

首先,路径需要以/开头

所以您需要将/usr/bin/python放入命令中,/home/pi/Documents/prressure.py放入参数中。在

唯一的问题是脚本暗示它需要作为根用户运行。除非您真的知道自己在做什么,否则不应该以root身份运行Node RED。另一个选项是使用sudo运行,在这种情况下,您将把/usr/bin/sudo放在命令中,/usr/bin/python /home/pi/Documents/prressure.py放在参数中。这只适用于raspberry pi,因为pi用户通常不需要密码就可以使用sudo。在

相关问题 更多 >