diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2020-07-15 20:04:05 +0200 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2020-07-15 20:04:05 +0200 |
| commit | 887f205a7e7a48c84267ed1ba7dcc1ebb2e2a011 (patch) | |
| tree | 0c48ab0d2bf3f2eda35e7e1408e760c87adf680a | |
| parent | 98e80a7c3bca5291db84501a6ab099205a4653ce (diff) | |
connect to wifi and update time over ntp
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | src/main.cpp | 37 |
2 files changed, 35 insertions, 3 deletions
@@ -3,3 +3,4 @@ .gcc-flags.json .ccls .ccls-cache/ +include/secrets.h diff --git a/src/main.cpp b/src/main.cpp index 1a73845..a4f80a8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,8 +2,10 @@ #include <GxEPD2_BW.h> #include <Fonts/FreeMonoBold9pt7b.h> +#include <WiFi.h> #include "tux.h" +#include "secrets.h" /* see GxEPD2_WS_ESP32_Driver.ino and esp32-waveshare-epd/src/DEV_Config.h @@ -47,13 +49,42 @@ void draw() { } while(display.nextPage()); } +void wifi_connect() { + WiFi.begin(wifi_ssid, wifi_psk); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + } +} + +void wifi_disconnect() { + WiFi.disconnect(); + WiFi.mode(WIFI_OFF); +} + +void update_time() { + struct tm timeinfo; + configTime(0, 0, "de.pool.ntp.org"); + getLocalTime(&timeinfo, 5000); +} + void setup() { - display_setup(); - draw(); + Serial.begin(115200); + + //display_setup(); + //draw(); + //display.powerOff(); - display.powerOff(); + wifi_connect(); + update_time(); + wifi_disconnect(); } void loop() { + struct tm timeinfo; + if (getLocalTime(&timeinfo)) { + Serial.println(&timeinfo); + } else { + Serial.println("Unknown time"); + } delay(1000); } |
