diff --git a/LICENSE.md b/LICENSE.md old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/display.ino b/display.ino old mode 100644 new mode 100755 index 2631c9b..b16295d --- a/display.ino +++ b/display.ino @@ -33,15 +33,23 @@ String getRow(String text, int width, int letter_width, int text_of_row_x) { // } // 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("ö", "oe"); text.replace("Ö", "OE"); + text.replace("ö", "oe"); + text.replace("Ö", "OE"); text.replace("ü", "ue"); text.replace("Ü", "UE"); + text.replace("ü", "ue"); + text.replace("Ü", "UE"); text.replace("ß", "ss"); text.replace("ẞ", "SS"); + text.replace("ß", "ss"); return text; } @@ -49,8 +57,8 @@ String removeSpecialChars(String text) { // show the daily text on the epd void showDailyText(String losung, String lehrtext, String losungPosition, String lehrtextPosition) { // clean the strings for - losung = removeSpecialChars(losung); - lehrtext = removeSpecialChars(lehrtext); + losung = replaceSpecialChars(losung); + lehrtext = replaceSpecialChars(lehrtext); // position vars int text_x = 0; diff --git a/http_grab.ino b/http_grab.ino new file mode 100755 index 0000000..1846ee5 --- /dev/null +++ b/http_grab.ino @@ -0,0 +1,62 @@ +#include + +String textBeginString = ""; +String textEndString = "
"; +String sourceBeginString = textEndString; // because source begins where text ends +String sourceEndString = "

"; + +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); +} \ No newline at end of file diff --git a/losungepaper.ino b/losungepaper.ino index c0dcde7..7d254e4 100755 --- a/losungepaper.ino +++ b/losungepaper.ino @@ -32,11 +32,11 @@ void setup() { } 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."; - 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."; - showDailyText(losung, lehrtext, "Hosea 14,6", "Johannes 15,5"); + connectWiFi(); + String html = getHTML("https://www.losungen.de/fileadmin/media-losungen/heute/2022/0821.html"); + + showDailyText(getLosungFromHTML(html), getLehrtextFromHTML(html), getLosungSourceFromHTML(html), getLehrtextSourceFromHTML(html)); } void loop() { - connectWiFi(); } diff --git a/wifi.ino b/wifi.ino old mode 100644 new mode 100755 index f838e31..d249d15 --- a/wifi.ino +++ b/wifi.ino @@ -3,12 +3,12 @@ void connectWiFi() { // connect to the wifi with the above defined credentials 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); - delay(5000); // pause the program 5 secs to give time for connection - if(WiFi.status() != WL_CONNECTED) { return; } - Serial.printf("Connected to WiFi %s, got IP-Adress ", wiFiSSID); + delay(10000); // pause the program 5 secs to give time for connection + if(WiFi.status() != WL_CONNECTED) { Serial.printf("[WiFi] Failed connecting to WiFi \"%s\".", wiFiSSID); return; } + Serial.printf("[WiFi] Connected to WiFi \"%s\", got IP-Adress ", wiFiSSID); Serial.println(WiFi.localIP()); return;