Multiple Arguments to Python Shell


I'm a beginner on both JS and Python, so I can't get too deep into the weeds on the script side. Hopefully I can provide enough context so that my question makes sense.

I am trying to run a single pass python script ( from the Bacpypes library) that requires two arguments to execute. This is using the python shell node.

I can manually run the command on the host (Alpine Linux) with
#python <device_id> <device_addr>
(both values entered with no punctuation, separated by a single space).
It works perfectly from the host CLI.

In Node-Red, I can't find a way to satisfy both arguments, as the script is expecting an integer for the ID and a string for the address.
If I send both arguments as a single string, the script doesn't accept it and errors out on invalid integer for device_id.
If I inject the ID as a number type, it skips past that error and of course comes back with an error for missing the address.

From what I've gathered, the value of msg.payload can't be of mixed types.

I've tried breaking the message up into an array, which does allow the two values to exist as different types, but if I inject that array into the python shell node, it errors out for both required arguments being missing and spits back the array as a string (square brackets included).

Does anyone know of a workaround or trick that would let me pass those two arguments on invoking the script? I'm not opposed to an exec node either, but it seems that the mixed data types is going to be an issue either way.

The python shell seems to work well with other scripts that take either a single argument or listen for console commands that can be injected in the msg.payload.

Thanks for reading!

How are you trying to execute this from node-red ? (ie. what does your flow look like)

Note that there is a bacnet node for node-red as well.

I've tried to use the Node-Red BACnet, but it doesn't support MS/TP devices. There is a new module out from Bitpool that also uses the JS Bacstack library and DOES detect the MS/TP devices but has issues properly fetching the objects.

The python Bacpypes library is much further developed, and the included samples so far have worked extremely well when running via CLI in the host. Network discovery works well in a Node-Red python shell, but that script runs and listens for singular arguments on the Std-In.

The script I'm trying to run requires the two arguments. It fires up, runs once, and closes when it gets the results.
Here is a barebones flow of the nodes I'm working with.

        "id": "63fb3651af578236",
        "type": "tab",
        "label": "Read Object List",
        "disabled": false,
        "info": "",
        "env": []
        "id": "21b26a2ea19de941",
        "type": "pythonshell in",
        "z": "63fb3651af578236",
        "name": "",
        "pyfile": "/bacpypes/samples/",
        "virtualenv": "",
        "continuous": false,
        "stdInData": false,
        "x": 730,
        "y": 240,
        "wires": [
        "id": "d33dfc5344b6ee8d",
        "type": "debug",
        "z": "63fb3651af578236",
        "name": "debug 16",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1180,
        "y": 240,
        "wires": []
        "id": "39be4bef97350806",
        "type": "inject",
        "z": "63fb3651af578236",
        "name": "",
        "props": [
                "p": "payload"
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "750",
        "payloadType": "str",
        "x": 360,
        "y": 240,
        "wires": [

Here is a debug if I inject a string containing the two arguments:

Here is when I change the type to a number and just send the device_id argument:

Here is a snip of the script being invoked in the command line:

Thanks for responding.

Well, it THINKS it is - but it isn't really. That is a limitation of s command line scripts. But that shouldn't be relevant.

I've not done this for a while so I might not be exactly right but I think if you make the payload an array, it would probably do the job. Alternatively, you should be able to send both as a single string separated by a space as long as node-red isn't putting quotes around them.

What are these dark blue nodes ? Did you try to execute the /bacpypes/samples/ command with arguments with an exec node instead ?

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