This repository has been archived by the owner on Nov 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomeMatic.ino
81 lines (70 loc) · 2.71 KB
/
HomeMatic.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//http://192.168.1.252:8181/cuxd.exe?ret=dom.GetObject(%22CUxD.CUX4000003:1.LEVEL%22).State(0.4)
bool setStateCUxD(String id, String value) {
if (HomeMaticConfig.UseCCU) {
if (id.indexOf(".null.") == -1) {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.setTimeout(HTTPTimeOut);
id.replace(" ", "%20");
String url = "http://" + String(GlobalConfig.ccuIP) + ":8181/cuxd.exe?ret=dom.GetObject(%22" + id + "%22).State(" + value + ")";
DEBUG("setStateCUxD url: " + url, "setStateCUxD()", _slInformational);
http.begin(url);
int httpCode = http.GET();
String payload = "";
if (httpCode > 0) {
DEBUG("HTTP " + id + " success", "setStateCUxD()", _slInformational);
payload = http.getString();
}
if (httpCode != 200) {
blinkLED(3);
DEBUG("HTTP " + id + " failed with HTTP Error Code " + String(httpCode), "setStateCUxD()", _slError);
}
http.end();
payload = payload.substring(payload.indexOf("<ret>"));
payload = payload.substring(5, payload.indexOf("</ret>"));
DEBUG("result: " + payload, "setStateCUxD()", (payload != "null") ? _slInformational : _slError);
return (payload != "null");
} else {
if (!doWifiConnect())
ESP.restart();
}
} else return true;
} else {
DEBUG("HomeMaticConfig.UseCCU is false! Nothing to do...", "setStateCUxD()", _slInformational);
return false;
}
}
String getStateCUxD(String id, String type) {
if (HomeMaticConfig.UseCCU) {
if (id.indexOf(".null.") == -1) {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.setTimeout(HTTPTimeOut);
id.replace(" ", "%20");
String url = "http://" + String(GlobalConfig.ccuIP) + ":8181/cuxd.exe?ret=dom.GetObject(%22" + id + "%22)." + type + "()";
DEBUG("getStateFromCUxD url: " + url, "getStateCUxD()", _slInformational);
http.begin(url);
int httpCode = http.GET();
String payload = "error";
if (httpCode > 0) {
payload = http.getString();
}
if (httpCode != 200) {
blinkLED(3);
DEBUG("HTTP " + id + " fail", "getStateCUxD()", _slError);
}
http.end();
payload = payload.substring(payload.indexOf("<ret>"));
payload = payload.substring(5, payload.indexOf("</ret>"));
DEBUG("result: " + payload, "getStateCUxD()", _slInformational);
return payload;
} else {
if (!doWifiConnect())
ESP.restart();
}
} else return "";
} else {
DEBUG("HomeMaticConfig.UseCCU is false! Nothing to do...", "getStateCUxD()", _slInformational);
return "";
}
}