###### tags: `TA Stuff ESP32` # Part 4: Installing and using Node-Red This is an extra topic which means that it is NOT mandatory in any way. It is mentioned only because it might be a good solution that fits your project. ### Before starting This tutorial should provide you with some help to install and use Node-Red which is a flow-editor that is based on Nodejs and is browser based. You can use it to integrate a multitude of different devices and services as well as creating your own functions. There are also many so called palettes which are groups of nodes that you can download and install to get more nodes that serve a specific function. Overall Node-Red is very powerful but more importantly easy to get used to. ## Installing Node-Red Node-Red has a great guide on how to install it on different operating systems. There is also a docker container if you want to go down that path. So follow the steps in this [tutorial](https://nodered.org/docs/getting-started/local) to install Node-Red and then you might also want to check the [Securing Node-RED](https://nodered.org/docs/user-guide/runtime/securing-node-red) guide if you are concerned about security. You do not necesserly have to enable HTTPS (if you are on your home network) but it is recommended to enable it later on. It is a good idea however to configure the login credentials. If your run into an error that says something like "running scripts is disabled" try running `Set-ExecutionPolicy -ExecutionPolicy RemoteSigned` in powershell as admin, type **Y** and press enter. (Do it at your own risk). ## Using Node-Red Using Node-Red should be straight forward. You are supplied with some nodes that perform different function right from the begining but you can also install more nodes that provide different integreations such as writing to an [Influxdb](https://www.influxdata.com/) database or sending a message on [Telegram](https://telegram.org/). Node-Red also provides a greate [user guide](https://nodered.org/docs/user-guide/) that goes through what node-red is capable, and they also have a [concepts](https://nodered.org/docs/user-guide/concepts) page that expalins what each concept means. ### Core nodes Looking at the [Core Nodes](https://nodered.org/docs/user-guide/nodes) page you can see that the "inject" node has no connection box on the left side, that is because it does not take any input and the flow will be going from left to right. It does however have an output connection which will connect to the next node which will have data injected into from the "inject" node. The opposite applies to the "debug" node. It has an input connection but no ouput. The debug info will be presented at the debug window on the right sidebar.  Although the "inject" and "debug" nodes are input/output only respectively, it does not mean that you are restricted to only one input and one output. In fact you can have multiple inputs and outputs which allows you to create very complex flows with many different debug points that do not stop the flow itself. In the picture below you can see that we have 2 inputs and 3 outputs with 2 different debug nodes that will be debuging 2 different members of the msg object. The flow will be ouputing to the debug node, MQTT as well as UDP.  So you can for example have a flow that: 1. Takes input from MQTT 2. Does some formating/parsing/processing 3. Stores the data to a database 4. Checks if a certain condition applies 5. Sends an alarm message if the condition applies or maybe sends a new MQTT message to an applience to turn it on. There are also some nodes that allow for easy control of the amount of messages sent down the flow. Which is very useful incase you decide to send messages to your smartphone since you will be avoiding spam. It can also be used to restrict the amount of data stored in the database. ### The function node The function node is a core node that is super useful and powerful due to the fact that it allows you to write your own functions that manipulate the msg object that holds that data the runs in the flow. This means that you can read/format/parse/modify the data or payload before it goes to the next node. Maybe you are sending temeprature and humidity data on MQTT as a string in the format ("30.5,43.7") then you can use the function node to parse the data and convert it to two floats and then store it in the database as two different floats. The programming language used in the function node is javascript which means that you have access to a good collection of functions that help you parse and format data. It is also a loosely typed language which means that you do not have to specify the type of the data you are storing just like in python. In difficulty both python and javascript are considered to be easier to learn for beginners. Check the [W3 javascript page](https://www.w3schools.com/js/DEFAULT.asp) to learn more about the language. ## Deploying Once the flow is done you can click the deploy button to enable the flow. However it is always a good idea to not have any data written immediately to the database. Instead use a debug node to confirm that the data is in the correct format and is coming in at the correct rate. Also you should use a limiting node even if you data rate is restricted before coming into Node-Red since it will provide an extra layer of security to prevent flooding the database with too much junk data. Any changes made to the flow will need to be re-deployed. If you try to close the borwser Node-Red will warn you for unsaved changes if you have not deployed your latest flow. Beware however that changing the position of the nodes without changing the actual connections is also considered a modification that prompts a save so you do not always have to save if you have not done any actual modification. ## Installing palettes Although Node-Red have good collection of very useful core nodes they will not be enough for most of your project. Luckily we can use the palette manager to install pallets that will give us more nodes that provide different function and integrations such as MQTT in and out nodes or even HTTP ones. We also can install InfluxDB pallets to be able to store data in an influxDB database. It is always a good idea to check for palettes since it is very likely that a palette already exists that will make what you are doing easier. To install a new pallet we go to the palette manager by clicking on the humburger menu on the right top corner of the screen near the deploy button. From there you should click on the "Manage palette" option.  From there you will get a window that will list all the curently installed palettes. You then can click on the "install" tab to search for a palette to download. We can type "influxdb" in the search to get a search result from which we pick the first one and click on the install button.  After we install a palette we will get the nodes that this palette provides. We can then drag and drop them into our workflow just like any other Node-Red node. You might still want to check the webpage of the palette to get an idea on how to use the nodes provided. ## Summary All in all Node-Red should be easy to install and relatively easy to get used to. You will need to learn a little javascript but it will not be that big of problem since you most likely are not going to need to write logic code, only data manipulation since the logic part is done through the different nodes you have at hand. You also have access to more nodes online that you can download that makes life easier. Hope you give it a try if you think that it is something that adds value to your project and if so make sure to let us know how it went 🤩
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up