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