Settings can now be changed:
* Via HTTP POST request to /settings, providing key=<key_to_change> and value=<new_value>. * Via MQTT at <MQTT_TOPIC>/settings.<key>.
This commit is contained in:
parent
0f1d4abe04
commit
ef57c5ea2e
@ -69,6 +69,20 @@ void http_server_setup() {
|
||||
message += "</table></body></html>";
|
||||
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) {
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user