pubsubclient icon indicating copy to clipboard operation
pubsubclient copied to clipboard

Use hostname for the MQTT broker IP

Open SteveRMann opened this issue 2 years ago • 2 comments

I need to move my MQTT server to a new IP. The reason why is irrelevant. If I could use the MDNS location for the broker in client.setserver(), a change in my broker IP would be trivial.

Instead of client.setServer("192.168.1.120", 1883);

I would like to be able to: client.setServer("broker.local", 1883);

SteveRMann avatar Dec 11 '23 16:12 SteveRMann

I've been looking for a "nslookup" type command for the ESP32 to work around this, but hostname is the correct solution.

lee32768 avatar Dec 22 '23 21:12 lee32768

Looks like this is already supported anywhere you would be setting an IP, just set the domain instead.

https://github.com/knolleary/pubsubclient/blob/master/src/PubSubClient.cpp#L118-L127 https://github.com/knolleary/pubsubclient/blob/master/src/PubSubClient.cpp#L715-L719

ChuckMash avatar Dec 24 '23 18:12 ChuckMash