I'm working with an IOT project where i have to connect an ESP32 in a MQTT server, when i was testing the module in my networking wifi home it was working very well but when i change the wifi connection to another network that is not this of my home, the MQTT not connect with thw device anymore, just the new wifi netwoking is connecting. What can i do to solve this??
Where is the MQTT server? Perhaps the firewall at your second location won't let you talk to it.
Here is the part of the code corresponding to wifi and mqtt:
const char* ssid = "as";
const char password = "vD";
const char username = "";
const char mqttServer = "t****.s***.pt";
unsigned int mqttPort = 1883;
const char* mqttUser = "";
const char* mqttPassword = "";
WiFiClient espClient;
PubSubClient client(espClient);
DFRobotHCHOSensor hcho(SensorAnalogPin,VREF);
void setup() {
Wire.begin();
Serial.begin(115200);
client.setKeepAlive(360);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
Serial.println(WiFi.localIP());
client.setServer(mqttServer, mqttPort);
while (!client.connected()) {
Serial.println("Connecting to MQTT...");
if (client.connect("***", mqttUser, mqttPassword )) {
Serial.println("connected");
} else {
Serial.print("failed with state ");
Serial.println(client.state());
delay(2000);
}
}
And this is the result:
If you post your code as described in How to get the best out of this forum, more forum members will read it.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.