Extended REST API for use with homebridge
This commit is contained in:
parent
95082ba925
commit
aeef8e8bc8
2 changed files with 27 additions and 4 deletions
|
@ -214,7 +214,11 @@ void setup() {
|
||||||
// Setup: SPIFFS Webserver handler
|
// Setup: SPIFFS Webserver handler
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
server.on("/brightness", []() {
|
server.on("/brightness", []() {
|
||||||
brightness = server.arg("p").toInt();
|
if (server.arg("c").toInt() > 0) {
|
||||||
|
brightness = (int) server.arg("c").toInt() * 2.55;
|
||||||
|
} else {
|
||||||
|
brightness = server.arg("p").toInt();
|
||||||
|
}
|
||||||
if (brightness > 255) {
|
if (brightness > 255) {
|
||||||
brightness = 255;
|
brightness = 255;
|
||||||
}
|
}
|
||||||
|
@ -230,6 +234,18 @@ void setup() {
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
server.on("/get_brightness", []() {
|
||||||
|
server.send(200, "text/plain", String((int) (brightness / 2.55)) );
|
||||||
|
});
|
||||||
|
|
||||||
|
server.on("/get_switch", []() {
|
||||||
|
server.send(200, "text/plain", (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) );
|
||||||
|
});
|
||||||
|
|
||||||
server.on("/status", []() {
|
server.on("/status", []() {
|
||||||
getStatusJSON();
|
getStatusJSON();
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,9 +2,16 @@
|
||||||
// Request handlers
|
// Request handlers
|
||||||
// ***************************************************************************
|
// ***************************************************************************
|
||||||
void getArgs() {
|
void getArgs() {
|
||||||
main_color.red = server.arg("r").toInt();
|
if (server.arg("rgb") != "") {
|
||||||
main_color.green = server.arg("g").toInt();
|
uint32_t rgb = (uint32_t) strtol(server.arg("rgb").c_str(), NULL, 16);
|
||||||
main_color.blue = server.arg("b").toInt();
|
main_color.red = ((rgb >> 16) & 0xFF);
|
||||||
|
main_color.green = ((rgb >> 8) & 0xFF);
|
||||||
|
main_color.blue = ((rgb >> 0) & 0xFF);
|
||||||
|
} else {
|
||||||
|
main_color.red = server.arg("r").toInt();
|
||||||
|
main_color.green = server.arg("g").toInt();
|
||||||
|
main_color.blue = server.arg("b").toInt();
|
||||||
|
}
|
||||||
delay_ms = server.arg("d").toInt();
|
delay_ms = server.arg("d").toInt();
|
||||||
|
|
||||||
if (main_color.red > 255) {
|
if (main_color.red > 255) {
|
||||||
|
|
Loading…
Reference in a new issue