How to trigger Python script on Raspberry Pi from Node-Red
27,022
Solution 1
Node-RED supplies an exec node as part of it's core set, which can be used to call external commands, this could be call your python script.
More details of how to use it can be found in the info sidebar when a copy is dragged onto the canvas.
Or you could wrap the script as a web service or just a simple TCP socket, both of which have nodes that can be used to drive them.
Solution 2
- I hope you have installed red-node along with Python. If not, install it using following either in Power shell or CMD: npm install -g node-red-contrib-python3-function
- After starting node-red, you can find pythonshell node in Node Panel of node-red. Drag and Drop it and double click it to get "node properties" panel, Enter Python.exe path in Name and Python File in Py File and click on Done.
- Have and msg-payload node connected to it and Deploy.
- Click on PythonShell node input, you will get your python program executed and displayed in output.
Author by
pronoob
Updated on February 12, 2020Comments
-
pronoob about 4 years
I'm using Node-Red, hosted on a Raspberry Pi for an IoT project.
How do I trigger a Python script that is on the raspi from Node-Red? I want to run a script that updates the text on an Adafruit LCD shield which is sitting on the Pi
Should I be looking to expose the Python script as a web service somehow?
I'm using a Raspberry Pi B+
-
pronoob over 8 yearsAwesome, thanks! Is there any way to pass a variable into the exec node? Would be cool if I could send a tweet or something