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