Choose between MQTT TLS and non TLS dynamically

This little flow demonstrates how we can switch between TLS and non TLS MQTT connection using the action and broker properties of the MQTT node.

[{"id":"83769724846c8526","type":"mqtt out","z":"175d2f09646e55cd","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"6c399a60e1ec5aa4","x":630,"y":120,"wires":[]},{"id":"fc809e89a72be105","type":"inject","z":"175d2f09646e55cd","name":"Connect TLS","props":[{"p":"action","v":"connect","vt":"str"},{"p":"broker","v":"{\"usetls\": true, \"port\": 8883}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":410,"y":120,"wires":[["83769724846c8526"]]},{"id":"caaf24765db1e4dc","type":"inject","z":"175d2f09646e55cd","name":"Connect nonTLS","props":[{"p":"action","v":"connect","vt":"str"},{"p":"broker","v":"{\"usetls\": false, \"port\": 1883}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":420,"y":160,"wires":[["83769724846c8526"]]},{"id":"b330f2cf6c518a45","type":"inject","z":"175d2f09646e55cd","name":"Disconnect","props":[{"p":"action","v":"disconnect","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":410,"y":240,"wires":[["83769724846c8526"]]},{"id":"6c399a60e1ec5aa4","type":"mqtt-broker","name":"","broker":"test.mosquitto.org","port":"","clientid":"","autoConnect":false,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

Flow Info

Created 1 year, 4 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • inject (x3)
  • mqtt out (x1)
  • mqtt-broker (x1)

Tags

  • MQTT
  • TLS
  • SSL
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option