-
Notifications
You must be signed in to change notification settings - Fork 5
/
Scenary.ino
78 lines (73 loc) · 1.86 KB
/
Scenary.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
void initScenary() {
loadScenary();
sCmd.addCommand("if", ifCommand);
sCmd.addCommand("id", idNot);
sCmd.addCommand("then", thenCommand);
HTTP.on("/setscenary", HTTP_GET, []() {
loadScenary();
HTTP.send(200, "text/plain", "Ok");
});
}
void loadScenary(){
Scenary = readFile("scenary.save.txt", 4096);
Scenary.replace("\r\n", "\n");
Scenary.replace("\n\n", "\n");
Scenary += "\n";
}
// Ничего не делать если комманда id
void idNot() {}
void handleScenary() {
if (flag) {
goCommands(Scenary);
//Serial.println(goCommands(Scenary));
flag = false;
}
}
// Разбор команды if
void ifCommand() {
thenOk = false;
String Name = readArgsString();
String Condition = readArgsString();
String Volume = readArgsString();
if (Condition == "=") {
if (Volume == getStatus(Name)) thenOk = true;
}
if (Condition == "<") {
if (Volume > getStatus(Name)) thenOk = true;
}
if (Condition == ">") {
if (Volume < getStatus(Name)) thenOk = true;
}
if (Condition == "<=") {
if (Volume >= getStatus(Name)) thenOk = true;
}
if (Condition == ">=") {
if (Volume <= getStatus(Name)) thenOk = true;
}
if (Condition == "!=") {
if (Volume != getStatus(Name)) thenOk = true;
}
}
// Выполнение then
void thenCommand() {
if (thenOk) {
String ssdp = jsonRead(configSetup, "SSDP");
String test = readArgsString();
String comm = readArgsString();
// Если это локальное устройство
if (ssdp == test ) {
sCmd.readStr(comm);
}
else {
//http://192.168.0.91/cmd?command=relay1
String urls = "http://";
String ip = jsonRead(ssdpList, test);
urls += ip;
urls += "/cmd?command=" + comm;
if (ip != "") {
//Serial.println(urls);
getURL(urls);
}
}
}
}