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

Added reboot logic to esp32 if fails to connect #217

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mitsubishi2mqtt/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const PROGMEM uint8_t redLedPin = 0;
// Define global variables for network
const PROGMEM char* hostnamePrefix = "HVAC_";
const PROGMEM uint32_t WIFI_RETRY_INTERVAL_MS = 300000;
const int CONNECTION_TIMEOUT = 10;
unsigned long wifi_timeout;
bool wifi_config_exists;
String hostname = "";
Expand Down
9 changes: 9 additions & 0 deletions src/mitsubishi2mqtt/mitsubishi2mqtt.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1655,6 +1655,8 @@ bool connectWifi() {
WiFi.begin(ap_ssid.c_str(), ap_pwd.c_str());
// Serial.println("Connecting to " + ap_ssid);
wifi_timeout = millis() + 30000;
int timeout_counter = 0;

while (WiFi.status() != WL_CONNECTED && millis() < wifi_timeout) {
Serial.write('.');
//Serial.print(WiFi.status());
Expand All @@ -1663,6 +1665,13 @@ bool connectWifi() {
delay(250);
digitalWrite(blueLedPin, HIGH);
delay(250);
//reboot ESP32 if fails to connect after retries
#ifdef ESP32
timeout_counter++;
if(timeout_counter >= CONNECTION_TIMEOUT * 5){
ESP.restart();
}
#endif
}
if (WiFi.status() != WL_CONNECTED) {
// Serial.println(F("Failed to connect to wifi"));
Expand Down