Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
fixed missing wifi reconnection if wifi connection is lost
Browse files Browse the repository at this point in the history
  • Loading branch information
jp112sdl committed Jan 16, 2018
1 parent 40ee83a commit acdd4bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
42 changes: 30 additions & 12 deletions SonoffHMLOX.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "js_pow.h"
#include "js_fwupd.h"

const String FIRMWARE_VERSION = "1.0.17";
const String FIRMWARE_VERSION = "1.0.18";
//#define UDPDEBUG
#define SERIALDEBUG

Expand Down Expand Up @@ -126,6 +126,7 @@ const String lastRelayStateFilename = "laststat.txt";
const String configJsonFile = "config.json";
bool RelayState = LOW;
bool KeyPress = false;
bool WiFiConnected = false;
bool LastSwitchGPIOPin14State = HIGH;
bool CurrentSwitchGPIO14State = HIGH;
byte LEDPin = 13;
Expand All @@ -137,9 +138,9 @@ unsigned long LastHlwMeasureMillis = 0;
unsigned long LastHlwCollectMillis = 0;
unsigned long KeyPressDownMillis = 0;
unsigned long TimerSeconds = 0;
unsigned long LastWiFiReconnectMillis = 0;
bool OTAStart = false;
bool UDPReady = false;
bool newFirmwareAvailable = false;
bool startWifiManager = false;
bool wm_shouldSaveConfig = false;
bool PRESS_LONGsent = false;
Expand Down Expand Up @@ -336,20 +337,37 @@ void setup() {
}

void loop() {
//Überlauf der millis() abfangen
if (LastMillisKeyPress > millis())
LastMillisKeyPress = millis();
if (TimerStartMillis > millis())
TimerStartMillis = millis();
if (LastHlwMeasureMillis > millis())
LastHlwMeasureMillis = millis();
if (LastHlwCollectMillis > millis())
LastHlwCollectMillis = millis();
if (LastWiFiReconnectMillis > millis())
LastWiFiReconnectMillis = millis();

//Reconnect WiFi wenn nicht verbunden (alle 30 Sekunden)
if (WiFi.status() != WL_CONNECTED) {
WiFiConnected = false;
if (millis() - LastWiFiReconnectMillis > 30000) {
LastWiFiReconnectMillis = millis();
DEBUG("WiFi Connection lost! Reconnecting...");
WiFi.reconnect();
}
} else {
if (!WiFiConnected) {
DEBUG("WiFi reconnected!");
WiFiConnected = true;
}
}

//auf OTA Anforderung reagieren
ArduinoOTA.handle();

if (!OTAStart) {
//Überlauf der millis() abfangen
if (LastMillisKeyPress > millis())
LastMillisKeyPress = millis();
if (TimerStartMillis > millis())
TimerStartMillis = millis();
if (LastHlwMeasureMillis > millis())
LastHlwMeasureMillis = millis();
if (LastHlwCollectMillis > millis())
LastHlwCollectMillis = millis();

//eingehende UDP Kommandos abarbeiten
String udpMessage = handleUDP();
if (udpMessage == "bootConfigMode")
Expand Down
1 change: 1 addition & 0 deletions WifiManager.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ bool doWifiConnect() {
delay(500);
}
DEBUG("Wifi Connected");
WiFiConnected = true;
return true;
} else {
WiFiManager wifiManager;
Expand Down

0 comments on commit acdd4bc

Please sign in to comment.