Help with exec node

I was poking around with running a python script in my raspberry pi with the exec node.
It looks like my script was run by it but i don't think i know how to get the result crunched by my code in the msg.payload or debug tab in node red.

Can someone point me out as to what i need to do in my python code to make this show up in the debug panel of node red? My python code generates a json styled output which needs to be used to do something on the Node red dashboard.

Appreciate any help on this !
Thanks :slight_smile:

You just need to print what you want to push to msg.payload...
For example print('Hello World') would appear in debug node as msg.payload....

But i am expecting a variable which is dynamic to come as the returned value after running my code
Variable is json string with the calculated values.

Lets say my variable i want is saved in a class,
I have "MyPort.growthValuation" which has all the json values i want.

I placed this command under

if name == 'main':
MyPort = MyPortfolio()
MyPort.GetInfo()
print(MyPort.growthValuation)

I did this but the print statement doesn't show up in the Node red console window under the debug node :frowning:

You can freely develop your python script as normal, test it via python filename.py and once you see in your tests the values you want to push to node-red just run it trought exec node...

Have you checked all three outputs of the exec node to see what is there? Use three debug nodes configured to Show Complete Message and give them names so you can identify them in the debug pane.

As per the info panel you made need -u option on Python to stop it buffering its output.

Ah Yes, My output came in the 1st output node
Will keep this in mind !

Thanks @Colin

I find it much easier to add MQTT support to a python script, and have said script run as a service. Then use NR to request and receive from the python (service) via MQTT. Not to say that exec method is not an option, but having python talk MQTT to and from NR is much easier in the long run, IMHO.

That is actually a wonderful idea !
MQTT is the easiest thing to work with. Since the script runs on my raspberry pi i can make use of crontab to run it at fixed intervals and spit out the information using MQTT
Thanks @Nodi.Rubrum

You are welcome. :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.