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

Added getters for IP, Domain, and Port. #996

Open AdamJHowell opened 1 year ago

AdamJHowell commented 1 year ago

I wanted a way to query the PubSubClient object, for cases where I attempt to connect to multiple different brokers with one PubSubClient object, and for cases where I have multiple PubSubClient objects which are passed around to helper functions.

This has been tested on an ESP32 WROOM with the following block:

if( mqttClient.connected() )
{
    Serial.print( "MQTT broker domain: " );
    Serial.println( mqttClient.getServerDomain() );
    Serial.print( "MQTT broker IP: " );
    Serial.println( mqttClient.getServerIP() );
    Serial.print( "MQTT broker port: " );
    Serial.println( mqttClient.getServerPort() );
}