🪄 Adds api service with updates

This commit is contained in:
Rune Harlyk
2024-05-08 13:26:40 +02:00
committed by Rune Harlyk
parent 4c66c428e6
commit b7ae17f3bf
19 changed files with 391 additions and 573 deletions
+31 -66
View File
@@ -7,6 +7,7 @@
*
* Copyright (C) 2018 - 2023 rjwats
* Copyright (C) 2023 theelims
* Copyright (C) 2024 runeharlyk
*
* All Rights Reserved. This software may be modified and distributed under
* the terms of the LGPL v3 license. See the LICENSE file for details.
@@ -14,74 +15,38 @@
#include <FeaturesService.h>
FeaturesService::FeaturesService(PsychicHttpServer *server) : _server(server)
{
FeaturesService::FeaturesService(PsychicHttpServer *server) : _server(server) {}
void FeaturesService::begin() {
_server->on(FEATURES_SERVICE_PATH, HTTP_GET, [&](PsychicRequest *request) {
PsychicJsonResponse response = PsychicJsonResponse(request, false);
JsonObject root = response.getRoot();
root["security"] = FT_SECURITY;
root["mqtt"] = FT_MQTT;
root["ntp"] = FT_NTP;
root["upload_firmware"] = FT_UPLOAD_FIRMWARE;
root["download_firmware"] = FT_DOWNLOAD_FIRMWARE;
root["sleep"] = FT_SLEEP;
root["battery"] = FT_BATTERY;
root["analytics"] = FT_ANALYTICS;
root["firmware_version"] = APP_VERSION;
root["firmware_name"] = APP_NAME;
root["firmware_built_target"] = BUILD_TARGET;
// Iterate over user features
for (auto &element : userFeatures) {
root[element.feature.c_str()] = element.enabled;
}
return response.send();
});
ESP_LOGV("FeaturesService", "Registered GET endpoint: %s",
FEATURES_SERVICE_PATH);
}
void FeaturesService::begin()
{
_server->on(FEATURES_SERVICE_PATH, HTTP_GET, [&](PsychicRequest *request)
{
PsychicJsonResponse response = PsychicJsonResponse(request, false);
JsonObject root = response.getRoot();
#if FT_ENABLED(FT_SECURITY)
root["security"] = true;
#else
root["security"] = false;
#endif
#if FT_ENABLED(FT_MQTT)
root["mqtt"] = true;
#else
root["mqtt"] = false;
#endif
#if FT_ENABLED(FT_NTP)
root["ntp"] = true;
#else
root["ntp"] = false;
#endif
#if FT_ENABLED(FT_UPLOAD_FIRMWARE)
root["upload_firmware"] = true;
#else
root["upload_firmware"] = false;
#endif
#if FT_ENABLED(FT_DOWNLOAD_FIRMWARE)
root["download_firmware"] = true;
#else
root["download_firmware"] = false;
#endif
#if FT_ENABLED(FT_SLEEP)
root["sleep"] = true;
#else
root["sleep"] = false;
#endif
#if FT_ENABLED(FT_BATTERY)
root["battery"] = true;
#else
root["battery"] = false;
#endif
#if FT_ENABLED(FT_ANALYTICS)
root["analytics"] = true;
#else
root["analytics"] = false;
#endif
root["firmware_version"] = APP_VERSION;
root["firmware_name"] = APP_NAME;
root["firmware_built_target"] = BUILD_TARGET;
// Iterate over user features
for (auto &element : userFeatures)
{
root[element.feature.c_str()] = element.enabled;
}
return response.send(); });
ESP_LOGV("FeaturesService", "Registered GET endpoint: %s", FEATURES_SERVICE_PATH);
}
void FeaturesService::addFeature(String feature, bool enabled)
{
void FeaturesService::addFeature(String feature, bool enabled) {
UserFeature newFeature;
newFeature.feature = feature;
newFeature.enabled = enabled;