aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arduino_sketch/fuzzy_alarm_clock_esp32/.gitignore1
-rw-r--r--arduino_sketch/fuzzy_alarm_clock_esp32/config.h15
-rw-r--r--arduino_sketch/fuzzy_alarm_clock_esp32/fuzzy_alarm_clock_esp32.ino52
3 files changed, 68 insertions, 0 deletions
diff --git a/arduino_sketch/fuzzy_alarm_clock_esp32/.gitignore b/arduino_sketch/fuzzy_alarm_clock_esp32/.gitignore
new file mode 100644
index 0000000..b6bf14b
--- /dev/null
+++ b/arduino_sketch/fuzzy_alarm_clock_esp32/.gitignore
@@ -0,0 +1 @@
+local_config.h
diff --git a/arduino_sketch/fuzzy_alarm_clock_esp32/config.h b/arduino_sketch/fuzzy_alarm_clock_esp32/config.h
new file mode 100644
index 0000000..1e505b2
--- /dev/null
+++ b/arduino_sketch/fuzzy_alarm_clock_esp32/config.h
@@ -0,0 +1,15 @@
+#define WIFI_SSID ""
+#define WIFI_PASS ""
+
+#define DEBUG 1
+
+#define NTP_SERV_1 "pool.ntp.org"
+#define NTP_SERV_2 "time.nist.gov"
+
+// TimeZone rule for Europe/Rome including daylight adjustment rules (optional)
+// See https://github.com/esp8266/Arduino/blob/master/cores/esp8266/TZ.h
+#define TZ "CET-1CEST,M3.5.0,M10.5.0/3"
+
+// Create the file local_config.h in this directory and override all of the
+// #defines you need
+#include "local_config.h"
diff --git a/arduino_sketch/fuzzy_alarm_clock_esp32/fuzzy_alarm_clock_esp32.ino b/arduino_sketch/fuzzy_alarm_clock_esp32/fuzzy_alarm_clock_esp32.ino
new file mode 100644
index 0000000..297b938
--- /dev/null
+++ b/arduino_sketch/fuzzy_alarm_clock_esp32/fuzzy_alarm_clock_esp32.ino
@@ -0,0 +1,52 @@
+// Create a file local_config.h with your network configuration and secrets (it
+// is ignored by git); see config.h for details of what it expects.
+#include "config.h"
+
+#include <WiFi.h>
+
+#include "time.h"
+#include "sntp.h"
+
+WiFiClient wifiClient;
+
+void connect_wifi() {
+ WiFi.begin(WIFI_SSID, WIFI_PASS);
+ Serial.print("WiFi ");
+ char count = 0;
+ while (WiFi.status() != WL_CONNECTED) {
+ delay(500);
+#ifdef DEBUG
+ Serial.print(WiFi.status());
+#endif
+ Serial.print(".");
+ count ++;
+ if (count > 10) {
+ Serial.println(" timeout");
+ return;
+ }
+ }
+ Serial.println(" connected");
+}
+
+void setup() {
+ Serial.begin(115200);
+#if defined(DEBUG)
+ Serial.setDebugOutput(true);
+#endif
+
+ configTzTime(TZ, NTP_SERV_1, NTP_SERV_2);
+
+ connect_wifi();
+
+}
+
+void loop() {
+ delay(5000);
+ struct tm timeinfo;
+ if(!getLocalTime(&timeinfo)){
+ Serial.println("No time available (yet)");
+ return;
+ }
+ Serial.print("Time is: ");
+ Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
+}