Browse Source
Merge pull request #2 from Oliver-ger
Improved ESP-Restart after MQTT-Fail
pull/86/head
Oliver-ger
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
19 additions and
5 deletions
-
tools/esp8266/mqtt.h
|
|
@ -85,11 +85,25 @@ class mqtt { |
|
|
|
private: |
|
|
|
void reconnect(void) { |
|
|
|
//DPRINTLN(DBG_VERBOSE, F("mqtt.h:reconnect"));
|
|
|
|
if(!mClient->connected()) { |
|
|
|
if (WiFi.status() != WL_CONNECTED) { |
|
|
|
Serial.println("WiFi not connected"); |
|
|
|
} |
|
|
|
else { |
|
|
|
int count = 0; |
|
|
|
while(!mClient->connected()) { |
|
|
|
if((strlen(mUser) > 0) && (strlen(mPwd) > 0)) |
|
|
|
mClient->connect(DEF_DEVICE_NAME, mUser, mPwd); |
|
|
|
else |
|
|
|
mClient->connect(DEF_DEVICE_NAME); |
|
|
|
if (mClient->connect(DEF_DEVICE_NAME, mUser, mPwd)){ |
|
|
|
Serial.println("MQTT connected"); |
|
|
|
} |
|
|
|
else { |
|
|
|
Serial.println("MQTT failed"); |
|
|
|
delay(2000); |
|
|
|
count = count + 1; |
|
|
|
} |
|
|
|
if (count >=3){ |
|
|
|
ESP.restart(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|