keep Wifi connected for 1 min at startup
This commit is contained in:
parent
5ee36054cf
commit
c0f54f2289
@ -17,6 +17,6 @@ lib_deps =
|
|||||||
adafruit/Adafruit LED Backpack Library@^1.1.8
|
adafruit/Adafruit LED Backpack Library@^1.1.8
|
||||||
adafruit/Adafruit BusIO@^1.6.0
|
adafruit/Adafruit BusIO@^1.6.0
|
||||||
jchristensen/Timezone@^1.2.4
|
jchristensen/Timezone@^1.2.4
|
||||||
|
;upload_port = /dev/ttyUSB0
|
||||||
;upload_port = 192.168.5.191
|
;upload_port = 192.168.5.191
|
||||||
upload_port = /dev/ttyUSB0
|
|
||||||
;upload_protocol = espota
|
;upload_protocol = espota
|
||||||
|
|||||||
@ -23,6 +23,7 @@ TimeChangeRule CET = {"CET ", Last, Sun, Oct, 3, 60}; // Central European
|
|||||||
Timezone CE(CEST, CET);
|
Timezone CE(CEST, CET);
|
||||||
|
|
||||||
int currentHour = -1;
|
int currentHour = -1;
|
||||||
|
time_t timeAtStartup;
|
||||||
|
|
||||||
String currentSSID;
|
String currentSSID;
|
||||||
String currentPsk;
|
String currentPsk;
|
||||||
@ -34,6 +35,7 @@ void displayTime();
|
|||||||
void displayColon(bool on);
|
void displayColon(bool on);
|
||||||
void setupOTA();
|
void setupOTA();
|
||||||
void printWiFiStatus();
|
void printWiFiStatus();
|
||||||
|
time_t updateTime();
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600); // Start the serial console
|
Serial.begin(9600); // Start the serial console
|
||||||
@ -56,6 +58,7 @@ void setup() {
|
|||||||
clockDisplay.setBrightness(BRIGHTNESS);
|
clockDisplay.setBrightness(BRIGHTNESS);
|
||||||
|
|
||||||
timeClient.begin();
|
timeClient.begin();
|
||||||
|
timeAtStartup = updateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@ -71,14 +74,16 @@ void loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
printWiFiStatus();
|
printWiFiStatus();
|
||||||
if (WiFi.status() == WL_CONNECTED && timeClient.forceUpdate()) {
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
time_t newTime = CE.toLocal(timeClient.getEpochTime());
|
if (time_t newTime = updateTime()) Serial.println(asctime(localtime(&newTime)));
|
||||||
setTime(newTime);
|
|
||||||
Serial.println(asctime(localtime(&newTime)));
|
|
||||||
}
|
}
|
||||||
WiFi.forceSleepBegin();
|
|
||||||
currentHour = hour();
|
currentHour = hour();
|
||||||
}
|
}
|
||||||
|
if (WiFi.status() == WL_CONNECTED && difftime(now(), timeAtStartup) > 60) {
|
||||||
|
Serial.println("Disconnecting WiFi");
|
||||||
|
WiFi.disconnect();
|
||||||
|
WiFi.forceSleepBegin();
|
||||||
|
}
|
||||||
displayTime();
|
displayTime();
|
||||||
displayColon(true);
|
displayColon(true);
|
||||||
delay(500);
|
delay(500);
|
||||||
@ -110,6 +115,16 @@ void displayColon(bool on) {
|
|||||||
clockDisplay.writeDisplay();
|
clockDisplay.writeDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time_t updateTime() {
|
||||||
|
if (timeClient.forceUpdate()) {
|
||||||
|
time_t newTime = CE.toLocal(timeClient.getEpochTime());
|
||||||
|
setTime(newTime);
|
||||||
|
return newTime;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setupOTA() {
|
void setupOTA() {
|
||||||
ArduinoOTA.onStart([]() {
|
ArduinoOTA.onStart([]() {
|
||||||
Serial.println("Start");
|
Serial.println("Start");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user