Put it all together

I am trying to get a wi-fi mini ESP8266 sorted so at the end I can control it from any computer/ipad/iphone in my house. But as any newbe knows there are a lot of moving parts. Thats ok and I have worked thru most of them and I think ive got everything I need. BUT BUT- I dont seem to have it all talking to each other.

Like some others I get to the--
const char* mqtt_server = "localhost";
and I cannot get anything in "localhost" to work. I use IP of my computer, IP of the SP8266, IP of my router-no luck?

I am on a Windows 10 and using vscode ('cos it seems easier) I think I have the node-red config file ok- because it works on other than MQTT. I have mosquitto working- however I am not sure how to configure it. Installed MQTT Explorer and that all seems to work. So back to the start I seem to have everything but something is not talking.
How to I find out the problem?
Cheers Trev

What order do I start -
Plug in Arduino using mqtt_esp8266
node-red in terminal
mosquitto in terminal do I use start mosquitto

FROM THE ESP8266

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

// Update these with values suitable for your network.

const char* ssid = "MyWifi";
const char* password = "Mypassword";
const char* mqtt_server = "localhost"; // broker.mqtt-dashboard.com

just had another go and message in node-red is --
[mqtt-broker:44905650.f409f8] Connection failed to broker: mqtt://10.1.1.115:1883

from the start mosquitto Get a web page with just-
mosquitto

the 10.1.1.115 is the ip of computer I am on

localhost is an alias the points to the same device the code is running on. On the ESP you will need to use the ip address of the machine running your MQTT broker.

Yeh I realize that and that is my problem. I am running the MQTT broker on my computer. So how do I find IP of 'Machine' running the broker-thanks 'cos that is where problem is?

I assume thats the Windows 10 machine you mentioned? Or are you running it somewhere else?

I don't know how to find the IP address on Windows, but I'm sure google will come to your rescue.

Havnt been able to find straight forward answer yet. If I was using Raspberry etc etc- but a straight forward Windows 10 Desktop- not much. Should be just so easy itsa ESP8266 and I am sure many many people are using them. I would love to find the solution?

A google search for windows 10 get ip address gives me this:

https://support.microsoft.com/en-us/windows/find-your-ip-address-f21a9bbc-c582-55cd-35e0-73431160a1b9

Thanks heaps for your help- and I will try anything. However, I have been thru that and not the solution, Just went back and put in generic --
const char* mqtt_server = "broker.mqtt-dashboard.com";

and I dont get any errors in terminal node-red.- Gunna try in Dashboard again and see?

OK I have got a green connected-Thats good Mmm. And I will play with that for a while. But I dont want external 'server'--

const char* mqtt_server = "broker.mqtt-dashboard.com";

But maybe itsa starting point.

Thanks Heaps
Cheers Trev

When you say this, are you refering to the Win10 computer? And is this the machine that the mqtt broker is installed and running on?

If so, then in the arduino code you want to use

const char* mqtt_server = "10.1.1.115 ";

and in the NR mqtt-in configuration, you need to use that address also.

Ok its looking good---I did as you said and it seemed to connect one time and then error. But I have the 10.1.1.115 in the Arduino and localhost in the NR. And I am lookin at two beautiful green buttons. I have a long way to go but at least a start.

Thankyou both so much.
Cheers Trev

Just deleting stuff

Deletedxxxxx.

Remember that whatever machine your mqtt broker is on has to always have the same IP address, since it is hard coded into your esp.
Perhaps the best way is to reserve an IP in your router setup.

The broker has to be up and running whenever there are messages to pass.

Lots of people use a raspberry pi to run an MQTT broker because it can be left on all the time without consuming too much power.

And you can run node-red on the raspberry pi too, just firing up the PC when you want to work on it, see what your esp has been doing, etc

Personally I've found that a more satisfactory solution than node-red on the pc.

1 Like

Alternatively, if you're using DHCP to assign IP addresses, use the machine's name for the MQTT initialisation. That way, if the IP address changes you don't have to change your code.

Your comments make a lot of sense to my set-up. I have a PC that is on 24/7 because I have BlueIris running several cameras that are recording 24/7. So I will probably have a look at assigning static IP. But just give me a clue here- do you mean assign static IP to the ESP or Static IP to the Computer. Both make sense?

A static IP address is helpful for anything acting as a server - where other devices need to connect to it. Having a static IP address means that server is at a well known place in the network.

It is much less relevant for anything acting as a client. In the case of the ESP, it needs to know the IP address of the server it needs to connect, but nothing needs to connect back to the ESP. So in that case, a static IP address for the ESP isn't necessary.