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