From a5fc54e87dcac81009fdcc0a37f2d106064da148 Mon Sep 17 00:00:00 2001 From: Ralf Bauer Date: Thu, 21 Dec 2023 21:45:20 +0100 Subject: [PATCH] fixed problem in initialization --- include/WebApi_database.h | 2 +- src/WebApi.cpp | 1 + src/WebApi_database.cpp | 15 ++++++++------- webapp/package.json | 3 +-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/WebApi_database.h b/include/WebApi_database.h index 98aa75e6..6a52d03c 100644 --- a/include/WebApi_database.h +++ b/include/WebApi_database.h @@ -8,7 +8,7 @@ class WebApiDatabaseClass { public: - void init(AsyncWebServer* server); + void init(AsyncWebServer& server); void loop(); bool write(float energy); diff --git a/src/WebApi.cpp b/src/WebApi.cpp index dce783a1..3e2e124d 100644 --- a/src/WebApi.cpp +++ b/src/WebApi.cpp @@ -34,6 +34,7 @@ void WebApiClass::init(Scheduler& scheduler) _webApiWebapp.init(_server); _webApiWsConsole.init(_server); _webApiWsLive.init(_server); + _webApiWsDatabase.init(_server); _server.begin(); diff --git a/src/WebApi_database.cpp b/src/WebApi_database.cpp index 264b9940..bd8269e4 100644 --- a/src/WebApi_database.cpp +++ b/src/WebApi_database.cpp @@ -1,19 +1,20 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "WebApi_database.h" +#include "WebApi.h" #include "Datastore.h" #include "MessageOutput.h" -#include "WebApi.h" #include "defaults.h" #include #include #include -void WebApiDatabaseClass::init(AsyncWebServer* server) +void WebApiDatabaseClass::init(AsyncWebServer& server) { using std::placeholders::_1; - _server = server; + _server = &server; + _server->on("/api/database", HTTP_GET, std::bind(&WebApiDatabaseClass::onDatabase, this, _1)); _server->on("/api/databaseHour", HTTP_GET, std::bind(&WebApiDatabaseClass::onDatabaseHour, this, _1)); _server->on("/api/databaseDay", HTTP_GET, std::bind(&WebApiDatabaseClass::onDatabaseDay, this, _1)); @@ -70,7 +71,7 @@ bool WebApiDatabaseClass::write(float energy) File f = LittleFS.open(DATABASE_FILENAME, "a", true); if (!f) { - MessageOutput.println("Failed to append to database."); + MessageOutput.println("Failed to append the database."); return (false); } f.write((const uint8_t*)&d, sizeof(pvData)); @@ -128,9 +129,9 @@ size_t WebApiDatabaseClass::readchunk(uint8_t* buffer, size_t maxLen, size_t ind size_t WebApiDatabaseClass::readchunk_log(uint8_t* buffer, size_t maxLen, size_t index) { size_t x = readchunk(buffer, maxLen, index); - MessageOutput.println("----------"); - MessageOutput.println(maxLen); - MessageOutput.println(x); + //MessageOutput.println("----------"); + //MessageOutput.println(maxLen); + //MessageOutput.println(x); return (x); } diff --git a/webapp/package.json b/webapp/package.json index bee199ba..84584d79 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -19,10 +19,9 @@ "sortablejs": "^1.15.1", "spark-md5": "^3.0.2", "vue": "^3.3.13", - "vue-i18n": "^9.8.0", "vue-google-charts": "^1.1.0", + "vue-i18n": "^9.8.0", "vue-router": "^4.2.5" - }, "devDependencies": { "@intlify/unplugin-vue-i18n": "^1.6.0",