Skip to content

Commit

Permalink
Merge pull request #1196 from FlowFuse/core-mqtt-websocket
Browse files Browse the repository at this point in the history
Add docs for MQTT and WebSocket nodes
  • Loading branch information
ZJvandeWeg authored Oct 3, 2023
2 parents 6266270 + c2178e2 commit cb80339
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/_includes/core-nodes/mqtt-use-case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## What is are MQTT nodes used for in Node-RED

Node-RED comes with 2 MQTT nodes.

### MQTT-in

The MQTT-in node is used to subscribe to a topic pattern on a given MQTT broker. This means messages published to a topic that matches the pattern will be delivered to the flow by this node.

### MQTT-out

The MQTT-out noe is used to publish messages to a topic from the flow.

### Configuring

Both of the nodes mentioned above make use a configuration node which holds all the details about connecting to a given MQTT broker. This includes things like:

- hostname
- port
- username/password

![MQTT Config Node](./images/mqtt-config.png)

Node-RED supports MQTT v3.x and v5 as well as allowing connecting to
brokers using both native MQTT and MQTT over WebSockets.

## Examples

Simple publish and subscribe

![MQTT Node Example](./images/mqtt-example.png)

```json
[{"id":"a149bb66646389a3","type":"tab","label":"MQTT Example","disabled":false,"info":"","env":[]},{"id":"bb79f2f114f79b39","type":"mqtt in","z":"a149bb66646389a3","name":"","topic":"ff/#","qos":"0","datatype":"auto-detect","broker":"037ca6b6ca0d7699","nl":false,"rap":true,"rh":0,"inputs":0,"x":210,"y":160,"wires":[["75dbd3c2f8e97550"]]},{"id":"cbc885829f5cf0dc","type":"mqtt out","z":"a149bb66646389a3","name":"","topic":"ff/test","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"037ca6b6ca0d7699","x":490,"y":100,"wires":[]},{"id":"f2641dab58edbc70","type":"inject","z":"a149bb66646389a3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":100,"wires":[["cbc885829f5cf0dc"]]},{"id":"75dbd3c2f8e97550","type":"debug","z":"a149bb66646389a3","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":500,"y":160,"wires":[]},{"id":"037ca6b6ca0d7699","type":"mqtt-broker","name":"","broker":"test.mosquitto.org","port":"1883","clientid":"","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":{},"userProps":"","sessionExpiry":""}]
```

Cheerlights

```json
[{"id":"0e7402215650517c","type":"mqtt in","z":"a149bb66646389a3","name":"","topic":"cheerlights/coloured/hex","qos":"2","datatype":"auto-detect","broker":"037ca6b6ca0d7699","nl":false,"rap":true,"rh":0,"inputs":0,"x":190,"y":300,"wires":[["6173b5c60df9bfee"]]},{"id":"6173b5c60df9bfee","type":"debug","z":"a149bb66646389a3","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":480,"y":300,"wires":[]},{"id":"037ca6b6ca0d7699","type":"mqtt-broker","name":"","broker":"test.mosquitto.org","port":"1883","clientid":"","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":{},"userProps":"","sessionExpiry":""}]
```
20 changes: 20 additions & 0 deletions src/_includes/core-nodes/websocket-use-case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## What is are WebSocket nodes used for in Node-RED

Node-RED comes with 2 WebSocket nodes, both of which can work in 2 modes

### Listen on

In this mode Node-RED will create a WebSocket server and allow remote clients to connect.

The `WebSocket-in` node will receive messages sent from the remote client and the `WebSocket-out` allows the flow to send messages either to a specific connected client or to broadcast to all connected clients

### Connect to

In this mode Node-RED connects out to a remote WebSocket server.

The `WebSocket-in` node receives messages sent to Node-RED and the `WebSocket-out` node allows the flow to send messages to the remote server.

## Examples

```json
```
Binary file added src/node-red/core-nodes/images/mqtt-config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit cb80339

Please sign in to comment.