Added download and parsing for daily texts
This commit is contained in:
parent
0b7c66a684
commit
429e400e32
0
LICENSE.md
Normal file → Executable file
0
LICENSE.md
Normal file → Executable file
14
display.ino
Normal file → Executable file
14
display.ino
Normal file → Executable file
@ -33,15 +33,23 @@ String getRow(String text, int width, int letter_width, int text_of_row_x) { //
|
|||||||
}
|
}
|
||||||
|
|
||||||
// remove special characters (ä,ö,ü,ß)
|
// remove special characters (ä,ö,ü,ß)
|
||||||
String removeSpecialChars(String text) {
|
String replaceSpecialChars(String text) {
|
||||||
|
if(text[0] == ' ') { text = text.substring(1,text.length()-1); }
|
||||||
text.replace("ä", "ae");
|
text.replace("ä", "ae");
|
||||||
text.replace("Ä", "AE");
|
text.replace("Ä", "AE");
|
||||||
|
text.replace("ä", "ae");
|
||||||
|
text.replace("Ä", "AE");
|
||||||
text.replace("ö", "oe");
|
text.replace("ö", "oe");
|
||||||
text.replace("Ö", "OE");
|
text.replace("Ö", "OE");
|
||||||
|
text.replace("ö", "oe");
|
||||||
|
text.replace("Ö", "OE");
|
||||||
text.replace("ü", "ue");
|
text.replace("ü", "ue");
|
||||||
text.replace("Ü", "UE");
|
text.replace("Ü", "UE");
|
||||||
|
text.replace("ü", "ue");
|
||||||
|
text.replace("Ü", "UE");
|
||||||
text.replace("ß", "ss");
|
text.replace("ß", "ss");
|
||||||
text.replace("ẞ", "SS");
|
text.replace("ẞ", "SS");
|
||||||
|
text.replace("ß", "ss");
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
@ -49,8 +57,8 @@ String removeSpecialChars(String text) {
|
|||||||
// show the daily text on the epd
|
// show the daily text on the epd
|
||||||
void showDailyText(String losung, String lehrtext, String losungPosition, String lehrtextPosition) {
|
void showDailyText(String losung, String lehrtext, String losungPosition, String lehrtextPosition) {
|
||||||
// clean the strings for
|
// clean the strings for
|
||||||
losung = removeSpecialChars(losung);
|
losung = replaceSpecialChars(losung);
|
||||||
lehrtext = removeSpecialChars(lehrtext);
|
lehrtext = replaceSpecialChars(lehrtext);
|
||||||
|
|
||||||
// position vars
|
// position vars
|
||||||
int text_x = 0;
|
int text_x = 0;
|
||||||
|
62
http_grab.ino
Executable file
62
http_grab.ino
Executable file
@ -0,0 +1,62 @@
|
|||||||
|
#include <HTTPClient.h>
|
||||||
|
|
||||||
|
String textBeginString = "<b>";
|
||||||
|
String textEndString = "</b><br>";
|
||||||
|
String sourceBeginString = textEndString; // because source begins where text ends
|
||||||
|
String sourceEndString = "</font></p>";
|
||||||
|
|
||||||
|
String getHTML(String url) {
|
||||||
|
String result = "";
|
||||||
|
if(WiFi.status() == WL_CONNECTED) {
|
||||||
|
HTTPClient http;
|
||||||
|
http.begin(url); // initialize the http instance
|
||||||
|
int httpCode = http.GET(); // get the page; httpCode will be negative on error
|
||||||
|
|
||||||
|
if(httpCode > 0) {
|
||||||
|
// HTTP header has been send and Server response header has been handled
|
||||||
|
Serial.printf("[HTTP] GET: %d\n", httpCode);
|
||||||
|
|
||||||
|
// file found at server
|
||||||
|
if(httpCode == HTTP_CODE_OK) {
|
||||||
|
result = http.getString();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Serial.printf("[HTTP] GET: %s\n", http.errorToString(httpCode).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
http.end();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getLosungFromHTML(String html) {
|
||||||
|
int losungBeginIndex = html.indexOf(textBeginString)+textBeginString.length();
|
||||||
|
int losungEndIndex = html.indexOf(textEndString);
|
||||||
|
|
||||||
|
return html.substring(losungBeginIndex, losungEndIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getLehrtextFromHTML(String html) {
|
||||||
|
String losung = getLosungFromHTML(html);
|
||||||
|
int losungIndex = html.indexOf(losung);
|
||||||
|
int lehrtextBeginIndex = html.indexOf(textBeginString, losungIndex)+textBeginString.length();
|
||||||
|
int lehrtextEndIndex = html.indexOf(textEndString, losungIndex+losung.length()+textEndString.length()); // calculating is needed for better performance and to get the second index, not the first
|
||||||
|
|
||||||
|
return html.substring(lehrtextBeginIndex, lehrtextEndIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getLosungSourceFromHTML(String html) { // get the source of losung in given html
|
||||||
|
int losungSourceBeginIndex = html.indexOf(sourceBeginString)+sourceBeginString.length();
|
||||||
|
int losungSourceEndIndex = html.indexOf(sourceEndString);
|
||||||
|
|
||||||
|
return html.substring(losungSourceBeginIndex, losungSourceEndIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
String getLehrtextSourceFromHTML(String html) { // get the source of losung in given html
|
||||||
|
String losungSource = getLosungSourceFromHTML(html);
|
||||||
|
int losungSourceIndex = html.indexOf(losungSource);
|
||||||
|
int lehrtextSourceBeginIndex = html.indexOf(sourceBeginString, losungSourceIndex)+sourceBeginString.length();
|
||||||
|
int lehrtextSourceEndIndex = html.indexOf(sourceEndString, losungSourceIndex+losungSource.length()+sourceEndString.length()); // calculating is needed for better performance and to get the second index, not the first
|
||||||
|
|
||||||
|
return html.substring(lehrtextSourceBeginIndex, lehrtextSourceEndIndex);
|
||||||
|
}
|
@ -32,11 +32,11 @@ void setup() {
|
|||||||
}
|
}
|
||||||
Serial.println("[INFO] Initialized e-Paper!");
|
Serial.println("[INFO] Initialized e-Paper!");
|
||||||
|
|
||||||
String losung = "Gott spricht: Ich will für Israel wie der Tau sein, dass es blüht wie eine Lilie.";
|
connectWiFi();
|
||||||
String lehrtext = "Ich bin der Weinstock, ihr seid die Reben. Wer in mir bleibt und ich in ihm, der bringt viel Frucht; denn ohne mich könnt ihr nichts tun.";
|
String html = getHTML("https://www.losungen.de/fileadmin/media-losungen/heute/2022/0821.html");
|
||||||
showDailyText(losung, lehrtext, "Hosea 14,6", "Johannes 15,5");
|
|
||||||
|
showDailyText(getLosungFromHTML(html), getLehrtextFromHTML(html), getLosungSourceFromHTML(html), getLehrtextSourceFromHTML(html));
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
connectWiFi();
|
|
||||||
}
|
}
|
||||||
|
8
wifi.ino
Normal file → Executable file
8
wifi.ino
Normal file → Executable file
@ -3,12 +3,12 @@
|
|||||||
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
|
||||||
|
|
||||||
Serial.println("Connecting to WiFi...");
|
Serial.println("[WiFi] Connecting to WiFi...");
|
||||||
|
|
||||||
WiFi.begin(wiFiSSID, wiFiPSK);
|
WiFi.begin(wiFiSSID, wiFiPSK);
|
||||||
delay(5000); // pause the program 5 secs to give time for connection
|
delay(10000); // pause the program 5 secs to give time for connection
|
||||||
if(WiFi.status() != WL_CONNECTED) { return; }
|
if(WiFi.status() != WL_CONNECTED) { Serial.printf("[WiFi] Failed connecting to WiFi \"%s\".", wiFiSSID); return; }
|
||||||
Serial.printf("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());
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user