This repository has been archived by the owner on Mar 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCCUfunctions.ino
58 lines (51 loc) · 1.87 KB
/
CCUfunctions.ino
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
HTTPClient http;
bool setStateCCU(String id, String value) {
if (WiFi.status() == WL_CONNECTED) {
if (String(HomeMaticConfig.CCUIP) != "0.0.0.0") {
http.setTimeout(HTTPTIMEOUT);
String url = "http://" + String(HomeMaticConfig.CCUIP) + ":8181/rfid.exe?ret=dom.GetObject(%22" + id + "%22).State(" + value + ")";
Serial.print("setStateCCU url: " + url + " -> ");
http.begin(url);
int httpCode = http.GET();
String payload = "";
if (httpCode > 0) {
Serial.print("HTTP " + id + " success -> ");
payload = http.getString();
}
if (httpCode != 200) {
Serial.println("HTTP " + id + " fail");
return false;
}
http.end();
payload = payload.substring(payload.indexOf("<ret>"));
payload = payload.substring(5, payload.indexOf("</ret>"));
Serial.println("result: " + payload);
return (payload != "null");
} else return true;
} else ESP.restart();
}
String getStateCCU(String id, String type) {
if (WiFi.status() == WL_CONNECTED) {
if (String(HomeMaticConfig.CCUIP) != "0.0.0.0") {
http.setTimeout(HTTPTIMEOUT);
String url = "http://" + String(HomeMaticConfig.CCUIP) + ":8181/rfid.exe?ret=dom.GetObject(%22" + id + "%22)." + type + "()";
Serial.print("getStateCCU url: " + url + " -> ");
http.begin(url);
int httpCode = http.GET();
String payload = "error";
if (httpCode > 0) {
Serial.print("HTTP " + id + " success -> ");
payload = http.getString();
}
if (httpCode != 200) {
Serial.println("HTTP " + id + " fail");
return "";
}
http.end();
payload = payload.substring(payload.indexOf("<ret>"));
payload = payload.substring(5, payload.indexOf("</ret>"));
Serial.println("result: " + payload);
return payload;
} else return "";
} else ESP.restart();
}