Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LAN IP in Mqtt Server does not connect. #143

Open
ajaybnl opened this issue Nov 23, 2024 · 0 comments
Open

LAN IP in Mqtt Server does not connect. #143

ajaybnl opened this issue Nov 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ajaybnl
Copy link

ajaybnl commented Nov 23, 2024

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

@ajaybnl ajaybnl added the bug Something isn't working label Nov 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant