forked from ksya/ILIFERobot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
http.ino
74 lines (54 loc) · 1.74 KB
/
http.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
void processCmdRequest() {
if(!server.hasArg("c")) return returnFail("BAD ARGS");
String cmd = server.arg("c");
int robotCmd = findValidRobotCmd(cmd.c_str());
if(robotCmd != -1) {
IRbutton irbutton = buttonCmds[robotCmd];
Serial.print("[HTTP] Got valid robot command: ");
Serial.println(irbutton.name);
server.send(200, "text/plain", "Robot "+String(irbutton.name));
SendIRCode(irbutton);
}
else {
returnFail("INVALID COMMAND");
}
}
void returnFail(String msg) {
server.send(200, "text/plain", msg);
}
void setupHTTP() {
// MDNS.begin(mDNSname);
httpUpdater.setup(&server, update_path, update_username, update_password);
server.begin();
// MDNS.addService("http", "tcp", 80);
Serial.printf("\n[HTTP] HTTPUpdateServer ready! Open http://%s%s in your browser and login with username '%s' and password '%s'\n", WiFi.localIP().toString().c_str(), update_path, update_username, update_password);
Serial.println("");
server.on("/", [](){
server.send_P(200, "text/html", PAGE_index);
});
server.on("/cmd", HTTP_GET, processCmdRequest);
}
//
//void HTTPRobotAction(IRbutton irbutton){
// //SendIRCode(irbutton);
//
// Serial.print("[HTTP] Got robot request: ");
// Serial.println(irbutton.name);
//
// server.send(200, "text/plain", "Robot "+String(irbutton.name));
//
// char command[20];
// sprintf(command, "robot;%s", irbutton.name);
// mqtt.publish(outTopic, command);
//}
//
//void setupHTTPRobotCmd() {
// for(int c = 0; c < sizeof(buttonCmds)/sizeof(buttonCmds[0]); c++) {
//
// char requesturl[20];
// sprintf(requesturl, "/cmd=%s", buttonCmds[c].name);
//
// //handle http request
// server.on(requesturl, std::bind(&HTTPRobotAction, buttonCmds[c]));
// }
//}