From b899b0a503cb02b6b67dfce79ec2e58eb869c012 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Wed, 8 Dec 2021 22:49:25 +0100 Subject: [PATCH 01/14] Require OTA_USERNAME --- main/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main/main.cpp b/main/main.cpp index 4828660..fa19f10 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,5 +1,9 @@ constexpr const char * const TAG = "BOBBY"; +#ifndef OTA_USERNAME +#error No OTA username! +#endif + // system includes #include From cc0a23802f3924aa7a1417cda79c698ada07e5aa Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Wed, 8 Dec 2021 22:50:30 +0100 Subject: [PATCH 02/14] Added new parameter and fixed ifdef --- main/presets.cpp | 9 ++++++++- main/stringsettings.h | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/main/presets.cpp b/main/presets.cpp index 14a16fb..17e1055 100644 --- a/main/presets.cpp +++ b/main/presets.cpp @@ -50,8 +50,15 @@ StringSettings makeDefaultStringSettings() }, .otaServerUrl = {}, #endif +#ifdef AP_PASSWORD .ap_password = STRING(AP_PASSWORD), - .otaServerBranch = {} +#else + .ap_password = "Bobbycar_123", +#endif +#ifdef FEATURE_OTA + .otaServerBranch = {}, +#endif + .webserver_password = STRING(AP_PASSWORD), }; } } // namespace presets diff --git a/main/stringsettings.h b/main/stringsettings.h index 406bcab..18755ca 100644 --- a/main/stringsettings.h +++ b/main/stringsettings.h @@ -49,7 +49,10 @@ struct StringSettings std::string dns_key; #endif std::string ap_password; +#ifdef FEATURE_OTA std::string otaServerBranch; +#endif + std::string webserver_password; }; template @@ -114,12 +117,13 @@ void StringSettings::executeForEveryCommonSetting(T &&callable) // callable("otaUrl9", otaServers[9].url); callable("otaserver", otaServerUrl); + callable("otaBranch", otaServerBranch); #endif #ifdef FEATURE_DNS_NS callable("dnskey", dns_key); #endif callable("ap_pw", ap_password); - callable("otaBranch", otaServerBranch); + callable("webpw", webserver_password); } template From 98641cfc0469436f62e0851b7d9414d5f0c7697c Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Dec 2021 00:19:52 +0100 Subject: [PATCH 03/14] Added plugin and fixed compiling --- config_mick.cmake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/config_mick.cmake b/config_mick.cmake index 16bf55d..b538f2b 100644 --- a/config_mick.cmake +++ b/config_mick.cmake @@ -44,7 +44,7 @@ set(BOBBYCAR_BUILDFLAGS -DAP_PASSWORD=Passwort_123 -DFEATURE_WEBSERVER # -DFEATURE_OTA -# -DOTA_USERNAME="mick" + -DOTA_USERNAME="mick" # -DFEATURE_DPAD_5WIRESW # -DPINS_DPAD_5WIRESW_OUT=4 # -DPINS_DPAD_5WIRESW_IN1=5 @@ -92,3 +92,8 @@ set(BOBBYCAR_BUILDFLAGS -DOLD_NVS # -DFEATURE_DNS_NS ) + +if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ignore/lockscreen_plugin.cmake") + include("${CMAKE_CURRENT_SOURCE_DIR}/ignore/lockscreen_plugin.cmake") + message(WARNING "Including lockscreen_plugin") +endif() From 8caf8789dd56d074ec02269cf29f94922c6d0a56 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Dec 2021 00:33:40 +0100 Subject: [PATCH 04/14] Added json versions of websites --- main/webserver_displaycontrol.cpp | 50 ++++++++++++++++++++++- main/webserver_ota.cpp | 66 ++++++++++++++++++++++++++++++- 2 files changed, 114 insertions(+), 2 deletions(-) diff --git a/main/webserver_displaycontrol.cpp b/main/webserver_displaycontrol.cpp index 8d215db..a51140c 100644 --- a/main/webserver_displaycontrol.cpp +++ b/main/webserver_displaycontrol.cpp @@ -19,6 +19,54 @@ esp_err_t webserver_root_handler(httpd_req_t *req) std::string body; + std::string wants_json_query; + if (auto result = esphttpdutils::webserver_get_query(req)) + wants_json_query = *result; + else + { + ESP_LOGE(TAG, "%.*s", result.error().size(), result.error().data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", result.error()); + } + + char tmpBuf[256]; + const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); + if (key_result == ESP_OK) + { + body += "{"; + if (auto currentDisplay = static_cast(espgui::currentDisplay.get())) + { + body.reserve(4096); + if (const auto *textInterface = currentDisplay->asTextInterface()) + { + body += fmt::format("\"name:\"{}\",", textInterface->text()); + } + + if (const auto *menuDisplay = currentDisplay->asMenuDisplay()) + { + body += fmt::format("\"index\":{},\"items\":[", menuDisplay->selectedIndex()); + menuDisplay->runForEveryMenuItem([&,selectedIndex=menuDisplay->selectedIndex()](const espgui::MenuItem &menuItem){ + body += "{"; + body += fmt::format("\"name\":\"{}\",\"icon\":\"{}\"", menuItem.text(), "none"); // menuItem.icon()->name + body += "},"; + }); + body += "],"; + } + else if (const auto *changeValueDisplay = currentDisplay->asChangeValueDisplayInterface()) + { + body += fmt::format("\"value\":\"{}\",", changeValueDisplay->shownValue()); + } + else + { + body += "\"err\":\"Screen not implemented yet.\","; + } + } + else + { + body += "\"err\":\"Currently no screen instantiated.\","; + } + body += "}"; + } + else { HtmlTag htmlTag{"html", body}; @@ -105,7 +153,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req) } } - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, "text/html", body) + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, (key_result == ESP_OK) ? "application/json":"text/html", body) } esp_err_t webserver_triggerButton_handler(httpd_req_t *req) diff --git a/main/webserver_ota.cpp b/main/webserver_ota.cpp index 1c13ead..322bf18 100644 --- a/main/webserver_ota.cpp +++ b/main/webserver_ota.cpp @@ -23,6 +23,70 @@ esp_err_t webserver_ota_handler(httpd_req_t *req) std::string body; + std::string wants_json_query; + if (auto result = esphttpdutils::webserver_get_query(req)) + wants_json_query = *result; + else + { + ESP_LOGE(TAG, "%.*s", result.error().size(), result.error().data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", result.error()); + } + + char tmpBuf[256]; + const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); + if (key_result == ESP_OK) + { + body += "{"; + + if (const esp_app_desc_t *app_desc = esp_ota_get_app_description()) + { + body += fmt::format("\"cur_name\":\"{}\",", app_desc->project_name); + body += fmt::format("\"cur_ver\":\"{}\",", app_desc->version); + body += fmt::format("\"cur_secver\":\"{}\",", app_desc->secure_version); + body += fmt::format("\"cur_ts\":\"{}\",", app_desc->time); + body += fmt::format("\"cur_idf\":\"{}\",", app_desc->idf_ver); + body += fmt::format("\"cur_sha\":\"{}\",", espcpputils::toHexString({app_desc->app_elf_sha256, 8})); + } + else + { + body += "\"err\":\"Could not access esp_ota_get_app_description()\","; + } + + body += "\"updater\":{"; + + if (asyncOta) + { + body += fmt::format("\"status\":\"{}\"", toString(asyncOta->status())); + + if (const auto &appDesc = asyncOta->appDesc()) + { + const auto progress = asyncOta->progress(); + const auto totalSize = asyncOta->totalSize(); + + body += fmt::format("\"cur_ota_percent\":\"{}\",", (totalSize && *totalSize > 0) ? fmt::format("{:.02f}", float(progress) / *totalSize * 100) : "?"); + body += fmt::format("\"cur_ota_progress\":\"{}\",", progress); + body += fmt::format("\"cur_ota_total\":\"{}\",", totalSize ? std::to_string(*totalSize) : "?"); + body += fmt::format("\"new_name\":\"{}\",", appDesc->project_name); + body += fmt::format("\"new_ver\":\"{}\",", appDesc->version); + body += fmt::format("\"new_secver\":\"{}\",", appDesc->secure_version); + body += fmt::format("\"new_ts\":\"{}\",", appDesc->time); + body += fmt::format("\"new_idf\":\"{}\",", appDesc->idf_ver); + body += fmt::format("\"new_sha\":\"{}\",", espcpputils::toHexString({appDesc->app_elf_sha256, 8})); + + } + else + { + body += "\"err\":\"Could not access asyncOta->appDesc()\","; + } + } + else + { + body += "\"info\":\"Updater is not constructed.\""; + } + + body += "}}"; + } + else { HtmlTag htmlTag{"html", body}; @@ -197,7 +261,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req) } } - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, "text/html", body) + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, (key_result == ESP_OK) ? "application/json" : "text/html", body) } esp_err_t webserver_trigger_ota_handler(httpd_req_t *req) From f1053cd3b5ea84f2ee570a0933426757e722f88e Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Dec 2021 07:22:57 +0100 Subject: [PATCH 05/14] Weg damit --- .github/workflows/default.yml | 56 ----------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 .github/workflows/default.yml diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml deleted file mode 100644 index 86789fb..0000000 --- a/.github/workflows/default.yml +++ /dev/null @@ -1,56 +0,0 @@ -on: - push: - pull_request: - branches: - - main - page_build: - release: - types: - - created - -jobs: - build: - runs-on: ubuntu-latest - environment: default - strategy: - fail-fast: false - matrix: - node: [feedc0de, comred, peter, mick] - steps: - - name: Checkout (without submodules) - uses: actions/checkout@v2 - - - name: Checkout and install esp-idf - uses: 0xFEEDC0DE64/checkout_install_esp_idf@main - - - name: Fast Submodule Checkout components/arduino-esp32 - uses: 0xFEEDC0DE64/fast_submodule_checkout@main - with: - submodule: components/arduino-esp32 - - - name: Checkout remaining submodules - run: git submodule update --init --recursive $(git submodule | awk '{ if ($2 != "esp-idf" && $2 != "components/arduino-esp32") print $2 }') - - - name: Setup ccache - uses: 0xFEEDC0DE64/setup_ccache@main - with: - key: ${{ runner.os }}-ccache-${{ matrix.node }} - - - name: Build firmware - run: | - export CCACHE_MAXSIZE=400M CCACHE_BASEDIR="$(pwd)" - . export.sh - ./switchconf.sh ${{ matrix.node }} - idf.py --ccache build - ccache -s - - - name: Upload Build Artifact - uses: actions/upload-artifact@v2.2.4 - with: - name: bobbyquad_${{ matrix.node }} - path: | - build_${{ matrix.node }}/bobbyquad_${{ matrix.node }}.bin - build_${{ matrix.node }}/bobbyquad_${{ matrix.node }}.elf - build_${{ matrix.node }}/bootloader/bootloader.bin - build_${{ matrix.node }}/bootloader/bootloader.elf - build_${{ matrix.node }}/partition_table/partition-table.bin From 57fe5b14b78fce96a42658cccb5890e939015edf Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Dec 2021 07:33:17 +0100 Subject: [PATCH 06/14] Added ledstrip --- config_mick.cmake | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/config_mick.cmake b/config_mick.cmake index b538f2b..ef85159 100644 --- a/config_mick.cmake +++ b/config_mick.cmake @@ -78,19 +78,19 @@ set(BOBBYCAR_BUILDFLAGS # -DDEFAULT_GAMETRAKDISTMIN=0 # -DDEFAULT_GAMETRAKDISTMAX=4095 # -DFEATURE_POWERSUPPLY -# -DFEATURE_CLOUD + -DFEATURE_CLOUD -DFEATURE_LEDBACKLIGHT -DPINS_LEDBACKLIGHT=23 -DLEDBACKLIGHT_INVERTED # -DFEATURE_GARAGE # -DFEATURE_NTP - -DFEATURE_WIRELESS_CONFIG -# -DFEATURE_LEDSTRIP -# -DPINS_LEDSTRIP=26 + -DFEATURE_WIRELESS_CONFIG + -DFEATURE_LEDSTRIP + -DPINS_LEDSTRIP=33 # -DLEDSTRIP_WRONG_DIRECTION -# -DLEDSTRIP_ANIMATION_DEFAULT=0 - -DOLD_NVS -# -DFEATURE_DNS_NS + -DLEDSTRIP_ANIMATION_DEFAULT=0 + -DOLD_NVS + -DFEATURE_DNS_NS ) if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/ignore/lockscreen_plugin.cmake") From b8172e7b6336168ac852112cd53600434676d318 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Dec 2021 07:40:39 +0100 Subject: [PATCH 07/14] Added ledstrip length --- config_mick.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/config_mick.cmake b/config_mick.cmake index ef85159..6359cd0 100644 --- a/config_mick.cmake +++ b/config_mick.cmake @@ -86,6 +86,7 @@ set(BOBBYCAR_BUILDFLAGS # -DFEATURE_NTP -DFEATURE_WIRELESS_CONFIG -DFEATURE_LEDSTRIP + -DLEDSTRIP_LENGTH=288 -DPINS_LEDSTRIP=33 # -DLEDSTRIP_WRONG_DIRECTION -DLEDSTRIP_ANIMATION_DEFAULT=0 From 38470629b8c165454e5444baced47555929cf0ae Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Dec 2021 07:42:41 +0100 Subject: [PATCH 08/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c9de615..c6ecff0 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ | Service | Status | | :--- | ---: | -| Actions (master) | ![Build Status](https://github.com/bobbycar-graz/bobbycar-boardcomputer-firmware/actions/workflows/main.yml/badge.svg) | +| Actions | ![Build Status](https://github.com/bobbycar-graz/bobbycar-boardcomputer-firmware/actions/workflows/main.yml/badge.svg) | ## How to clone ? (READ THIS OR YOU WILL FAIL) From 64ac74ea5d2e00e8ff592b2eea9f2168551d51f4 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Dec 2021 08:06:38 +0100 Subject: [PATCH 09/14] Fixed non-feature-ota compiling --- main/accessors/settingsaccessors.h | 2 ++ main/displays/menus/ledstripmenu.cpp | 2 ++ main/displays/menus/ledstripselectotamode.h | 2 +- main/ledstrip.cpp | 11 ++++++++++- main/ledstrip.h | 4 ++++ main/presets.h | 2 ++ main/settings.h | 4 ++++ main/udpcloud.cpp | 2 -- 8 files changed, 25 insertions(+), 4 deletions(-) diff --git a/main/accessors/settingsaccessors.h b/main/accessors/settingsaccessors.h index f924ef8..57a61f3 100644 --- a/main/accessors/settingsaccessors.h +++ b/main/accessors/settingsaccessors.h @@ -179,8 +179,10 @@ struct EnableLedstripStVOFrontlight : public RefAccessorSaveSettings { boo struct AnimationMultiplierAccessor : public RefAccessorSaveSettings { int16_t &getRef() const override { return settings.ledstrip.animationMultiplier; } }; struct LedstripBrightnessAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.ledstrip.brightness; } }; struct LedstripEnableBlinkAnimationAccessor : public RefAccessorSaveSettings { bool &getRef() const override { return settings.ledstrip.enableAnimBlink; } }; +#ifdef FEATURE_OTA struct LedstripOtaAnimationAccessor : public RefAccessorSaveSettings { OtaAnimationModes &getRef() const override { return settings.ledstrip.otaMode; } }; #endif +#endif // Battery struct BatterySeriesCellsAccessor : public RefAccessorSaveSettings { uint8_t &getRef() const override { return settings.battery.cellsSeries; } }; diff --git a/main/displays/menus/ledstripmenu.cpp b/main/displays/menus/ledstripmenu.cpp index f0ea464..cdeba51 100644 --- a/main/displays/menus/ledstripmenu.cpp +++ b/main/displays/menus/ledstripmenu.cpp @@ -127,7 +127,9 @@ LedstripMenu::LedstripMenu() constructMenuItem, SwitchScreenAction>>(); constructMenuItem, SwitchScreenAction>>(); +#ifdef FEATURE_OTA if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } +#endif constructMenuItem, SwitchScreenAction>>(); if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } if (!simplified) { constructMenuItem, SwitchScreenAction>>(); } diff --git a/main/displays/menus/ledstripselectotamode.h b/main/displays/menus/ledstripselectotamode.h index ad40792..f49e54d 100644 --- a/main/displays/menus/ledstripselectotamode.h +++ b/main/displays/menus/ledstripselectotamode.h @@ -11,7 +11,7 @@ #include "accessors/settingsaccessors.h" #include "ledstripmenu.h" -#ifdef FEATURE_LEDSTRIP +#if defined(FEATURE_LEDSTRIP) && defined(FEATURE_OTA) using namespace espgui; template diff --git a/main/ledstrip.cpp b/main/ledstrip.cpp index f8763dd..8aed3aa 100644 --- a/main/ledstrip.cpp +++ b/main/ledstrip.cpp @@ -213,7 +213,12 @@ void updateLedStrip() void showAnimation() { - if (settings.ledstrip.enableLedAnimation && !simplified && !(asyncOtaTaskStarted && settings.ledstrip.otaMode != OtaAnimationModes::None)) + if (settings.ledstrip.enableLedAnimation + && !simplified +#ifdef FEATURE_OTA + && !(asyncOtaTaskStarted && settings.ledstrip.otaMode != OtaAnimationModes::None) +#endif + ) { if (animation_type == LedstripAnimation::DefaultRainbow) showDefaultLedstrip(); else if (animation_type == LedstripAnimation::BetterRainbow) showBetterRainbow(); @@ -221,17 +226,20 @@ void showAnimation() else if (animation_type == LedstripAnimation::CustomColor) showCustomColor(); else showDefaultLedstrip(); } +#ifdef FEATURE_OTA else if (asyncOtaTaskStarted && settings.ledstrip.otaMode != OtaAnimationModes::None) { // show ota animation showOtaAnimation(); } +#endif else { std::fill(std::begin(leds), std::end(leds), CRGB{0, 0, 0}); } } +#ifdef FEATURE_OTA void showOtaAnimation() { std::fill(std::begin(leds), std::end(leds), CRGB{0,0,0}); @@ -260,6 +268,7 @@ void showOtaAnimation() } } } +#endif void showBetterRainbow() { diff --git a/main/ledstrip.h b/main/ledstrip.h index e8edea8..2041841 100644 --- a/main/ledstrip.h +++ b/main/ledstrip.h @@ -19,12 +19,14 @@ enum Bobbycar_Side FRONT }; +#ifdef FEATURE_OTA enum OtaAnimationModes { None, GreenProgressBar, ColorChangeAll }; +#endif extern std::vector leds; extern uint8_t gHue; @@ -37,7 +39,9 @@ void showAnimation(); void showBetterRainbow(); void showSpeedSyncAnimation(); void showCustomColor(); +#ifdef FEATURE_OTA void showOtaAnimation(); +#endif void initLedStrip(); void updateLedStrip(); diff --git a/main/presets.h b/main/presets.h index c99feab..34c1f72 100644 --- a/main/presets.h +++ b/main/presets.h @@ -266,7 +266,9 @@ constexpr Settings::Ledstrip defaultLedstrip { .animationMultiplier = 10, .brightness = 255, .enableAnimBlink = false, +#ifdef FEATURE_OTA .otaMode = OtaAnimationModes::GreenProgressBar +#endif }; #endif diff --git a/main/settings.h b/main/settings.h index 6ba38b4..87549e4 100644 --- a/main/settings.h +++ b/main/settings.h @@ -183,7 +183,9 @@ struct Settings int16_t animationMultiplier; uint8_t brightness; bool enableAnimBlink; +#ifdef FEATURE_OTA OtaAnimationModes otaMode; +#endif } ledstrip; #endif @@ -330,7 +332,9 @@ void Settings::executeForEveryCommonSetting(T &&callable) callable("ledAnimMul", ledstrip.animationMultiplier); callable("ledbrightness", ledstrip.brightness); callable("enAnimBlink", ledstrip.enableAnimBlink); +#ifdef FEATURE_OTA callable("ledOtaAnim", ledstrip.otaMode); +#endif #endif callable("batteryCS", battery.cellsSeries); diff --git a/main/udpcloud.cpp b/main/udpcloud.cpp index 8e54855..443bdfb 100644 --- a/main/udpcloud.cpp +++ b/main/udpcloud.cpp @@ -4,11 +4,9 @@ constexpr const char * const TAG = "bobbycloud"; // 3rd party includes #include #include -#ifdef FEATURE_OTA #include #include #include -#endif // local includes #include "udpcloud.h" From 7761f415a57d889bea92764c714b2ef82fb28963 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Dec 2021 14:56:06 +0100 Subject: [PATCH 10/14] Added security to json backend --- main/presets.cpp | 2 +- main/webserver.cpp | 35 ++++++++++++++++++ main/webserver.h | 1 + main/webserver_displaycontrol.cpp | 8 +++- main/webserver_ota.cpp | 61 ++++++++++++++++++++++++++++++- main/webserver_ota.h | 1 + 6 files changed, 104 insertions(+), 4 deletions(-) diff --git a/main/presets.cpp b/main/presets.cpp index 17e1055..d764ba1 100644 --- a/main/presets.cpp +++ b/main/presets.cpp @@ -58,7 +58,7 @@ StringSettings makeDefaultStringSettings() #ifdef FEATURE_OTA .otaServerBranch = {}, #endif - .webserver_password = STRING(AP_PASSWORD), + .webserver_password = {}, }; } } // namespace presets diff --git a/main/webserver.cpp b/main/webserver.cpp index d98e657..a9bc32b 100644 --- a/main/webserver.cpp +++ b/main/webserver.cpp @@ -33,6 +33,7 @@ void initWebserver() httpd_uri_t { .uri = "/reboot", .method = HTTP_GET, .handler = webserver_reboot_handler, .user_ctx = NULL }, #ifdef FEATURE_OTA httpd_uri_t { .uri = "/ota", .method = HTTP_GET, .handler = webserver_ota_handler, .user_ctx = NULL }, + httpd_uri_t { .uri = "/otaPercent", .method = HTTP_GET, .handler = webserver_ota_percentage_handler, .user_ctx = NULL }, httpd_uri_t { .uri = "/triggerOta", .method = HTTP_GET, .handler = webserver_trigger_ota_handler, .user_ctx = NULL }, #endif httpd_uri_t { .uri = "/settings", .method = HTTP_GET, .handler = webserver_settings_handler, .user_ctx = NULL }, @@ -42,6 +43,7 @@ void initWebserver() #ifdef OLD_NVS httpd_uri_t { .uri = "/dumpnvs", .method = HTTP_GET, .handler = webserver_dump_nvs_handler, .user_ctx = NULL }, #endif + httpd_uri_t { .uri = "/check", .method = HTTP_GET, .handler = webserver_status_handler, .user_ctx = NULL }, }) { const auto result = httpd_register_uri_handler(httpdHandle, &uri); @@ -66,4 +68,37 @@ esp_err_t webserver_reboot_handler(httpd_req_t *req) CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, "text/plain", "REBOOT called...") } +esp_err_t webserver_status_handler(httpd_req_t *req) +{ + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) + { + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); + } + + std::string body; + + std::string wants_json_query; + if (auto result = esphttpdutils::webserver_get_query(req)) + wants_json_query = *result; + else + { + ESP_LOGE(TAG, "%.*s", result.error().size(), result.error().data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", result.error()); + } + + char tmpBuf[256]; + const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); + if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty())) + { + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, "text/plain", "Ok."); + } + else + { + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", ""); + } +} + #endif diff --git a/main/webserver.h b/main/webserver.h index c312174..f349b3a 100644 --- a/main/webserver.h +++ b/main/webserver.h @@ -32,4 +32,5 @@ extern httpd_handle_t httpdHandle; void initWebserver(); void handleWebserver(); esp_err_t webserver_reboot_handler(httpd_req_t *req); +esp_err_t webserver_status_handler(httpd_req_t *req); #endif diff --git a/main/webserver_displaycontrol.cpp b/main/webserver_displaycontrol.cpp index a51140c..379aa81 100644 --- a/main/webserver_displaycontrol.cpp +++ b/main/webserver_displaycontrol.cpp @@ -30,7 +30,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req) char tmpBuf[256]; const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); - if (key_result == ESP_OK) + if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty())) { body += "{"; if (auto currentDisplay = static_cast(espgui::currentDisplay.get())) @@ -46,7 +46,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req) body += fmt::format("\"index\":{},\"items\":[", menuDisplay->selectedIndex()); menuDisplay->runForEveryMenuItem([&,selectedIndex=menuDisplay->selectedIndex()](const espgui::MenuItem &menuItem){ body += "{"; - body += fmt::format("\"name\":\"{}\",\"icon\":\"{}\"", menuItem.text(), "none"); // menuItem.icon()->name + body += fmt::format("\"name\":\"{}\",\"icon\":\"{}\"", menuItem.text(), menuItem.icon()->name); body += "},"; }); body += "],"; @@ -66,6 +66,10 @@ esp_err_t webserver_root_handler(httpd_req_t *req) } body += "}"; } + else if (tmpBuf != stringSettings.webserver_password) + { + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", ""); + } else { HtmlTag htmlTag{"html", body}; diff --git a/main/webserver_ota.cpp b/main/webserver_ota.cpp index 322bf18..a5cc84e 100644 --- a/main/webserver_ota.cpp +++ b/main/webserver_ota.cpp @@ -11,6 +11,61 @@ namespace { constexpr const char * const TAG = "BOBBYWEB"; } // namespace +esp_err_t webserver_ota_percentage_handler(httpd_req_t *req) +{ + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) + { + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); + } + + std::string body; + + std::string wants_json_query; + if (auto result = esphttpdutils::webserver_get_query(req)) + wants_json_query = *result; + else + { + ESP_LOGE(TAG, "%.*s", result.error().size(), result.error().data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", result.error()); + } + + char tmpBuf[256]; + const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); + if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty())) + { + body += "{"; + if (asyncOta) + { + if (const auto &appDesc = asyncOta->appDesc()) + { + const auto progress = asyncOta->progress(); + const auto totalSize = asyncOta->totalSize(); + + body += fmt::format("\"cur_ota_percent\":\"{}\",", (totalSize && *totalSize > 0) ? fmt::format("{:.02f}", float(progress) / *totalSize * 100) : "?"); + } + else + { + body += "\"err\":\"Could not access asyncOta->appDesc()\","; + } + } + else + { + body += "\"info\":\"Updater is not constructed.\""; + } + + body += "}"; + } + else if (tmpBuf != stringSettings.webserver_password) + { + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", ""); + } + + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, (key_result == ESP_OK) ? "application/json" : "text/html", body) +} + esp_err_t webserver_ota_handler(httpd_req_t *req) { espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; @@ -34,7 +89,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req) char tmpBuf[256]; const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); - if (key_result == ESP_OK) + if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty())) { body += "{"; @@ -86,6 +141,10 @@ esp_err_t webserver_ota_handler(httpd_req_t *req) body += "}}"; } + else if (tmpBuf != stringSettings.webserver_password) + { + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", ""); + } else { HtmlTag htmlTag{"html", body}; diff --git a/main/webserver_ota.h b/main/webserver_ota.h index cef270b..81c11e3 100644 --- a/main/webserver_ota.h +++ b/main/webserver_ota.h @@ -24,5 +24,6 @@ #if defined(FEATURE_WEBSERVER) && defined(FEATURE_OTA) esp_err_t webserver_ota_handler(httpd_req_t *req); +esp_err_t webserver_ota_percentage_handler(httpd_req_t *req); esp_err_t webserver_trigger_ota_handler(httpd_req_t *req); #endif From 24db6a7ce5928b3eb0c169da53b39b7d6731daa8 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Thu, 9 Dec 2021 22:43:31 +0100 Subject: [PATCH 11/14] Updated gui lib --- components/esp-gui-lib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp-gui-lib b/components/esp-gui-lib index 1e26302..9bc2e03 160000 --- a/components/esp-gui-lib +++ b/components/esp-gui-lib @@ -1 +1 @@ -Subproject commit 1e26302340372be34e50ca61c33d7682985ee635 +Subproject commit 9bc2e0353b31739de60f751afcfb0dcd3dfd3e75 From c6bfc4b77ab4e435ef6625580077f0629d084f55 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Fri, 10 Dec 2021 07:25:16 +0100 Subject: [PATCH 12/14] Fixed a few bugs in json view --- main/webserver.cpp | 3 +-- main/webserver_displaycontrol.cpp | 6 ++++-- main/webserver_dumpnvs.cpp | 1 + main/webserver_ota.cpp | 16 ++++++---------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/main/webserver.cpp b/main/webserver.cpp index a9bc32b..5c79fd6 100644 --- a/main/webserver.cpp +++ b/main/webserver.cpp @@ -70,6 +70,7 @@ esp_err_t webserver_reboot_handler(httpd_req_t *req) esp_err_t webserver_status_handler(httpd_req_t *req) { + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; if (!helper.locked()) { @@ -78,8 +79,6 @@ esp_err_t webserver_status_handler(httpd_req_t *req) CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } - std::string body; - std::string wants_json_query; if (auto result = esphttpdutils::webserver_get_query(req)) wants_json_query = *result; diff --git a/main/webserver_displaycontrol.cpp b/main/webserver_displaycontrol.cpp index 379aa81..6f18142 100644 --- a/main/webserver_displaycontrol.cpp +++ b/main/webserver_displaycontrol.cpp @@ -32,13 +32,14 @@ esp_err_t webserver_root_handler(httpd_req_t *req) const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty())) { + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); body += "{"; if (auto currentDisplay = static_cast(espgui::currentDisplay.get())) { body.reserve(4096); if (const auto *textInterface = currentDisplay->asTextInterface()) { - body += fmt::format("\"name:\"{}\",", textInterface->text()); + body += fmt::format("\"name\":\"{}\",", textInterface->text()); } if (const auto *menuDisplay = currentDisplay->asMenuDisplay()) @@ -46,7 +47,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req) body += fmt::format("\"index\":{},\"items\":[", menuDisplay->selectedIndex()); menuDisplay->runForEveryMenuItem([&,selectedIndex=menuDisplay->selectedIndex()](const espgui::MenuItem &menuItem){ body += "{"; - body += fmt::format("\"name\":\"{}\",\"icon\":\"{}\"", menuItem.text(), menuItem.icon()->name); + body += fmt::format("\"name\":\"{}\",\"icon\":\"{}\"", menuItem.text(), (menuItem.icon()) ? menuItem.icon()->name : ""); body += "},"; }); body += "],"; @@ -68,6 +69,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req) } else if (tmpBuf != stringSettings.webserver_password) { + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", ""); } else diff --git a/main/webserver_dumpnvs.cpp b/main/webserver_dumpnvs.cpp index 1fe4afb..601b563 100644 --- a/main/webserver_dumpnvs.cpp +++ b/main/webserver_dumpnvs.cpp @@ -113,6 +113,7 @@ showInputForSetting(std::string_view key, T value, JsonObject &body) esp_err_t webserver_dump_nvs_handler(httpd_req_t *req) { + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; if (!helper.locked()) { diff --git a/main/webserver_ota.cpp b/main/webserver_ota.cpp index a5cc84e..d5b495e 100644 --- a/main/webserver_ota.cpp +++ b/main/webserver_ota.cpp @@ -33,23 +33,17 @@ esp_err_t webserver_ota_percentage_handler(httpd_req_t *req) } char tmpBuf[256]; + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty())) { body += "{"; if (asyncOta) { - if (const auto &appDesc = asyncOta->appDesc()) - { - const auto progress = asyncOta->progress(); - const auto totalSize = asyncOta->totalSize(); + const auto progress = asyncOta->progress(); + const auto totalSize = asyncOta->totalSize(); - body += fmt::format("\"cur_ota_percent\":\"{}\",", (totalSize && *totalSize > 0) ? fmt::format("{:.02f}", float(progress) / *totalSize * 100) : "?"); - } - else - { - body += "\"err\":\"Could not access asyncOta->appDesc()\","; - } + body += fmt::format("\"cur_ota_percent\":\"{}\",", (totalSize && *totalSize > 0) ? fmt::format("{:.02f}", float(progress) / *totalSize * 100) : "?"); } else { @@ -91,6 +85,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req) const auto key_result = httpd_query_key_value(wants_json_query.data(), "json", tmpBuf, 256); if (key_result == ESP_OK && (tmpBuf == stringSettings.webserver_password || stringSettings.webserver_password.empty())) { + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); body += "{"; if (const esp_app_desc_t *app_desc = esp_ota_get_app_description()) @@ -143,6 +138,7 @@ esp_err_t webserver_ota_handler(httpd_req_t *req) } else if (tmpBuf != stringSettings.webserver_password) { + httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", ""); } else From f2e5478106dc69c0b6ae101279cf9dd84c87589b Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Fri, 10 Dec 2021 07:29:34 +0100 Subject: [PATCH 13/14] Added icon names corresponding to their .png filename --- main/icons/battery.cpp | 2 +- main/icons/bluetooth.cpp | 2 +- main/icons/buzzer.cpp | 2 +- main/icons/close.cpp | 2 +- main/icons/demos.cpp | 2 +- main/icons/graph.cpp | 2 +- main/icons/info.cpp | 2 +- main/icons/lock.cpp | 2 +- main/icons/modes.cpp | 2 +- main/icons/neopixel.cpp | 2 +- main/icons/poweroff.cpp | 2 +- main/icons/presets.cpp | 2 +- main/icons/reboot.cpp | 2 +- main/icons/scan.cpp | 2 +- main/icons/settings.cpp | 2 +- main/icons/statistics.cpp | 2 +- main/icons/time.cpp | 2 +- main/icons/update.cpp | 2 +- main/icons/wifi.cpp | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/main/icons/battery.cpp b/main/icons/battery.cpp index 55b6327..bccde7e 100644 --- a/main/icons/battery.cpp +++ b/main/icons/battery.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> battery{{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0220 (544) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "battery"}; } // namespace bobbyicons diff --git a/main/icons/bluetooth.cpp b/main/icons/bluetooth.cpp index d530cde..a0a3e35 100644 --- a/main/icons/bluetooth.cpp +++ b/main/icons/bluetooth.cpp @@ -39,6 +39,6 @@ const espgui::Icon<24, 24> bluetooth{{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x19ED, 0x4353, 0x53F5, 0x5C37, 0x5C57, 0x5C57, 0x5C37, 0x53F5, 0x4332, // 0x0220 (544) pixels 0x19ED, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels 0x00A6, 0x21EC, 0x2A6F, 0x32B1, 0x32B1, 0x2A6F, 0x19EC, 0x00A6, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "bluetooth"}; #endif } // namespace bobbyicons diff --git a/main/icons/buzzer.cpp b/main/icons/buzzer.cpp index 7f21926..4014d59 100644 --- a/main/icons/buzzer.cpp +++ b/main/icons/buzzer.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> buzzer{{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x5AEB, 0x52CA, 0x1884, 0x39C6, 0x39E7, 0x3A07, 0x52EA, 0x52AA, 0x0000, // 0x0220 (544) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels 0x52AA, 0x52CA, 0x5AEB, 0x5ACB, 0x5ACA, 0x4A4A, 0x52AA, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "buzzer"}; } // namespace bobbyicons diff --git a/main/icons/close.cpp b/main/icons/close.cpp index 681491f..303894e 100644 --- a/main/icons/close.cpp +++ b/main/icons/close.cpp @@ -34,5 +34,5 @@ const espgui::Icon<32, 32> close{{ 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x5800,0xA800,0xB0A2,0xA8E3,0xA0A2,0xA041,0x9800,0x9800,0xA041,0xA0A2,0xA8E3,0xB0A2,0xA800,0x5800,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 29, 960 pixels 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x3000,0x6000,0x8800,0xA000,0xA800,0xA800,0xA000,0x8800,0x6000,0x3000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 30, 992 pixels 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, // row 31, 1024 pixels -}}; +}, "close"}; } // namespace bobbyicons diff --git a/main/icons/demos.cpp b/main/icons/demos.cpp index f6a9142..75d436b 100644 --- a/main/icons/demos.cpp +++ b/main/icons/demos.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> demos{{ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x9CF3, 0xB5B6, 0xC638, 0xC638, 0xB596, 0xA514, 0x9CD3, 0x94B2, 0x9CD3, 0xA514, 0xAD75, 0xC618, // 0x0220 (544) pixels 0xC638, 0xBDD7, 0xA514, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xCE79, // 0x0230 (560) pixels 0xD6DA, 0xDEFB, 0xE71C, 0xE73C, 0xE71C, 0xE71C, 0xDEDB, 0xD69A, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0240 (576) pixels -}}; +}, "demos"}; } // namespace bobbyicons diff --git a/main/icons/graph.cpp b/main/icons/graph.cpp index defd71c..dba2775 100644 --- a/main/icons/graph.cpp +++ b/main/icons/graph.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> graph{{ 0x0000, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, // 0x0220 (544) pixels 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x0000, 0x0000, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x738E, 0x7BCF, 0x7BCF, // 0x0230 (560) pixels 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x738E, 0x7BCF, 0x7BCF, 0x7BCF, 0x7BCF, 0x0000, // 0x0240 (576) pixels -}}; +}, "graph"}; } // namespace bobbyicons diff --git a/main/icons/info.cpp b/main/icons/info.cpp index 304eb7e..e756081 100644 --- a/main/icons/info.cpp +++ b/main/icons/info.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> info{{ 0x0000, 0x0000, 0x0000, 0x014C, 0x016D, 0x0335, 0x014C, 0x01AE, 0x0210, 0x0272, 0x02B4, 0x02B4, 0x02D4, 0x02B4, 0x0272, 0x0210, // 0x0220 (544) pixels 0x01AE, 0x014B, 0x0315, 0x016D, 0x014C, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x00C6, 0x014C, 0x01EE, 0x016C, // 0x0230 (560) pixels 0x01AD, 0x01CE, 0x01EE, 0x01CE, 0x01CE, 0x01EE, 0x01CE, 0x01AD, 0x016C, 0x01EE, 0x016C, 0x00A5, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "info"}; } // namespace bobbyicons diff --git a/main/icons/lock.cpp b/main/icons/lock.cpp index 28233d9..dc92a22 100644 --- a/main/icons/lock.cpp +++ b/main/icons/lock.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> lock{{ 0x0000, 0x0000, 0x0000, 0x0000, 0xC569, 0xE648, 0xE5E2, 0xD540, 0xC4E0, 0xBC60, 0xB420, 0xB420, 0xB440, 0xBC60, 0xC480, 0xCD00, // 0x0220 (544) pixels 0xDDA0, 0xE687, 0xDE8F, 0xACEB, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "lock"}; } // namespace bobbyicons diff --git a/main/icons/modes.cpp b/main/icons/modes.cpp index 3cb82ec..0c26f9a 100644 --- a/main/icons/modes.cpp +++ b/main/icons/modes.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> modes{{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0007, 0x0000, 0x0002, 0x0849, 0x2190, 0x3270, 0x3B30, 0x3B90, 0x3B90, 0x2B0F, 0x224F, 0x114C, // 0x0220 (544) pixels 0x0046, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0003, 0x0000, // 0x0230 (560) pixels 0x0000, 0x0004, 0x0006, 0x0007, 0x0007, 0x0006, 0x0003, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "modes"}; } // namespace bobbyicons diff --git a/main/icons/neopixel.cpp b/main/icons/neopixel.cpp index abc80fa..f61b4bd 100644 --- a/main/icons/neopixel.cpp +++ b/main/icons/neopixel.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> neopixel{{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0x0000, 0x0000, // 0x0220 (544) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "neopixel"}; } // namespace bobbyicons diff --git a/main/icons/poweroff.cpp b/main/icons/poweroff.cpp index 4bea6a7..b2242f4 100644 --- a/main/icons/poweroff.cpp +++ b/main/icons/poweroff.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> poweroff{{ 0xA8C3, 0xA1A5, 0x9984, 0x9102, 0x9122, 0x9942, 0x9942, 0x9962, 0x9962, 0x9982, 0x9982, 0x9982, 0x9982, 0x9982, 0x9982, 0x9962, // 0x0220 (544) pixels 0x9962, 0x9142, 0x9142, 0x9122, 0x9122, 0x9143, 0x8903, 0x9820, 0xB000, 0xA061, 0x9061, 0x9020, 0x9020, 0x9020, 0x9020, 0x9020, // 0x0230 (560) pixels 0x9020, 0x9020, 0x9020, 0x8820, 0x8820, 0x8820, 0x8820, 0x8820, 0x8820, 0x8820, 0x8820, 0x8820, 0x9040, 0x9040, 0x9820, 0xB800, // 0x0240 (576) pixels -}}; +}, "poweroff"}; } // namespace bobbyicons diff --git a/main/icons/presets.cpp b/main/icons/presets.cpp index 0f7f191..6e7af4d 100644 --- a/main/icons/presets.cpp +++ b/main/icons/presets.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> presets{{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x1120, 0x2A41, 0x3B02, 0x4B83, 0x4BA4, 0x4B83, 0x4343, 0x32A2, 0x21A1, // 0x0220 (544) pixels 0x0880, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels 0x0000, 0x0000, 0x0880, 0x08E0, 0x08C0, 0x0040, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "presets"}; } // namespace bobbyicons diff --git a/main/icons/reboot.cpp b/main/icons/reboot.cpp index 905710f..795772f 100644 --- a/main/icons/reboot.cpp +++ b/main/icons/reboot.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> reboot{{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0220 (544) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "reboot"}; } // namespace bobbyicons diff --git a/main/icons/scan.cpp b/main/icons/scan.cpp index a09880a..362bbbc 100644 --- a/main/icons/scan.cpp +++ b/main/icons/scan.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> scan{{ 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x20E4, 0x20C4, 0x0000, 0x0000, 0x0000, // 0x0220 (544) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0x0000, 0x1082, 0x0000, 0x0000, // 0x0230 (560) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x10A2, 0x0000, 0x0000, 0xFFFF, 0xFFFF, 0xFFFF, // 0x0240 (576) pixels -}}; +}, "scan"}; } // namespace bobbyicons diff --git a/main/icons/settings.cpp b/main/icons/settings.cpp index e22c559..49fdefa 100644 --- a/main/icons/settings.cpp +++ b/main/icons/settings.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> settings{{ 0x122E, 0x122E, 0x1969, 0x0000, 0x0000, 0x0800, 0x0800, 0x0800, 0x0800, 0x0820, 0x0820, 0x0840, 0x0061, 0x0061, 0x0041, 0x0041, // 0x0220 (544) pixels 0x0041, 0x0042, 0x0000, 0x0000, 0x0000, 0x5841, 0x5841, 0x5841, 0x122E, 0x122E, 0x1969, 0x0000, 0x0000, 0x0800, 0x0800, 0x0800, // 0x0230 (560) pixels 0x0800, 0x0820, 0x0820, 0x0840, 0x0061, 0x0061, 0x0041, 0x0041, 0x0041, 0x0042, 0x0800, 0x0800, 0x0000, 0x5841, 0x5841, 0x5841, // 0x0240 (576) pixels -}}; +}, "settings"}; } // namespace bobbyicons diff --git a/main/icons/statistics.cpp b/main/icons/statistics.cpp index 83b9471..df36778 100644 --- a/main/icons/statistics.cpp +++ b/main/icons/statistics.cpp @@ -39,6 +39,6 @@ const espgui::Icon<24, 24> statistics{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0xA3E1, 0xFE21, 0xE5A1, 0xB461, 0x3960, 0x5200, 0x8320, 0xA3C0, 0xE581, 0xFE21, // 0x0220 (544) pixels 0xFE21, 0xE581, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0020, 0x0020, // 0x0230 (560) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x3960, 0xC4C1, 0xF601, 0x8340, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels - } + }, "statistics" }; } // namespace bobbyicons diff --git a/main/icons/time.cpp b/main/icons/time.cpp index b956a38..f79e656 100644 --- a/main/icons/time.cpp +++ b/main/icons/time.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> time{{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x18A3, 0x41C9, 0x4A2B, 0x524C, 0x524C, 0x4A2B, 0x39A9, 0x10A3, // 0x0220 (544) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "time"}; } // namespace diff --git a/main/icons/update.cpp b/main/icons/update.cpp index 1d4c118..8c3a1e9 100644 --- a/main/icons/update.cpp +++ b/main/icons/update.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> update{{ 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x1480, 0x2CE3, 0x0BE0, 0x0D20, 0x0000, // 0x0220 (544) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0230 (560) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0B40, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "update"}; } // namespace bobbyicons diff --git a/main/icons/wifi.cpp b/main/icons/wifi.cpp index 5573268..651eac2 100644 --- a/main/icons/wifi.cpp +++ b/main/icons/wifi.cpp @@ -38,5 +38,5 @@ const espgui::Icon<24, 24> wifi{{ 0x0000, 0x0000, 0x8C50, 0x8C50, 0x6B6D, 0x7BEF, 0xC637, 0x2124, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, // 0x0220 (544) pixels 0x634C, 0x9D13, 0x7BEF, 0x738D, 0x8C50, 0x8C50, 0x0000, 0x0000, 0x0000, 0x0000, 0x8C50, 0x8C50, 0x8430, 0x8430, 0x0000, 0x0000, // 0x0230 (560) pixels 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x8430, 0x8430, 0x8C50, 0x8C50, 0x0000, 0x0000, // 0x0240 (576) pixels -}}; +}, "wifi"}; } // namespace bobbyicons From 1f9a53dd7eab5747877e2d2b089af744c8f9ecfa Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Fri, 10 Dec 2021 10:01:49 +0100 Subject: [PATCH 14/14] Added color and fixed json --- main/webserver_displaycontrol.cpp | 57 +++++++++++++++++++++++++++++-- main/webserver_ota.cpp | 17 ++++++++- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/main/webserver_displaycontrol.cpp b/main/webserver_displaycontrol.cpp index 6f18142..69dd915 100644 --- a/main/webserver_displaycontrol.cpp +++ b/main/webserver_displaycontrol.cpp @@ -47,7 +47,52 @@ esp_err_t webserver_root_handler(httpd_req_t *req) body += fmt::format("\"index\":{},\"items\":[", menuDisplay->selectedIndex()); menuDisplay->runForEveryMenuItem([&,selectedIndex=menuDisplay->selectedIndex()](const espgui::MenuItem &menuItem){ body += "{"; - body += fmt::format("\"name\":\"{}\",\"icon\":\"{}\"", menuItem.text(), (menuItem.icon()) ? menuItem.icon()->name : ""); + const auto itemName = menuItem.text(); + std::string color{}; + std::string font{}; + switch (menuItem.color()) { + case TFT_RED: + color = "&1"; + break; + case TFT_GREEN: + color = "&2"; + break; + case TFT_BLUE: + color = "&3"; + break; + case TFT_YELLOW: + color = "&4"; + break; + case TFT_BLACK: + color = "&5"; + break; + case TFT_WHITE: + color = "&6"; + break; + case TFT_GREY: + case TFT_DARKGREY: + color = "&7"; + break; + default: + color = ""; + break; + } + + switch (menuItem.font()) + { + case 2: + font = "&s"; + break; + case 4: + font = "&m"; + break; + default: + font = ""; + break; + } + + std::string menuItemName = font + color + itemName; + body += fmt::format("\"name\":\"{}\",\"icon\":\"{}\",\"index\":{}", menuItemName, (menuItem.icon()) ? menuItem.icon()->name : "", selectedIndex); body += "},"; }); body += "],"; @@ -66,8 +111,16 @@ esp_err_t webserver_root_handler(httpd_req_t *req) body += "\"err\":\"Currently no screen instantiated.\","; } body += "}"; + + size_t lastGesch = body.rfind("},"); + if (std::string::npos != lastGesch) + body = body.erase(lastGesch+1, 1); + + size_t lastEckig = body.rfind("],"); + if (std::string::npos != lastEckig) + body = body.erase(lastEckig+1, 1); } - else if (tmpBuf != stringSettings.webserver_password) + else if (key_result != ESP_ERR_NOT_FOUND && tmpBuf != stringSettings.webserver_password) { httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", ""); diff --git a/main/webserver_ota.cpp b/main/webserver_ota.cpp index d5b495e..ca9e01f 100644 --- a/main/webserver_ota.cpp +++ b/main/webserver_ota.cpp @@ -52,11 +52,19 @@ esp_err_t webserver_ota_percentage_handler(httpd_req_t *req) body += "}"; } - else if (tmpBuf != stringSettings.webserver_password) + else if (key_result != ESP_ERR_NOT_FOUND && tmpBuf != stringSettings.webserver_password) { CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Unauthorized, "text/plain", ""); } + size_t lastGesch = body.rfind("},"); + if (std::string::npos != lastGesch) + body = body.erase(lastGesch+1, 1); + + size_t lastEckig = body.rfind("],"); + if (std::string::npos != lastEckig) + body = body.erase(lastEckig+1, 1); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::Ok, (key_result == ESP_OK) ? "application/json" : "text/html", body) } @@ -135,6 +143,13 @@ esp_err_t webserver_ota_handler(httpd_req_t *req) } body += "}}"; + size_t lastGesch = body.rfind("},"); + if (std::string::npos != lastGesch) + body = body.erase(lastGesch+1, 1); + + size_t lastEckig = body.rfind("],"); + if (std::string::npos != lastEckig) + body = body.erase(lastEckig+1, 1); } else if (tmpBuf != stringSettings.webserver_password) {