Pythonshell use in Node-red

Dears,

I have installed pythonshell and want to exec BACpypres script. For example ">python /home/pi/bacpypes/samples/RandomAnalogValueSleep.py --ini BACpypes,ini". However, I don't know how to do it correctly. Could you please help me solve it ?

Br,
Chris

So what have you tried so far?
What keywords have you used in a search of the forum?

Hi zenofmud,

I cannot run the script in pythonshell and the result show "pyfile not exist".

[{"id":"16b51057.cf729","type":"pythonshell in","z":"41096a38.ae9594","name":"","pyfile":"/home/pi/bacpypes/samples/RandomAnalogValueSleep.py --ini BACpypes.ini","virtualenv":"/home/pi/bacpypes/","continuous":false,"stdInData":false,"x":340,"y":160,"wires":[["95fd053b.8b33d8"]]},{"id":"89192f8.b3c71d","type":"inject","z":"41096a38.ae9594","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":140.5,"y":76,"wires":[["16b51057.cf729"]]},{"id":"95fd053b.8b33d8","type":"debug","z":"41096a38.ae9594","name":"","active":true,"console":"false","complete":"false","x":537.5,"y":233,"wires":[]}]

What keywords have you used in a search of the forum?

Yes. I search the "python" in the forum but I cannot find answer to solve it. I think the key point is that how to identify argv [argument]. Example: >python /xxx/xxx/xxx/xxx.py --ini BACpypes.ini

you might want to try the 'exec' node and pass the arguments to it.

Using the exec node to run a python script works fine and I use NR to start a number of python scripts for various tasks. In addition, I like some of them to be started "visually", i.e. when I vnc into a headless RPi I want to see the script execution. To do this, I configure the exec node as shown below. In the example from my home automation systems I have four python scripts running in this way
image

1 Like

If you still want to use the pythonshell node, you should read the documentation to see how to padd arguments, You might want to try the example flow the author provides.

Dears,

I also try to use exec node to run python script in windows OS. However it still have issue.

[{"id":"a57ce9b6.631478","type":"exec","z":"59cea228.0dde9c","command":"python C:\bacpypes\RandomAnalogValueSleep.py --ini","addpay":true,"append":"C:\bacpypes\BACpypes.ini","useSpawn":"false","timer":"","oldrc":false,"name":"","x":500,"y":780,"wires":[["da47c202.50496"],["da47c202.50496"],["da47c202.50496"]]},{"id":"2d79e91a.e26fb6","type":"inject","z":"59cea228.0dde9c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":720,"wires":[["a57ce9b6.631478"]]},{"id":"da47c202.50496","type":"debug","z":"59cea228.0dde9c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":950,"y":780,"wires":}]

The correct command should be the follows,
image

there seems to be quite a difference between the command you are using in the exec node vrs what you call the correct command. So does, from the command line, the command

python C:bacpypes/RandomAnalogValueSleep.py --ini C:bacpypes/BACpypes.ini

work> I notice in the example where it works, bagpipes.ini is not in caps....

Sorry, I don't run Node-RED in Windows, only Linux

Maybe you need double backslashes in Windows (Like C:\\ etc etc)

It seems cannot identify arguments always show "unrecognized arguments". Below is my command in exec node for reference.

image

image

However it can be run well in command line as follows,

http://bacpypes.sourceforge.net/

try unchecking the +Append [] msg.payload.

It looks like a timestamp is being passed - in msg.payload - to the exec node and is being added to the arguments.

Thank you. After uncheck the +Append[] msg.payload it is correct now.