MQTT configuration nodes are not recognized when packaged in a subflow module

Structure

── node-red
│   └── subflows
│       ├── custom-nodes-internal-mqtt-in.js
│       ├── custom-nodes-internal-mqtt-in.json
│       ├── custom-nodes-internal-mqtt-out.js
│       └── custom-nodes-internal-mqtt-out.json
├── Dockerfile
├── package.json

After some painstaking deep dive into packaging subflow modules tried running things within a docker container only to find out that the configuration for mqtt broker node is not being read.

custom-nodes-internal-mqtt-in.json

this is the adapted JSON file based on the packaging documentation for subflows

{
    "id": "45db115760787ca3",
    "type": "subflow",
    "name": "internal mqtt in",
    "info": "# Internal MQTT In Node\n\nAutomatically connects to the Internal MQTT Broker and subscribes to User-Defined MQTT Topics\n\n## Subscribe to MQTT Topics\n\nCreate an __Inject__ node with following:\n\n- `msg.action` = `subscribe`\n- `msg.topic` = `YOUR/TOPIC/HERE`\n\nand connect to this node\n\n## Disconnect from Internal MQTT Broker\n> NOTE: If you disconnect from the broker, you will need to reconnect again\n\nCreate an __Inject__ node with following:\n\n- `msg.action` = `disconnect`\n\nand connect to this node\n\n## Reconnect to Internal MQTT Broker\n\nCreate an __Inject__ node with following:\n\n- `msg.action` = `connect`\n\nand connect to this node\n\n## Unsubscribe from MQTT Topics\n\nCreate an __Inject__ node with following:\n\n- `msg.action` = `unsubscribe`\n- `msg.topic` = (select boolean) `true`\n\nand connect to this node",
    "category": "custom-nodes",
    "in": [
        {
            "x": 220,
            "y": 100,
            "wires": [
                {
                    "id": "cd6f53791302e5d9"
                }
            ]
        }
    ],
    "out": [
        {
            "x": 560,
            "y": 100,
            "wires": [
                {
                    "id": "cd6f53791302e5d9",
                    "port": 0
                }
            ]
        }
    ],
    "env": [],
    "meta": {
        "module": "subflow-mqtt-common",
        "type": "mqtt-internal-in",
        "version": "0.1.0",
        "author": "Shantanoo \"Shan\" Desai <sdes.softdev@gmail.com>",
        "desc": "MQTT In Node for Internal MQTT Broker",
        "keywords": "mqtt, subflows",
        "license": "Apache-2.0"
    },
    "color": "#F3B567",
    "icon": "node-red/bridge.svg",
    "status": {
        "x": 540,
        "y": 180,
        "wires": [
            {
                "id": "cd6f53791302e5d9",
                "port": 0
            }
        ]
    },
    "flow": [
        {
            "id": "cd6f53791302e5d9",
            "type": "mqtt in",
            "z": "45db115760787ca3",
            "name": "Internal MQTT Broker In",
            "topic": "",
            "qos": "2",
            "datatype": "auto",
            "broker": "1e34472ea3f09540",
            "nl": false,
            "rap": true,
            "rh": 0,
            "inputs": 1,
            "x": 390,
            "y": 100,
            "wires": [
                []
            ]
        },
        {
            "id": "1e34472ea3f09540",
            "type": "mqtt-broker",
            "z": "45db115760787ca3",
            "name": "Internal MQTT Broker In Node",
            "broker": "internal-mqtt-broker",
            "port": "1883",
            "clientid": "red-client-mqtt-internal-in",
            "autoConnect": true,
            "usetls": false,
            "protocolVersion": "4",
            "keepalive": "60",
            "cleansession": true,
            "birthTopic": "",
            "birthQos": "0",
            "birthPayload": "",
            "birthMsg": {},
            "closeTopic": "",
            "closeQos": "0",
            "closePayload": "",
            "closeMsg": {},
            "willTopic": "",
            "willQos": "0",
            "willPayload": "",
            "willMsg": {},
            "sessionExpiry": "",
            "credentials": {
                "user": "",
                "password": ""
            }
        }
    ]
}

package.json

{
    "name"         : "node-red-mqtt-subflows",
    "version"      : "0.1.0",
    "description"  : "Custom MQTT Nodes for Distinct Broker using node-RED Subflows",
    "dependencies": {
        "node-red": ">=2.2.0"
    },
    "keywords": [ "node-red" ],
    "node-red"     : {
        "version": ">=2.0.0",
        "nodes": {
            "custom-nodes-internal-mqtt-in": "node-red/subflows/custom-nodes-internal-mqtt-in.js",
            "custom-nodes-internal-mqtt-out": "node-red/subflows/custom-nodes-internal-mqtt-out.js"
        }
    },
    "scripts": {
        "start": "node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS --userDir=/data"
    }
}

Dockerfile

FROM nodered/node-red:2.2.2

# Copy all node-red related files
COPY . /data

RUN npm install --unsafe-perm --no-update-notifier --no-audit --only=production /data

Result

Everything compiles great and I can see the nodes under custom palette I have created called custom-nodes however upon connecting an inject and debug node I get the following error:

node-red              | 25 Apr 19:09:46 - [error] [mqtt-internal-in:Internal MQTT Broker In] missing broker configuration
node-red              | 25 Apr 19:10:21 - [error] [mqtt-internal-out:MQTT Internal Broker Out] missing broker configuration

The configuration already exists in the flow array however it is not recognized

Related Queries

Hack / Solution

the Only possible solution is to export all the subflows as a single JSON and pack these flows into /data/flows.json

This maintains the MQTT configuration and one is able to connect to MQTT Broker.

node-red/flows.json

add the flows.json to the node-red/ directory

[
{
        "id": "45db115760787ca3",
        "type": "subflow",
        "name": "internal mqtt in",
        "info": "# Internal MQTT In Node\n\nAutomatically connects to the Internal MQTT Broker and subscribes to User-Defined MQTT Topics\n\n## Subscribe to MQTT Topics\n\nCreate an __Inject__ node with following:\n\n- `msg.action` = `subscribe`\n- `msg.topic` = `YOUR/TOPIC/HERE`\n\nand connect to this node\n\n## Disconnect from Internal MQTT Broker\n> NOTE: If you disconnect from the broker, you will need to reconnect again\n\nCreate an __Inject__ node with following:\n\n- `msg.action` = `disconnect`\n\nand connect to this node\n\n## Reconnect to Internal MQTT Broker\n\nCreate an __Inject__ node with following:\n\n- `msg.action` = `connect`\n\nand connect to this node\n\n## Unsubscribe from MQTT Topics\n\nCreate an __Inject__ node with following:\n\n- `msg.action` = `unsubscribe`\n- `msg.topic` = (select boolean) `true`\n\nand connect to this node",
        "category": "custom-nodes",
        "in": [
            {
                "x": 220,
                "y": 100,
                "wires": [
                    {
                        "id": "cd6f53791302e5d9"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 560,
                "y": 100,
                "wires": [
                    {
                        "id": "cd6f53791302e5d9",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "meta": {
            "module": "subflow-mqtt-common",
            "type": "mqtt-internal-in",
            "version": "0.1.0",
            "author": "Shantanoo \"Shan\" Desai <sdes.softdev@gmail.com>",
            "desc": "MQTT In Node for Internal MQTT Broker",
            "keywords": "mqtt, subflows",
            "license": "Apache-2.0"
        },
        "color": "#F3B567",
        "icon": "node-red/bridge.svg",
        "status": {
            "x": 540,
            "y": 180,
            "wires": [
                {
                    "id": "cd6f53791302e5d9",
                    "port": 0
                }
            ]
        }
    },
    {
        "id": "cd6f53791302e5d9",
        "type": "mqtt in",
        "z": "45db115760787ca3",
        "name": "Internal MQTT Broker In",
        "topic": "",
        "qos": "2",
        "datatype": "auto",
        "broker": "1e34472ea3f09540",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 1,
        "x": 390,
        "y": 100,
        "wires": [
            []
        ]
    },
    {
        "id": "1e34472ea3f09540",
        "type": "mqtt-broker",
        "z": "45db115760787ca3",
        "name": "Internal MQTT Broker In Node",
        "broker": "internal-mqtt-broker",
        "port": "1883",
        "clientid": "red-client-mqtt-internal-in",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": "",
        "credentials": {
            "user": "",
            "password": ""
        }
    },
    {
        "id": "ced02ad71788907a",
        "type": "subflow",
        "name": "internal mqtt out",
        "info": "# Internal MQTT Out Node\n\nAutomatically connects to the Internal MQTT Broker and publish to User-Defined MQTT Topics\n\n## Subscribe to MQTT Topics\n\nCreate an __Inject__ node with following:\n\n- `msg.topic` = `YOUR/TOPIC/HERE`\n\nand connect to this node\n\n## Disconnect from INternal MQTT Broker\n\n> NOTE: If you disconnect from the broker, you will need to reconnect again. \n\nCreate an __Inject__ node with following:\n\n- `msg.action` = `disconnect`\n\nand connect to this node\n\n## Reconnect to Internal MQTT Broker\n\nCreate an __Inject__ node with following:\n\n- `msg.action` = `connect`\n\nand connect to this node",
        "category": "custom-nodes",
        "in": [
            {
                "x": 160,
                "y": 180,
                "wires": [
                    {
                        "id": "f40d0dbc09407cae"
                    }
                ]
            }
        ],
        "out": [],
        "env": [],
        "meta": {
            "module": "subflow-mqtt-common",
            "type": "mqtt-internal-out",
            "version": "0.1.0",
            "author": "Shantanoo \"Shan\" Desai <sdes.softdev@gmail.com>",
            "desc": "MQTT Out Node for Internal Broker",
            "keywords": "mqtt, subflows",
            "license": "Apache-2.0"
        },
        "color": "#F3B567",
        "icon": "node-red/bridge.svg"
    },
    {
        "id": "4afe4316918f609c",
        "type": "mqtt-broker",
        "z": "ced02ad71788907a",
        "name": "Internal MQTT Broker Out Node",
        "broker": "internal-mqtt-broker",
        "port": "1883",
        "clientid": "red-client-mqtt-internal-out",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": "",
        "credentials": {
            "user": "",
            "password": ""
        }
    },
    {
        "id": "f40d0dbc09407cae",
        "type": "mqtt out",
        "z": "ced02ad71788907a",
        "name": "MQTT Internal Broker Out",
        "topic": "",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "4afe4316918f609c",
        "x": 390,
        "y": 180,
        "wires": []
    }
]

Dockerfile

FROM nodered/node-red:2.2.2

# Copy all node-red related files
COPY node-red/flows.json /data/flows.json
COPY package.json .

RUN npm install --unsafe-perm --no-update-notifier --no-audit --only=production

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