This is a basic setup guide to install a Node-Red server with MQTT to use for your home IoT. I used a Raspberry 3A+ I had - this works plenty. You can also do this on a Raspberry B+.
First stop: get Liunux on that Raspberry.
Go to https://www.raspberrypi.org/downloads/raspbian/ and download the Raspbian Buster Lite image.
Insert your Micro SDHC card in your computer and use a tool to burn the IMG. I have a MAC and use balenaEtcher. Very simple: card - select IMG and press Flash!
When it's ready you need to prepare a few things before ejecting the card. As the Raspberry 3A+ has Wifi only it needs a config file. If you want to find info about it search for 'raspberry headless'.
Create a file in the root of the SD card. On a Mac open terminal and use:
touch /Volumes/boot/wpa_supplicant.conf
Open it with a text editor and insert:
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=BE
network={
ssid="your ssid"
psk="your password"
}
Replace country code with your country ISO code, SSID and password. Save it.
Then you need to add a blank file to the root called: ssh
On a MAC you can open terminal and run:
touch /Volumes/boot/ssh
This will enable SSH when the raspberry boots.
Insert the card in the Raspberry and wait for about 2 to 3 minutes.
Check your wifi router to find the IP of the new device. It should also show the host raspberrypi.local. Use Putty or similar to connect. I use Termius as I'm on a Mac.
Connect to the IP with SSH.
User: pi
password: raspberry
Update the setupFirst thing is to update the setup. Confirm with 'y' when asked.
sudo apt-get update
sudo apt-get upgrade
Then use
sudo raspi-config
A basic UI appears. Change the following here:
1 - user password
2 - network options - host name
4 - localisation options - change timezone
7 - advanced options - expand filesystem
Reboot... this should take more than 30 seconds.
Node-redMain info can be found here: https://nodered.org/docs/getting-started/raspberrypi
First run this to ensure all the build tools have been installed (the haven't normally)
sudo apt install build-essential git
then run this
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
You should see a progress like this:
Pfew - this is easy no? Almost there.
Ok next is to update node-red first
A Raspberry 3A+ only has 512Mb RAM. To optimize memory usage you need to adapt the node-red startup config.
sudo nano /lib/systemd/system/nodered.service
Find the line where it says 512 and change it to 256.
Save (CTRL-O) and exit (CTRL-X).
Then save and configure the startup so that nod-red starts automatically:
sudo systemctl enable nodered.service
Then you can manually start node-red (node-red-start) now or reboot. If you manually start you'll see thet node-red service load. Once done you don't return to the command line. Use CTRL-C to get out. The server still runs, don't worry.
Once that is done check that the interfaces are running and the correct ports are open.
netstat -lnt
In the list you should see the ports 22 and 1880 opened.
Ok you can then use your browser to connect to the node-red service for the first time. Use the local IP you got and connect to port 1880
You should see something like this:
Node-red has some strange terminology I find, but on the hamburger menu on the right you'll find different options. Select Manage Palette. These are your extensions you have loaded or where you install new ones.
Install the following ones:
- node-red-contrib-aedes. (mqtt)
- node-red-dashboard
- node-red-contrib-ui-artless-gauge
- node-red-contrib-ui-led
- node-red-contrib-simpletime (simple timer)
- node-red-contrib-huemagic (Philips Hue)
If you get errors check the dependencies or try
sudo apt --fix-broken install
Sometimes in your node-red configuration screens you will need to supply credentials. If you want to maintain these after you reboot you pi, best to set a user configured credentialSecret.
sudo nano ~/.node-red/settings.js
Look for credentialSecret
remove the // and insert your personal secret key.
Finally shutdown your pi, take out the SD card and use your pc or Mac to make a backup. WindiskSD for windows or ApplePiBaker is what I use on Mac.
Re-insert the SD and read this chapter: https://nodered.org/docs/user-guide/runtime/securing-node-red
My node-red is not exposed to the internet and I don't intend to. I use Telegram with a private bot for the few operations that I would do while not at home. I suggest you do the same unless you secure the device as detailed in the document mentioned above.
MQTTOpen node-red drag the Aedes block on the Flow:
Here you have the Aedes broker running.
A Switch (eSPURNA device)
Switch on the UI:
and output back to MQTT to activate the device:
On the device itself you have
Or similar for a Shelly:
We'll I -think- this is it and you should have your node-red with mqtt up and running.
A handy tool is to also have at hand is MQTT Explorer.
Also look at flow that other people made - some amazing stuff here:
And finally how to install the Dark theme I use: https://flows.nodered.org/flow/eb9a4d44f72b0755aa3e14055fb3eacb
I'm not at all a linux specialist - far from, so please if you see something incorrect or have any other tips, let me know.
thanks
Comments
Please log in or sign up to comment.