Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger Python script on Raspberry Pi from Node-Red

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+

like image 981
pronoob Avatar asked Aug 17 '15 19:08

pronoob


People also ask

How to run Node RED on Raspberry Pi?

Running on Raspberry Pi 1 Prerequisites. If you are using Raspbian, then you must have Raspbian Stretch as a minimum version. ... 2 Installing and Upgrading Node-RED. We provide a script to install Node.js, npm and Node-RED onto a Raspberry Pi. ... 3 Running locally. ... 4 Running as a service. ... 5 Autostart on boot 6 Opening the editor. ...

How to run Python script in Node-RED?

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.

How do I run Node-RED-Pi in the background?

To do this, you should use the alternative node-red-pi command and pass in the max-old-space-size argument. The install script for the Pi also sets it up to run as a service. This means it can run in the background and be enabled to automatically start on boot.

How to deploy MSG-payload node using Python?

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.


1 Answers

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.

like image 149
hardillb Avatar answered Sep 20 '22 06:09

hardillb