I am getting to grips with the concept of Dynamic MQTT connections and related Pub/Sub. However I am curious as to whether it would be possible to use the same Inject Node to do the following:
- Force connect to an MQTT broker
- Subscribe to a desired topic
I tried doing the following within an inject node:
-
msg.action
set toconnect
-
msg.broker
set to{"broker": "internal-mqtt-broker", "port":1883, "force":true}
-
msg.action
set tosubscribe
-
msg.topic
set to$SYS/#
Upon deploying the flow, the inject node is not able to connect to the Broker.
Logs:
node-red | 20 Apr 19:55:55 - [info] Server now running at http://127.0.0.1:1880/
node-red | 20 Apr 19:55:55 - [info] Starting flows
node-red | 20 Apr 19:55:55 - [info] Started flows
node-red | 20 Apr 20:00:47 - [info] Stopping flows
node-red | 20 Apr 20:00:47 - [info] Stopped flows
node-red | 20 Apr 20:00:47 - [info] Starting flows
node-red | 20 Apr 20:00:47 - [info] Started flows
Flow Diagram:
Inject Node Properties
Whereas upon removing the subscribe action and topic from the Inject node, I am able to connect to the broker and subscribe to a topic via a separate node.
Would there be some way to merge the connection + subscription actions of the node into one node?