esp_clock: disable WiFi for 1 hour
This commit is contained in:
parent
611124d166
commit
b1952bebe4
@ -39,6 +39,8 @@ byte displayHours[24] = {12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4,
|
|||||||
bool blinkColon = false; // Track colon status to blink once/sec
|
bool blinkColon = false; // Track colon status to blink once/sec
|
||||||
int status = WL_IDLE_STATUS;
|
int status = WL_IDLE_STATUS;
|
||||||
bool shouldUpdate = true;
|
bool shouldUpdate = true;
|
||||||
|
String currentSSID;
|
||||||
|
String currentPsk;
|
||||||
|
|
||||||
ESP8266WiFiMulti wifiMulti;
|
ESP8266WiFiMulti wifiMulti;
|
||||||
WiFiUDP ntpUDP;
|
WiFiUDP ntpUDP;
|
||||||
@ -55,6 +57,8 @@ void setup() {
|
|||||||
delay(500);
|
delay(500);
|
||||||
}
|
}
|
||||||
Serial.println("Connected to network.");
|
Serial.println("Connected to network.");
|
||||||
|
currentSSID = WiFi.SSID();
|
||||||
|
currentPsk = WiFi.psk();
|
||||||
printWiFiStatus(); // Display WiFi status data
|
printWiFiStatus(); // Display WiFi status data
|
||||||
|
|
||||||
setupOTA();
|
setupOTA();
|
||||||
@ -74,6 +78,7 @@ void loop() {
|
|||||||
minutes = timeClient.getMinutes();
|
minutes = timeClient.getMinutes();
|
||||||
seconds = timeClient.getSeconds();
|
seconds = timeClient.getSeconds();
|
||||||
Serial.println(timeClient.getFormattedTime());
|
Serial.println(timeClient.getFormattedTime());
|
||||||
|
WiFi.forceSleepBegin();
|
||||||
} else {
|
} else {
|
||||||
incrementTime();
|
incrementTime();
|
||||||
}
|
}
|
||||||
@ -82,14 +87,28 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void incrementTime() {
|
void incrementTime() {
|
||||||
if (++seconds == 60) {
|
if (++seconds >= 60) {
|
||||||
seconds = 0;
|
seconds = 0;
|
||||||
if (++minutes == 60) {
|
if (++minutes == 60) {
|
||||||
minutes = 0;
|
minutes = 0;
|
||||||
Serial.println("Minutes set to zero - should query NTP on next loop()");
|
Serial.println("Minutes set to zero - should query NTP on next loop()");
|
||||||
if (++hours == 24) hours = 0;
|
if (++hours == 24) hours = 0;
|
||||||
}
|
}
|
||||||
if (((minutes % 5) == 0)) shouldUpdate = true;
|
if ((minutes == 0)) {
|
||||||
|
WiFi.forceSleepWake();
|
||||||
|
WiFi.begin(currentSSID.c_str(), currentPsk.c_str());
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
Serial.println("Reconnecting to WiFi netowrk...");
|
||||||
|
delay(1000);
|
||||||
|
seconds++;
|
||||||
|
}
|
||||||
|
if (WiFi.status() == WL_CONNECTED) {
|
||||||
|
shouldUpdate = true;
|
||||||
|
} else {
|
||||||
|
WiFi.forceSleepBegin();
|
||||||
|
}
|
||||||
|
printWiFiStatus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +124,9 @@ void displayTime() {
|
|||||||
// which can look confusing. Go in and explicitly add these zeros.
|
// which can look confusing. Go in and explicitly add these zeros.
|
||||||
if (displayHour == 0) {
|
if (displayHour == 0) {
|
||||||
clockDisplay.writeDigitNum(1, 0);
|
clockDisplay.writeDigitNum(1, 0);
|
||||||
|
if (minutes < 10) {
|
||||||
|
clockDisplay.writeDigitNum(3, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blink the colon by flipping its value every loop iteration
|
// Blink the colon by flipping its value every loop iteration
|
||||||
@ -118,15 +140,7 @@ void displayTime() {
|
|||||||
|
|
||||||
void setupOTA() {
|
void setupOTA() {
|
||||||
ArduinoOTA.onStart([]() {
|
ArduinoOTA.onStart([]() {
|
||||||
String type;
|
Serial.println("Start");
|
||||||
if (ArduinoOTA.getCommand() == U_FLASH) {
|
|
||||||
type = "sketch";
|
|
||||||
} else { // U_FS
|
|
||||||
type = "filesystem";
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: if updating FS this would be the place to unmount FS using FS.end()
|
|
||||||
Serial.println("Start updating " + type);
|
|
||||||
});
|
});
|
||||||
ArduinoOTA.onEnd([]() {
|
ArduinoOTA.onEnd([]() {
|
||||||
Serial.println("\nEnd");
|
Serial.println("\nEnd");
|
||||||
@ -136,17 +150,11 @@ void setupOTA() {
|
|||||||
});
|
});
|
||||||
ArduinoOTA.onError([](ota_error_t error) {
|
ArduinoOTA.onError([](ota_error_t error) {
|
||||||
Serial.printf("Error[%u]: ", error);
|
Serial.printf("Error[%u]: ", error);
|
||||||
if (error == OTA_AUTH_ERROR) {
|
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
|
||||||
Serial.println("Auth Failed");
|
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
|
||||||
} else if (error == OTA_BEGIN_ERROR) {
|
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
|
||||||
Serial.println("Begin Failed");
|
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
|
||||||
} else if (error == OTA_CONNECT_ERROR) {
|
else if (error == OTA_END_ERROR) Serial.println("End Failed");
|
||||||
Serial.println("Connect Failed");
|
|
||||||
} else if (error == OTA_RECEIVE_ERROR) {
|
|
||||||
Serial.println("Receive Failed");
|
|
||||||
} else if (error == OTA_END_ERROR) {
|
|
||||||
Serial.println("End Failed");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
Serial.println("Ready");
|
Serial.println("Ready");
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user