the mqtt part of my code must have some mistake. I wonder because I thought I have just used it successfuly in another project.
Somehow it goes into a loop. Watch the attached picture to understand what I mean. I can't find the mistake.
void loop() {
if(WiFi.status() != WL_CONNECTED){
while (WiFi.status() != WL_CONNECTED){
connect();
uint8_t timeout = 8;
while (timeout && (WiFi.status() != WL_CONNECTED)) {
timeout--;
delay(1000);
}
}
}
if(!client.connected()){
Serial.println("test nach client.connected");
while(!client.connected()){
Serial.println("Connecting to MQTT...");
client.connect("ESP8266Client", mqttUser, mqttPassword);
uint8_t timeout = 8;
while (timeout && (!client.connected())){
timeout--;
delay(1000);
}
if (client.connect("ESP8266Client", mqttUser, mqttPassword )) {
Serial.println("connected");
delay(2000);
} else {
Serial.print("failed with state ");
Serial.print(client.state());
}
client.subscribe("bad/fenster");
client.subscribe("kueche/fenster");
}
}
Can anyone help?
(full code also attached)