-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemscheidMuellParser.cpp
More file actions
78 lines (70 loc) · 2.75 KB
/
RemscheidMuellParser.cpp
File metadata and controls
78 lines (70 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
RemscheidMuellParser.cpp - Library to parse the Trash website of the German city Remscheid.
This will be used to evaluate if tomorrow the trash will be emptied.
So that we can signal to put out the trash.
Created by Jannis Dohm, 2020-04-20.
Released under MIT License.
*/
#include "Arduino.h"
#include "RemscheidMuellParser.h"
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
RemscheidMuellParser::RemscheidMuellParser(char *DatabaseURL){//the URL needs to be checked on the official website "https://abfallkalenderremscheid.insert-infotech.de/index.php"
_DatabaseURL = DatabaseURL;
}
bool RemscheidMuellParser::CheckDate(char* SearchFor, int day, int month, int year){
std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
client->setInsecure();
HTTPClient https;
if (https.begin(*client, String(_DatabaseURL) + "&Year=" + String(year) + "&KW=NULL&Monat=" + String(month))) { // HTTPS
Serial.println("[HTTPS] GET...");
int httpCode = https.GET();
// httpCode will be negative on error
if (httpCode > 0) {
// HTTP header has been send and Server response header has been handled
Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
// file found at server?
if (httpCode == HTTP_CODE_OK) {
int payload = https.getSize();
Serial.println(String("[HTTPS] Received payload: ") + payload);
Stream *httpsS = https.getStreamPtr();
while(httpsS -> available()){
String _day = ">" + _ToTwoString(day) +"</div>";
char _dayC[9];
_day.toCharArray(_dayC,9);
//if(httpsS -> find(String(">") + _ToTwoString(day) +"</div>")){
if(httpsS -> find(_dayC)){
Serial.print("found date: ");
Serial.print(day);
Serial.print(".");
Serial.print(month);
Serial.print(".");
Serial.println(year);
//skip next 4 line
for(int i=0; i<4;i++){
httpsS -> readStringUntil('\n');
}
}
String line = httpsS -> readStringUntil('\n');
Serial.print("looking for ");
Serial.print(SearchFor);
Serial.println(" in the following line:");
Serial.println(line);
if(1 <= line.indexOf(SearchFor)) return true;
}
return false;
}
} else {
Serial.printf("[HTTPS] GET... failed, error: %s\n\r", https.errorToString(httpCode).c_str());
}
https.end();
} else {
Serial.printf("[HTTPS] Unable to connect\n\r");
}
return false;
}
String RemscheidMuellParser::_ToTwoString(int Num){
if(Num<0) return "00";
if(Num<10) return "0" + String(Num);
return String(Num);
}