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
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);
}
The text was updated successfully, but these errors were encountered:
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
Hardware
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);
}
The text was updated successfully, but these errors were encountered: