0
votes

I am new to using Node-red and the raspberry pi. I have a python script that would like to run from node-red and receive the mag.payload. I cannot figure the correct command in the daemon node to start the python script. Any help is appreciated.

Current Python script:

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)

The python script is stored at home/pi/Document/pressure.py

I am not sure what the command and arguments should be in the daemon node of node-red. I have tried in

command: usr/bin/python

arguments: home/pi/Documents/prressure.py

2
What have you tried sand what error did you get. Also with no information about where the script is stored, or what arguments it takes this question is currently Impossibles to answer. Edit the question to add updates. - hardillb
I didn't ask for the content of the script, I asked where it was stored on your system and for a description of what you have already tried. - hardillb

2 Answers

1
votes

Firstly paths need to start with a leading /

So you need to put /usr/bin/python into the command and /home/pi/Documents/prressure.py into the arguments.

The only problem is the script implies it needs to be run as root. You should NOT run Node-RED as root unless you REALLY REALLY know what you are doing. The other option would be to run with sudo in which case you would put /usr/bin/sudo in the command and /usr/bin/python /home/pi/Documents/prressure.py in the arguments. This will only work on a raspberry pi because the pi user is normally allowed to use sudo without a password.

0
votes

If you want to run a program/script/command from node-red i recommend you checkout 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.

For more information check the info tab of the node in Node-Red