Reputation: 1
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
Upvotes: 0
Views: 1421
Reputation: 194
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
Upvotes: 0
Reputation: 59608
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.
Upvotes: 1