Rather than use an external broker like mosquitto with node-red you can install the Aedes node which is a MQTT broker written in node.js.
Because Aedes isn’t part of the core nodes you need to install it using the npm package manager or through the Node-red Admin control panel.
Note: Aedes replaces the Mosca broker.
Aedes Install Using Node-red Admin
In the node-red admin go to Settings and manage Pallette.
Click on the install tab and search for aedes.
After the install you should find a new node called aedes under the network categories.
Drag and drop on the Canvas to use.
Aedes Node Configuration
The node properties has two tabs connections and security,and with very few settings.
The main tab is show below:
You need to set the ports for standard MQTT and MQTT over websockets if used.
There is an option to enable SSL and if you do that then your are able to upload certificates.
You will need to upload the server.crt and the server.key files as shown in the screen shot below:
If you enable SSL then it is enabled for MQTT and MQTT over websockets, if configured. In the above screenshot the SSL port is 1883. So the possible configurations are:
- MQTT + Websockets
- MQTT (SSL)+ Websockets(SSL)
That means that you cannot run MQTT and MQTT(SSL) on the broker. You also need to have the MQTT port configured but websockets is an option.
The security tab contains options for username and password. These fields I understand are for the mongodb database,and you can usually leave them blank even when using the database.
The mongo database is used for persistent data and is usually as shown in the screenshot.
Note: If it appears greyed out then it is not being used.
Persistent data stores unsent messages,subscribes and retained messages so they are remembered if the server is restarted.
To use it you will need to have the mongodb server installed on your system.
Important Note: This isn’t the mongodb node. The node is a connector to a database server and not the server itself.
You will need to install the mongodb database server separately it is not a node-red node.
Testing The Install
You can use any MQTT client for testing the broker.The easiest is to use the MQTT input and output nodes.
Here is a screen shot of my test flow:
Here is the flow code which you can import into your own flow:
Video- How to Install The Mosca MQTT Broker on Node-Red
In case you are worried about performance I did a quick check using my node-red broker tester with a message rate of 100 messages/sec and it didn’t record any errors. The screenshot below show the result
Note The Aedes broker was also running on the same node-red instance as the test software.
The Node-Red Aedes node replaces the Mosca node and is useful for testing, it may also be useful for small home automation networks.
It is not really suitable for a production environment as it lacks many of the features like ACL (access control lists), authentication, message limits) that the mosquitto broker has.
However the message throughput seems to be very good.
Related Tutorials and Resources
- MQTT Hosting, Brokers and Servers
- Using the MQTT publish and subscribe Nodes
- Node-Red HTTP Request Node for Beginners