Now using NTP server for getting time.
This commit is contained in:
parent
429e400e32
commit
45df5179b8
@ -28,6 +28,22 @@ String getHTML(String url) {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
String getHTML() { // gets the date and year from time.h library
|
||||||
|
struct tm timeinfo;
|
||||||
|
char dayInMonth[3];
|
||||||
|
char month[3];
|
||||||
|
char year[5];
|
||||||
|
|
||||||
|
if(!getLocalTime(&timeinfo)){
|
||||||
|
Serial.println("Failed to obtain time");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
strftime(dayInMonth,3, "%d", &timeinfo);
|
||||||
|
strftime(month,3, "%m", &timeinfo);
|
||||||
|
strftime(year,5, "%Y", &timeinfo);
|
||||||
|
|
||||||
|
return getHTML(String("https://www.losungen.de/fileadmin/media-losungen/heute/") + String(year) + String("/") + String(month) + String(dayInMonth) + String(".html"));
|
||||||
|
}
|
||||||
|
|
||||||
String getLosungFromHTML(String html) {
|
String getLosungFromHTML(String html) {
|
||||||
int losungBeginIndex = html.indexOf(textBeginString)+textBeginString.length();
|
int losungBeginIndex = html.indexOf(textBeginString)+textBeginString.length();
|
||||||
|
@ -11,6 +11,11 @@ Epd epd;
|
|||||||
char wiFiSSID[] = "SSID"; // SSID of your network
|
char wiFiSSID[] = "SSID"; // SSID of your network
|
||||||
char wiFiPSK[] = "PRE-SHARED KEY"; //password of your WPA Network
|
char wiFiPSK[] = "PRE-SHARED KEY"; //password of your WPA Network
|
||||||
|
|
||||||
|
// NTP (Network Time Protocol)
|
||||||
|
const String ntpServer = "pool.ntp.org"; // address of ntp server; may also be your router, other local service, etc.
|
||||||
|
const long gmtOffset_sec = 3600; // for localization (gmt = greenwich mean time); in germany: 3600
|
||||||
|
const int daylightOffset_sec = 3600; // for daylight saving
|
||||||
|
|
||||||
// style of the frame shown
|
// style of the frame shown
|
||||||
sFONT TITLE_FONT = Font20;
|
sFONT TITLE_FONT = Font20;
|
||||||
char TITLE_TEXT[] = "Losung heute";
|
char TITLE_TEXT[] = "Losung heute";
|
||||||
@ -33,8 +38,8 @@ void setup() {
|
|||||||
Serial.println("[INFO] Initialized e-Paper!");
|
Serial.println("[INFO] Initialized e-Paper!");
|
||||||
|
|
||||||
connectWiFi();
|
connectWiFi();
|
||||||
String html = getHTML("https://www.losungen.de/fileadmin/media-losungen/heute/2022/0821.html");
|
String html = getHTML();
|
||||||
|
|
||||||
showDailyText(getLosungFromHTML(html), getLehrtextFromHTML(html), getLosungSourceFromHTML(html), getLehrtextSourceFromHTML(html));
|
showDailyText(getLosungFromHTML(html), getLehrtextFromHTML(html), getLosungSourceFromHTML(html), getLehrtextSourceFromHTML(html));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
wifi.ino
5
wifi.ino
@ -1,4 +1,5 @@
|
|||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
void connectWiFi() { // connect to the wifi with the above defined credentials
|
void connectWiFi() { // connect to the wifi with the above defined credentials
|
||||||
if(WiFi.status() == WL_CONNECTED) { return; } // return if not connected
|
if(WiFi.status() == WL_CONNECTED) { return; } // return if not connected
|
||||||
@ -11,5 +12,9 @@ void connectWiFi() { // connect to the wifi with the above defined credentials
|
|||||||
Serial.printf("[WiFi] Connected to WiFi \"%s\", got IP-Adress ", wiFiSSID);
|
Serial.printf("[WiFi] Connected to WiFi \"%s\", got IP-Adress ", wiFiSSID);
|
||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
Serial.println("[NTP] Getting time...");
|
||||||
|
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer.c_str());
|
||||||
|
Serial.println("[NTP] Got time.");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user