diff --git a/API.md b/API.md index 2e2a9ab..a37ddc6 100644 --- a/API.md +++ b/API.md @@ -6,8 +6,8 @@ - [POST /api/connection](#post-apiconnection) - [GET /api/system](#get-apisystem) - [POST /api/system](#post-apisystem) -- [GET /api/steps](#get-apisteps) -- [POST /api/steps](#post-apisteps) +- [GET /api/steps/values](#get-apistepsvalues) +- [POST /api/steps/values](#post-apistepsvalues) - [GET /api/triggers/time](#get-apitriggerstime) - [POST /api/triggers/time](#post-apitriggerstime) - [GET /api/triggers/motion](#get-apitriggersmotion) @@ -111,7 +111,7 @@ Updates the settings of the WiFi connections. The module will apply the new sett ## POST /api/system -## GET /api/steps +## GET /api/steps/values Returns the current brightness value for each step. The number of items in the array is equal to the number of configured steps. Each value has a range of 0 to 255. @@ -123,7 +123,7 @@ Returns the current brightness value for each step. The number of items in the a ] ``` -## POST /api/steps +## POST /api/steps/values Changes the brightness value for each step. If the number of values in the array is less than the number of configured steps, each subsequent step is considered to be off. diff --git a/WIRING.md b/WIRING.md index 2def5e3..277b080 100644 --- a/WIRING.md +++ b/WIRING.md @@ -1,4 +1,5 @@ ## Bill of materials 1. ESP8266 module (I based mine on a vanilla ESP8266 ESP-12F, but friendlier modules like the Wemos D1 should work as well) -1. PCA9685 16-channel PWM module \ No newline at end of file +1. PCA9685 16-channel PWM module +1. TODO complete this list \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index a153a1f..6d87b68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -99,9 +99,9 @@ void setup() _dln("Setup :: registering routes"); registerStaticRoutes(&server); + registerAPIRoutes(&server); registerSettingsRoutes(&server); registerFirmwareRoutes(&server); - registerAPIRoutes(&server); _dln("Setup :: starting HTTP server"); server.onNotFound(handleNotFound); diff --git a/src/server/api.cpp b/src/server/api.cpp index 86b3e5b..8b60e62 100644 --- a/src/server/api.cpp +++ b/src/server/api.cpp @@ -16,7 +16,7 @@ #include "../settings/triggers/time.h" -void handleGetSteps(AsyncWebServerRequest *request) +void handleGetStepValues(AsyncWebServerRequest *request) { _dln("API :: get steps"); @@ -35,7 +35,7 @@ void handleGetSteps(AsyncWebServerRequest *request) } -void handlePostSteps(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) +void handlePostStepValues(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) { _dln("API :: post steps"); @@ -125,8 +125,8 @@ void handlePostMotionTriggers(AsyncWebServerRequest *request, uint8_t *data, siz void registerAPIRoutes(AsyncWebServer* server) { - server->on("/api/steps", HTTP_GET, handleGetSteps); - server->on("/api/steps", HTTP_POST, devNullRequest, devNullFileUpload, handlePostSteps); + server->on("/api/steps/values", HTTP_GET, handleGetStepValues); + server->on("/api/steps/values", HTTP_POST, devNullRequest, devNullFileUpload, handlePostStepValues); server->on("/api/triggers/time", HTTP_GET, handleGetTimeTriggers); server->on("/api/triggers/time", HTTP_POST, devNullRequest, devNullFileUpload, handlePostTimeTriggers); diff --git a/src/server/settings.cpp b/src/server/settings.cpp index 6b11f84..cf3ce35 100644 --- a/src/server/settings.cpp +++ b/src/server/settings.cpp @@ -116,6 +116,35 @@ void handlePostSystem(AsyncWebServerRequest *request, uint8_t *data, size_t len, } +void handleGetSteps(AsyncWebServerRequest *request) +{ + _dln("API :: get steps"); + + AsyncResponseStream *response = request->beginResponseStream("application/json"); + stepsSettings->toJson(*response); + request->send(response); +} + + +void handlePostSteps(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) +{ + _dln("API :: post steps"); + + bool changed; + if (stepsSettings->fromJson((char*)data, &changed)) + { + stepsSettings->write(); + + if (changed) + stepsSettingsChanged = true; + + request->send(200); + } + else + request->send(400); +} + + void registerSettingsRoutes(AsyncWebServer* server) { server->on("/api/version", HTTP_GET, handleVersion); @@ -127,4 +156,7 @@ void registerSettingsRoutes(AsyncWebServer* server) server->on("/api/system", HTTP_GET, handleGetSystem); server->on("/api/system", HTTP_POST, devNullRequest, devNullFileUpload, handlePostSystem); + + server->on("/api/steps", HTTP_GET, handleGetSteps); + server->on("/api/steps", HTTP_POST, devNullRequest, devNullFileUpload, handlePostSteps); } \ No newline at end of file diff --git a/web/app.js b/web/app.js index c7e9410..708477c 100644 --- a/web/app.js +++ b/web/app.js @@ -1,6 +1,5 @@ function startApp() { - // TODO support for disable checkboxes Vue.component('check', { template: '