# Put it all together

**URL:** <https://discourse.nodered.org/t/put-it-all-together/47936>\
**Category:** General\
**Created:** [2 July 2021 09:25 UTC](https://discourse.nodered.org/t/put-it-all-together/47936 "2021-07-02T09:25:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 09:25 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/1 "2021-07-02T09:25:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 09:32 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/2 "2021-07-02T09:32:06Z")

</div>

What order do I start -  
Plug in Arduino using mqtt\_esp8266  
node-red in terminal  
mosquitto in terminal do I use start mosquitto

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 09:35 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/3 "2021-07-02T09:35:51Z")

</div>

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](http://broker.mqtt-dashboard.com)

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 09:46 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/4 "2021-07-02T09:46:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 09:47 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/5 "2021-07-02T09:47:24Z")

</div>

the 10.1.1.115 is the ip of computer I am on

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 July 2021 09:48 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/6 "2021-07-02T09:48:55Z")

</div>

> [@Trev1951](#):
>
> const char\* mqtt\_server = "localhost";

`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.

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 09:52 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/7 "2021-07-02T09:52:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 July 2021 09:53 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/8 "2021-07-02T09:53:54Z")

</div>

> [@Trev1951](#):
>
> how do I find IP of 'Machine' running the broker-

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.

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 10:02 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/9 "2021-07-02T10:02:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 July 2021 10:04 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/10 "2021-07-02T10:04:53Z")

</div>

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](https://support.microsoft.com/en-us/windows/find-your-ip-address-f21a9bbc-c582-55cd-35e0-73431160a1b9)

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 10:23 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/11 "2021-07-02T10:23:41Z")

</div>

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](http://broker.mqtt-dashboard.com)";

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

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 10:31 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/12 "2021-07-02T10:31:34Z")

</div>

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](http://broker.mqtt-dashboard.com)";

But maybe itsa starting point.

Thanks Heaps  
Cheers Trev

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [2 July 2021 10:32 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/13 "2021-07-02T10:32:24Z")

</div>

> [@Trev1951](#):
>
> the 10.1.1.115 is the ip of computer I am on

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

```auto
const char* mqtt_server = "10.1.1.115 ";

```

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

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 10:47 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/14 "2021-07-02T10:47:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 10:52 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/15 "2021-07-02T10:52:10Z")

</div>

Just deleting stuff

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 10:57 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/16 "2021-07-02T10:57:38Z")

</div>

Deletedxxxxx.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [2 July 2021 11:52 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/17 "2021-07-02T11:52:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![molesworth](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/molesworth/32/11748_2.png) [@molesworth](https://discourse.nodered.org/u/molesworth)\
**Post date:** [2 July 2021 12:04 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/18 "2021-07-02T12:04:09Z")

</div>

> [@jbudd](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![Trev1951](https://avatars.discourse-cdn.com/v4/letter/t/e19b73/32.png) [@Trev1951](https://discourse.nodered.org/u/Trev1951)\
**Post date:** [2 July 2021 12:49 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/19 "2021-07-02T12:49:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [2 July 2021 12:52 UTC](https://discourse.nodered.org/t/put-it-all-together/47936/20 "2021-07-02T12:52:17Z")

</div>

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.

[Next page](https://discourse.nodered.org/t/put-it-all-together/47936.md?page=2)
