knolleary / pubsubclient

A client library for the Arduino Ethernet Shield that provides support for MQTT.
http://pubsubclient.knolleary.net/
MIT License
3.78k stars 1.46k forks source link

Use hostname for the MQTT broker IP #1039

Open SteveRMann opened 6 months ago

SteveRMann commented 6 months ago

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);

lee32768 commented 6 months ago

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

ChuckMash commented 6 months ago

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