You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have PubSubClient running fine on an ESP32 which connects without any problems to an MQTT broker in my local network.
For my project, I now want to include an MQTT broker in my code on the same ESP32 that PubSubClient is running on, so that users have the choice of using a dedicated MQTT broker or - if my project is the only one they need MQTT for - use a small MQTT broker on the same ESP32. For that I have included PicoMQTT. I can connect to the PicoMQTT broker on that same ESP32 that PubSubClient is running on from MQTT Explorer and publishing and subscribing the topics from outside the ESP32 works fine. PubSubClient is also still running fine when subscribing and publishing to an external MQTT broker, but what is not working is for PubSubClient to connect to the PicoMQTT broker.
I have used the actual local IP, as well as 127.0.0.1 as well as "localhost" to tell PubSubClient that it should connect to the broker on the same host, but the connection fails all the time. state() returns -2 which means that the connection has failed.
Does anyone have an idea why this is the case? I don't want to switch to PicoMQTT for the client functions because it only runs on ESPs, not on the Arduino Due which is also used by a number of my users. Adding an optional feature such as the broker would be fine to offer for just the ESP users.
Any help is highly appreciated!
The text was updated successfully, but these errors were encountered:
No, I decided not to pursue this approach anymore because the ESP32 has too little memory to keep/retain several hundred values. But I read somewhere else that the issue is connected to the fact that the network library of the ESP32 doesn't resolve localhost (or has a concept of it talking to itself), so that's what could be the reason here as well...
Thank you for your response.
I think I will also follow an other approach so I get rid of the local broker.
But I will list what I found out. Maybe it's interesting for someone:
I could run PubSubClient with EmbeddedMqttBroker on the same ESP32. There PubSubClient connects to 127.0.0.1. Because I found memory leaks on this broker I will not use it. But it shows that it is possible to connect to localhost with PubSubClient.
I could run PubSubClient with PicoMqtt on the same ESP32. The PubSubClient connected to an other ESP32 with a PicoMqtt broker what worked without problems and I could send and subscribe from a raspberry pi and mosquito to the first PicoMqtt broker. So running PubSubClient and PicoMqtt on the same ESP32 is working.
The problems start when I try to connect PubSubClient to PicoMqtt running on the same host. I tried the actual IP of the device, localhost and 127.0.0.1 but none of this got a connection.
I have PubSubClient running fine on an ESP32 which connects without any problems to an MQTT broker in my local network.
For my project, I now want to include an MQTT broker in my code on the same ESP32 that PubSubClient is running on, so that users have the choice of using a dedicated MQTT broker or - if my project is the only one they need MQTT for - use a small MQTT broker on the same ESP32. For that I have included PicoMQTT. I can connect to the PicoMQTT broker on that same ESP32 that PubSubClient is running on from MQTT Explorer and publishing and subscribing the topics from outside the ESP32 works fine. PubSubClient is also still running fine when subscribing and publishing to an external MQTT broker, but what is not working is for PubSubClient to connect to the PicoMQTT broker.
I have used the actual local IP, as well as 127.0.0.1 as well as "localhost" to tell PubSubClient that it should connect to the broker on the same host, but the connection fails all the time.
state()
returns-2
which means that the connection has failed.Does anyone have an idea why this is the case? I don't want to switch to PicoMQTT for the client functions because it only runs on ESPs, not on the Arduino Due which is also used by a number of my users. Adding an optional feature such as the broker would be fine to offer for just the ESP users.
Any help is highly appreciated!
The text was updated successfully, but these errors were encountered: