From 887f205a7e7a48c84267ed1ba7dcc1ebb2e2a011 Mon Sep 17 00:00:00 2001 From: Reiner Herrmann Date: Wed, 15 Jul 2020 20:04:05 +0200 Subject: connect to wifi and update time over ntp --- src/main.cpp | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src') 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 #include +#include #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); } -- cgit v1.2.3