Open
Description
Description of the problem
My Mqtt Server is hosted on Raspberry Pi, when i set '192.168.100.x' as mqtt server, the client never connects to the mqtt server.
Versions
- ESPMQTTClient lib: 1.13.3
- PubSubClient lib: 2.8
- Arduino ESP32 / ESP8622 core: 3.20011.230801
Hardware
- Board type : ESP32 Wroom
- Board model : Custom
Logs
DNS Error
Correction
Add this code to detect and use ip or domain name
if(isip(_mqttServerIp)){
_mqttClient.setServer(_mqttServerIp, _mqttServerPort);
}else{
const char* mqtt_ip = MDNS.queryHost(_mqttServerIp).toString().c_str();
_mqttClient.setServer(mqtt_ip, _mqttServerPort);
}
add this function
bool isip(const String& input) {
int dotCount = 0;
for (size_t i = 0; i < input.length(); i++) {
char c = input[i];
if (c == '.') {
dotCount++;
} else if (!isDigit(c)) {
return false; // Contains a non-digit character other than '.'
}
}
// Must have exactly 3 dots to be an IP address
return (dotCount == 3);
}