The magic happens in lines 5 and 6 where the query is formed with all the variables. The topic is hard coded as a string to make this simple. In this example we are expecting a float so we will parseFloat(msg.payload) and store it in a var. Msg.payload can be called to get the MQTT message. The function will take the message from the MQTT node and create an SQL queries that it will send to the mysql node which will process the query. Make connections from the MQTT to the function and from the function to the mysql. To do that we need to add a function node and a mysql node which was installed earlier.
![unraid plugins to get unraid plugins to get](https://images.anandtech.com/doci/9463/carousel_678x291.jpg)
You can do whatever you want with the message, but in this example we will be storing it in a SQL table. When a message does come through the node will output it. This will bring you back to the grid.Īt this point we have set up the connection to the MQTT broker and set up a node to listen for a specific topic. I usually use most of the Topic since it already tells me what this node is doing. Auto-detect is default and should work in most uses. Enter one of the Topics that you would like this node to listen for.In the properties tab you can now set up the MQTT node: This will add this MQTT broker to the server list and bring you back to the properties tab. Fill in the connection and security details based on your setup and click the red “Add” button in the top right.This should bring you to the properties tab. In the Server Line, open the drop down and click “Add new mqtt-broker…” and click on the edit pencil to the right.The “Edit mqtt in node” window should come up. To set up the MQTT node first we will have to set up the server connection: When there is a message on this topic it will be output by the node. The MQTT node will connect to an MQTT broker and listen for a specific topic. Start off by finding the MQTT node in the left hand frame.
Unraid plugins to get install#
When you find it click on install and close out the settings window.
![unraid plugins to get unraid plugins to get](https://i.ytimg.com/vi/2CbObOuOEuA/maxresdefault.jpg)
Click on the “Install” tab and search for “node-red-node-mysql”. In the “Settings” window click on “Palette”. Click on the three horizontal lines at the top right to open the menu bar. Once in Node-Red you will have to install a “Palette” (basically a plugin for additional feature). After installation go ahead and open up Node-Red. MQTT supports passwords but if all your devices are local and not connecting to the broker through the internet (and you haven’t enabled port forwarding) you can skip the passwords.Īfter the MQTT broker is installed and setup you can go ahead and install Node-Red which is also in the Unraid the Community Applications (plugin). If you need to be able to connect browsers to the MQTT broker then forward port 9001 as well). Port 9001 is for Websocket connection (b rowsers can’t speak MQTT but they do support websockets. Optionally you can also forward port 9001. If you are just using MQTT you’ll need to forward port 1883 to the local IP of the Unraid server. If you want the MQTT broker to be accessible from the internet you will have to set up port forwarding on your router. Just find it in the Community Applications (plugin) and hit install. Instead of a simple JS that inserted each message into the MySQL server I am now using Node-Red which makes it much simpler to store the MQTT data. I have since moved the MQTT broker and MySQL server to an Unraid server. After a while the SQL tables get too large and the queries take too long due to the limited processing power of the system. I used to use Mosquitto and some simple JS on a Synology 2-Bay NAS. Instead of using an online MQTT broker service you can self host it.