diff --git a/src/http_server.cpp b/src/http_server.cpp index 49dd6b2..6846230 100644 --- a/src/http_server.cpp +++ b/src/http_server.cpp @@ -69,6 +69,20 @@ void http_server_setup() { message += ""; http_server.send(200, "text/html", message); }); + http_server.on("/settings", HTTP_POST, [&]() { + if (!http_server.hasArg("key") || !http_server.hasArg("value")) { + http_server.send(400, "text/plain", "Missing argument."); + return; + } + String name = http_server.arg("key"); + uint16_t value = http_server.arg("value").toInt(); + + if (change_setting(name.c_str(), value)) { + http_server.send(200, "text/plain", "OK"); + } else { + http_server.send(400, "text/plain", "Could not change setting."); + } + }); http_server.on("/delete", HTTP_GET, [&]() { LOGln("HTTP * GET /delete"); if (http_server.args()==0) { diff --git a/src/mqtt.cpp b/src/mqtt.cpp index 42b4c9f..ba0be5b 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -71,10 +71,15 @@ void mqtt_callback(char* original_topic, byte* pl, unsigned int length) { tests::run(); return; } + long value = payload.toInt(); LOGln("MQTT * Payload as number: %d", value); - - if (topic.compareTo("brightness")==0) { + + if (topic.startsWith("settings.")) { + topic.remove(0, 9); + change_setting(topic.c_str(), value); + return; + } else if (topic.compareTo("brightness")==0) { if (value > 0 && value <= 255) { LOGln("MQTT * Changing brightness..."); FastLED.setBrightness(value);