From af6c2fb0585067d83822770b97a9439877137fbc Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Fri, 28 May 2021 15:20:06 +0200 Subject: [PATCH] Initial commit --- esp32indicator.ino | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 esp32indicator.ino diff --git a/esp32indicator.ino b/esp32indicator.ino new file mode 100644 index 0000000..1641559 --- /dev/null +++ b/esp32indicator.ino @@ -0,0 +1,76 @@ +#include +#include +#include + +const char* ssid = "Your WiFi SSID"; +const char* password = "Your WiFi Password"; + +const int notify_hour = 20; +const int notify_minute = 0; + +const int local_time_offset = 2 * 3600; + +const int led = 1; + +bool flashing = false; +bool skip = false; + +WiFiUDP ntpUDP; +NTPClient timeClient(ntpUDP); + +bool check_time() { + while(!timeClient.update()) { + timeClient.forceUpdate(); + } + + int hours = timeClient.getHours(); + int minutes = timeClient.getMinutes(); + + if (skip && hours < notify_hour) skip = false; + + if (!skip && (hours > notify_hour || (hours == notify_hour && minutes >= notify_minute))) { + return true; + } + + return false; +} + +void setup() { + // Serial.begin(115200); + pinMode(led, OUTPUT); + digitalWrite(led, HIGH); + + // Serial.print("Connecting to "); + // Serial.println(ssid); + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + // Serial.print("."); + } + + /* Serial.println(""); + Serial.println("WiFi connected."); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); */ + + timeClient.begin(); + timeClient.setTimeOffset(local_time_offset); + + if (check_time()) skip = true; +} + +void loop() { + if (!flashing) { + flashing = check_time(); + if (!flashing) delay(30000); + return; + } + + if (!skip) { + digitalWrite(led, LOW); + delay(500); + digitalWrite(led, HIGH); + delay(500); + } +}