我刚开始使用Node-red和覆盆子pi。我有一个python脚本,它想要从node-red运行并接收mag.payload。我无法在守护程序节点中找到正确的命令来启动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
发布于 2019-07-30 05:41:42
首先,路径需要以前导/开头
因此,您需要将/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。
发布于 2019-08-03 07:11:28
如果您想要从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中节点的信息选项卡
https://stackoverflow.com/questions/57245696
复制相似问题