-
-
Notifications
You must be signed in to change notification settings - Fork 8
NodeRed MQTT Setup
This is a simple how-to on setting up a Rasperry Pi node, attempting to be as copy/pastable as possible. As we stand on the shoulders of giants, I will refer to external how-tos for some of the steps. They did it better than I could anyway.
- a multicore raspberry pi. Though you can run it on a classic raspi 2/pi zero w, a pi zero 2 is the minimum for stablility.
- a recent version of raspberry pi os.
Just like it says on the tin. Throughout this, I will use some conventions assuming you used the hostname Solar, the username is Solar, and the password is SolarPowered. The rest of this doc assumes you are SSHed in using PuTTY (for windows users) or a terminal of your choice (for the rest of us heathens). The hostname will be solar.local
, username solar
, and password SolarPowered
sudo apt update && sudo apt upgrade && sudo apt install tmux git mosquitto nginx
Using your favorite text editor, add these lines to /etc/mosquitto/mosquitto.conf
listener 1883
allow_anonymous false
password_file /etc/mosquitto/passwd
Create a new mosquitto
password file while adding an mqtt user sudo mosquitto_passwd -c /etc/mosquitto/passwd solar
- to add another user later, drop the -c
. Start the service with sudo systemctl start mosquitto
, set the service to start on boot with sudo systemctl enable mosquitto
.
mkdir ~/src/ && cd ~/src && git clone https://github.com/HotNoob/PythonProtocolGateway.git
Install how-to - As of the 6 August 2024, you can just paste in bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
- Log in.
- Click the hambuger menu.
- Go to
Manage palette
. - Under the
Install
tab, search for@flowfuse/node-red-dashboard
. ClickInstall
. - Optional: Under the
Install
tab, search fornode-red-contrib-influxdb
, clickInstall
.
If you want to do some historical logging, InfluxDB is a better solution than the node-red internal db.
- Install influx
sudo apt install influxdb influxdb-client && sudo systemctl enable influxdb && sudo systemctl start
- Create the
solar
db in influxecho "CREATE DATABASE solar" | influx
- Drag an
InfluxDB Out Node
out into the workspace, connect a wire from themqtt in
node to theInfluxDB Out
node. Double click the node, click the+
, give it a name and the name of the database from above (solar). Click add. It will return you to the node setup, where you will give it a name and a measurement (solar
in my setup), clicksave
ordone
.
Go to the hamburger, down to Import
, click select a file to import
, find nodered-example-flow.json
in the repo. You should be left with something like this.
- Drag a
debug
node out - we will be using this throughout to see how the data flows. You can see the debug output by dragging a wire from an output to the debug's input and turning it on. - Drag an
mqtt in
node out to the workspace. click the pencil to create a new mqtt-broker-node. Give it a name, enter the hostname in the server field (solar.local
in our example), click security, add the username and password, clickadd
orfupdate
. UnderTopic
, enterhome/inverter
. Click done. - Drag a json node out onto the workspace, connect the input (left) side of the
json
node to the output of themqtt in
node. - For each of the things you want on the dashboard, add in a
function
node. This is to filter out the thing you want displayed, in this example, battery percentage. Drag a wire from thejson
node to the function you just created.
msg.payload = parseInt(msg.payload.battery_percentage);
return msg;
click done.
4. From here on out, you will be setting up the wigets you want to see. Checkout the flowfuse dashboard wiki for more info. For each of the functions you just created, create a chart
, gauge
, or text
node to display the things the way you want them displayed. You will need to create a group and page node on the first, the ui will help you throuhg that.
Use sudo and your favorite editor to edit /etc/nginx/sites-enabled/default
. jump down to the server_name _
section and replace everything between the {
and }
so it's like below.
location / {
include proxy_params;
rewrite ^/(.*) /dashboard/$1 break;
proxy_pass http://127.0.0.1:1880;
}
You should now be able to browse to Solar.local/Home
source: https://github.com/yNosGR/PythonProtocolGateway/blob/NodeRed_howto/NodeRed.MD