Setting up a Live/Prod and a Development System

I have two environments running on two seperate RPI's. RPI-14 and RPI-15.
I have a very basic sprinkler system on 14 that uses an ESP32 to control the valves. (just on off for now).
I setup a second esp32 for testing and I'm trying to connect to RPI-15. The flows from 14 where all exported then imported to 15. I changed all the Nodes to use RPI-15 as the broker.
I hope there's and easier way to do this.
The second esp32 will not connect to the second broker, the dashbaord for api-15 shows no connections.
This is my first system that I have running, I am a newby with Node-red.
Version 3.0.2
Any thoughts are appreciated?

Welcome to the forum @DonRacz

How does the esp talk to the pi? MQTT for example?

Exactly what is it that shows not connected?

Yes, It uses MQTT to connect from ESP32..
On the DashBoard every MQTT In and MQTT out shows a little yellow box with the word "connecting". I can't send a picture because I'm a new user.
On the debug terminal from the ESP32 it shows
23:49:48.164 -> Attempting MQTT connection...
23:49:48.211 -> failed, rc=-2 try again in 5 seconds

Are you trying to connect to a broker on the same pi that is running node red? If so, have you installed a broker such as mosquito? If so, how did you install it?

... which by default does not expose a public port unless you remember to configure it.

But that would not stop node-red from connecting to a broker on localhost.
Clarification is required from @DonRacz

I thought it blocked anonymous connections locally as well ?

No, I have just tested it to check, with mosquitto 2.0.15. Local anonymous connections are allowed by default.

2 Likes

That confused me slightly as well, when I thought about it. With version 2 if you want to access it remotely then, as we know, it is necessary to configure it with
listener 1883
If that is not configured then it is only possible to connect locally (with or without user/pwd). However once the listener line is added then it is also necessary to specify
allow_anonymous true
to access without user/pwd, even when accessing locally.

2 Likes

Both RPI's have Mosquitto and NodeRed and the NodeRed Dashboard installed and running on them.

I have a list of commands that I use to install both so they are as Identical as I can make them.
Is there a script or a program that can do the move. I'm guessing there must be something to move a the flows thru a "normal" development cycle.

Thx

Once you work out what is not working then you will know what is missing.
Are you using user names/pwds for mqtt? If so then check that has been setup correctly.
Otherwise stop node red and start it again in a terminal and post the startup log here. Assuming that you installed using the recommended method you can see that by running
node-red-stop
node-red-start

Starting as a systemd service.
7 Sep 10:36:46 - [info]
Welcome to Node-RED

7 Sep 10:36:46 - [info] Node-RED version: v3.0.2
7 Sep 10:36:46 - [info] Node.js version: v16.17.0
7 Sep 10:36:46 - [info] Linux 5.15.61-v8+ arm64 LE
7 Sep 10:36:47 - [info] Loading palette nodes
7 Sep 10:36:49 - [info] Dashboard version 3.1.7 started at /ui
7 Sep 10:36:49 - [info] Settings file : /home/pi/.node-red/settings.js
7 Sep 10:36:49 - [info] Context store : 'default' [module=memory]
7 Sep 10:36:49 - [info] User directory : /home/pi/.node-red
7 Sep 10:36:49 - [warn] Projects disabled : editorTheme.projects.enabled=false
7 Sep 10:36:49 - [info] Flows file : /home/pi/.node-red/flows.json
7 Sep 10:36:49 - [info] Server now running at http://127.0.0.1:1880/
7 Sep 10:36:49 - [warn]

Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.

7 Sep 10:36:49 - [info] Starting flows
7 Sep 10:36:49 - [info] Started flows
7 Sep 10:36:49 - [info] [mqtt-broker:c12152de73af6732] Connection failed to broker: mqtt://192.168.1.15:1883
7 Sep 10:37:04 - [info] [mqtt-broker:c12152de73af6732] Connection failed to broker: mqtt://192.168.1.15:1883
7 Sep 10:37:19 - [info] [mqtt-broker:c12152de73af6732] Connection failed to broker: mqtt://192.168.1.15:1883
7 Sep 10:37:34 - [info] [mqtt-broker:c12152de73af6732] Connection failed to broker: mqtt://192.168.1.15:1883
7 Sep 10:37:49 - [info] [mqtt-broker:c12152de73af6732] Connection failed to broker: mqtt://192.168.1.15:1883
7 Sep 10:38:04 - [info] [mqtt-broker:c12152de73af6732] Connection failed to broker: mqtt://192.168.1.15:1883
7 Sep 10:38:19 - [info] [mqtt-broker:c12152de73af6732] Connection failed to broker: mqtt://192.168.1.15:1883

pi@RPI-15:~/.node-red $ sudo systemctl status mosquitto

  • mosquitto.service - Mosquitto MQTT Broker
    Loaded: loaded (/lib/systemd/system/mosquitto.service; enabled; vendor preset: enabled)
    Active: active (running) since Wed 2022-09-07 09:46:04 MST; 1h 6min ago
    Docs: man:mosquitto.conf(5)
    man:mosquitto(8)
    Main PID: 3105 (mosquitto)
    Tasks: 1 (limit: 8986)
    CPU: 1.997s
    CGroup: /system.slice/mosquitto.service
    `-3105 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Sep 07 09:46:04 RPI-15 systemd[1]: Starting Mosquitto MQTT Broker...
Sep 07 09:46:04 RPI-15 systemd[1]: Started Mosquitto MQTT Broker.

What is the IP address of the pi?

In node red, change the broker address to localhost.

That may fix the node red issue, but not the esp connection.
What version of mosquito are you using in the other pi?

192.168.1.15
I changed to localhost.

Still won't connect.

is there a command to find the version number of nodered and mosquitto?

mosqitto on both machines is 2.0.11

node-red is now showing connected to mosquitto on 15
local host must have fixed that.

ESP32 still won't connect.

There was a listener entry in the mosquitto.conf file on 14 so I added it to the conf file on 15.
Both systems are now workng!

Colin, Thank you for your time. I learned alot working thru this with you.

Don

1 Like

If you add tripple backticks on separate lines before logs, code etc when posting it then it stops the forum from interpretting it as markdown which is why you have the strange effects in the node red startup log you posted.

The reason for that is that without the listener configuration you can't connect using an ip address, even if it is the ip of the same machine. It looks to mosquitto as if it is a remote connection so it blocks it.

On Linux, rather than adding the line to main config it is arguably better to put it in a separate conf file in /etc/mosquitto/conf.d. Conf files in there add to or override the main settings, but doing that has the advantage that an upgrade or re-install of mosquitto is not going to undo your changes. I add a file /etc/mosquitto/conf.d/mossy.conf containing

listener 1883
allow_anonymous true
log_timestamp true
log_timestamp_format %Y-%m-%d %H:%M:%S

Which allows remote access and also configures the mosquitto log to have human readable timestamps.
On systems where I have users/pwds then that setup goes in that file too.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.