Closed cimba007 closed 6 years ago
@cimba007 Could you please elaborate this issue?
I will try .. assume I upload my sketch to the esp8266 and everything is working as expected.
Now I want to upload a new sketch .. the upload process resets the esp8266 and leaves an open mqtt-connection on the broker (the client just vanished and did no proper logoff). Now the new sketch is uploaded .. and tries to connect again to the broker.
MC[D]: Attempting MQTT connection...<\n>
MC[I]: MQTT settings(Broker:[], Port:[])<\n>
MC[I]: MQTT authenticating as user:[]<\n>
MC[I]: MQTT connection failed, rc=-4<\n>
MC[D]: Try again in 3 seconds<\n>
The connection fails .. but succeeds after 3 seconds on the next retry.
The code presented here will be skipped ...
if(mqttClient.connected()){
before();
sendRSSI();
sendStatistics();
mcPresentation();
}
When the yellow part is called
The only check and chance to run
if(mqttClient.connected()){
before();
sendRSSI();
sendStatistics();
mcPresentation();
}
is gone.
I hope this made it a little bit more clear.
I am not good with github and pull requests but I suggest to change this:
mqttClient.connect(WiFi.hostname().c_str(), _mqttUser, _mqttPwd)
to
int limit = 0;
while(!mqttClient.connect(WiFi.hostname().c_str(), _mqttUser, _mqttPwd) && limit++ < 5)
{
MC_SERIAL.printf("MC[I]: MQTT retry .. %d\n",limit);
mcDelay(500);
}
in void MyController::checkMqtt() {
This will make sure that even if the innitical connection during initialize-method fails one times there are a few more retrys.
@cimba007 Yes, thank you for the detailed information. I understand that I need fix this issue on https://github.com/mycontroller-org/MyControllerDevice
moving to https://github.com/mycontroller-org/MyControllerDevice/issues/15
If I upload a new sketch the mqtt-client does not logoff from the mqtt-server (buildin mycontroller). On next sketch run presentation is skipped: