Little Bugfixes added REST-API endpoints.

This commit is contained in:
Tobias Blum
2016-05-22 00:28:30 +02:00
parent 0364a5316f
commit fe6f191deb
2 changed files with 435 additions and 420 deletions
+22 -7
View File
@@ -187,9 +187,11 @@ void setup() {
server.on("/edit", HTTP_DELETE, handleFileDelete);
//first callback is called after the request has ended with all parsed arguments
//second callback handles file uploads at that location
server.on("/edit", HTTP_POST, [](){ server.send(200, "text/plain", ""); }, handleFileUpload);
server.on("/edit", HTTP_POST, []() {
server.send(200, "text/plain", "");
}, handleFileUpload);
//get heap status, analog input value and all GPIO statuses in one json call
server.on("/status", HTTP_GET, [](){
server.on("/esp_status", HTTP_GET, []() {
String json = "{";
json += "\"heap\":" + String(ESP.getFreeHeap());
json += ", \"analog\":" + String(analogRead(A0));
@@ -207,13 +209,19 @@ void setup() {
handleNotFound();
});
server.on("/upload", handleMinimalUpload);
server.on("/restart", []() {
DBG_OUTPUT_PORT.printf("/restart:\n");
server.send(200, "text/plain", "restarting..." );
ESP.restart();
});
// ***************************************************************************
// Setup: SPIFFS Webserver handler
// ***************************************************************************
server.on("/brightness", []() {
server.on("/set_brightness", []() {
if (server.arg("c").toInt() > 0) {
brightness = (int) server.arg("c").toInt() * 2.55;
} else {
@@ -235,15 +243,22 @@ void setup() {
});
server.on("/get_brightness", []() {
server.send(200, "text/plain", String((int) (brightness / 2.55)) );
String str_brightness = String((int) (brightness / 2.55));
server.send(200, "text/plain", str_brightness );
DBG_OUTPUT_PORT.print("/get_brightness: ");
DBG_OUTPUT_PORT.println(str_brightness);
});
server.on("/get_switch", []() {
server.send(200, "text/plain", (mode == OFF) ? "0" : "1" );
DBG_OUTPUT_PORT.printf("/get_switch: %s\n", (mode == OFF) ? "0" : "1");
});
server.on("/get_color", []() {
server.send(200, "text/plain", String(main_color.red, HEX) + String(main_color.green, HEX) + String(main_color.blue, HEX) );
String rgbcolor = String(main_color.red, HEX) + String(main_color.green, HEX) + String(main_color.blue, HEX);
server.send(200, "text/plain", rgbcolor );
DBG_OUTPUT_PORT.print("/get_color: ");
DBG_OUTPUT_PORT.println(rgbcolor);
});
server.on("/status", []() {
@@ -321,7 +336,7 @@ void loop() {
strip.setPixelColor(i, 0, 0, 0);
}
strip.show();
mode = HOLD;
//mode = HOLD;
}
if (mode == ALL) {
uint16_t i;