Merge 88557e49d4 into 3dc70ab40a
This commit is contained in:
commit
970d3cadf8
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,3 +1,4 @@
|
|||||||
{
|
{
|
||||||
"C_Cpp.clang_format_style": "WebKit"
|
"C_Cpp.clang_format_style": "WebKit",
|
||||||
|
"cmake.sourceDirectory": "C:/git/OpenDTU-Database/.pio/libdeps/generic_esp32/ArduinoJson/src"
|
||||||
}
|
}
|
||||||
29
README.md
29
README.md
@ -1,12 +1,35 @@
|
|||||||
# OpenDTU
|
# OpenDTU-Database-Database
|
||||||
|
# OpenDTU-Database
|
||||||
|
|
||||||
|
One year OpenDTU-Database
|
||||||
|

|
||||||
|
|
||||||
[](https://github.com/tbnobody/OpenDTU/actions/workflows/build.yml)
|
[](https://github.com/tbnobody/OpenDTU/actions/workflows/build.yml)
|
||||||
[](https://github.com/tbnobody/OpenDTU/actions/workflows/cpplint.yml)
|
[](https://github.com/tbnobody/OpenDTU/actions/workflows/cpplint.yml)
|
||||||
[](https://github.com/tbnobody/OpenDTU/actions/workflows/yarnlint.yml)
|
[](https://github.com/tbnobody/OpenDTU/actions/workflows/yarnlint.yml)
|
||||||
|
|
||||||
## !! IMPORTANT UPGRADE NOTES !!
|
OpenDTU-Database adds an ESP32 LittleFS Database and two energy charts, a column chart of the last 25 hours and a full calendar chart.
|
||||||
|
|
||||||
If you are upgrading from a version before 15.03.2023 you have to upgrade the partition table of the ESP32. Please follow the [this](docs/UpgradePartition.md) documentation!
|

|
||||||
|
|
||||||
|
OpenDTU-Database adds an ESP32 LittleFS Database and two energy charts, a column chart of the last 25 hours and a full calendar chart.
|
||||||
|
|
||||||
|
There are 3 new APIs available, returning JSON strings:
|
||||||
|
|
||||||
|
| API | returned values |
|
||||||
|
|-------------------|-----------------|
|
||||||
|
| /api/database | returns all recored data points from the database with total energy value |
|
||||||
|
| /api/databaseHour | returns the energy per hour for the last 25 hours |
|
||||||
|
| /api/databaseDay | returns the energy for each day |
|
||||||
|
|
||||||
|
Each data point has the following format:
|
||||||
|
[ _year (00-99)_, _month (1-12)_, _day (1-31)_, _hour (0-23)_, _energy (Wh)_ ]
|
||||||
|
|
||||||
|
Example: [23,6,30,15,132.995605]
|
||||||
|
|
||||||
|
The 192KB LittleFS in OpenDTU can store around 6 years of data, because each data point needs only 8 bytes of memory.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Background
|
## Background
|
||||||
|
|
||||||
|
|||||||
BIN
docs/screenshots/23_Database.png
Normal file
BIN
docs/screenshots/23_Database.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 204 KiB |
@ -89,3 +89,7 @@ here are some screenshots of OpenDTU's web interface.
|
|||||||
***
|
***
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
***
|
||||||
|
|
||||||
|

|
||||||
|
|||||||
BIN
docs/screenshots/Screenshot_2024-05-23_131208.png
Normal file
BIN
docs/screenshots/Screenshot_2024-05-23_131208.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 203 KiB |
@ -23,6 +23,7 @@
|
|||||||
#include "WebApi_webapp.h"
|
#include "WebApi_webapp.h"
|
||||||
#include "WebApi_ws_console.h"
|
#include "WebApi_ws_console.h"
|
||||||
#include "WebApi_ws_live.h"
|
#include "WebApi_ws_live.h"
|
||||||
|
#include "WebApi_database.h"
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <TaskSchedulerDeclarations.h>
|
#include <TaskSchedulerDeclarations.h>
|
||||||
@ -68,6 +69,7 @@ private:
|
|||||||
WebApiWebappClass _webApiWebapp;
|
WebApiWebappClass _webApiWebapp;
|
||||||
WebApiWsConsoleClass _webApiWsConsole;
|
WebApiWsConsoleClass _webApiWsConsole;
|
||||||
WebApiWsLiveClass _webApiWsLive;
|
WebApiWsLiveClass _webApiWsLive;
|
||||||
|
WebApiDatabaseClass _webApiWsDatabase;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern WebApiClass WebApi;
|
extern WebApiClass WebApi;
|
||||||
|
|||||||
37
include/WebApi_database.h
Normal file
37
include/WebApi_database.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <ESPAsyncWebServer.h>
|
||||||
|
#include <TaskSchedulerDeclarations.h>
|
||||||
|
|
||||||
|
#define DATABASE_FILENAME "/database.bin"
|
||||||
|
|
||||||
|
class WebApiDatabaseClass {
|
||||||
|
public:
|
||||||
|
WebApiDatabaseClass();
|
||||||
|
void init(AsyncWebServer& server, Scheduler& scheduler);
|
||||||
|
bool write(float energy);
|
||||||
|
|
||||||
|
struct pvData {
|
||||||
|
uint8_t tm_year;
|
||||||
|
uint8_t tm_mon;
|
||||||
|
uint8_t tm_mday;
|
||||||
|
uint8_t tm_hour;
|
||||||
|
float energy;
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
void onDatabase(AsyncWebServerRequest* request);
|
||||||
|
void onDatabaseHour(AsyncWebServerRequest* request);
|
||||||
|
void onDatabaseDay(AsyncWebServerRequest* request);
|
||||||
|
static size_t readchunk(uint8_t* buffer, size_t maxLen, size_t index);
|
||||||
|
static size_t readchunk_log(uint8_t* buffer, size_t maxLen, size_t index);
|
||||||
|
static size_t readchunkHour(uint8_t* buffer, size_t maxLen, size_t index);
|
||||||
|
static size_t readchunkDay(uint8_t* buffer, size_t maxLen, size_t index);
|
||||||
|
|
||||||
|
AsyncWebServer* _server;
|
||||||
|
|
||||||
|
Task _sendDataTask;
|
||||||
|
void sendDataTaskCb();
|
||||||
|
};
|
||||||
@ -36,6 +36,7 @@ void WebApiClass::init(Scheduler& scheduler)
|
|||||||
_webApiWebapp.init(_server, scheduler);
|
_webApiWebapp.init(_server, scheduler);
|
||||||
_webApiWsConsole.init(_server, scheduler);
|
_webApiWsConsole.init(_server, scheduler);
|
||||||
_webApiWsLive.init(_server, scheduler);
|
_webApiWsLive.init(_server, scheduler);
|
||||||
|
_webApiWsDatabase.init(_server, scheduler);
|
||||||
|
|
||||||
_server.begin();
|
_server.begin();
|
||||||
}
|
}
|
||||||
|
|||||||
323
src/WebApi_database.cpp
Normal file
323
src/WebApi_database.cpp
Normal file
@ -0,0 +1,323 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include "WebApi_database.h"
|
||||||
|
#include "WebApi.h"
|
||||||
|
#include "Datastore.h"
|
||||||
|
#include "MessageOutput.h"
|
||||||
|
#include "defaults.h"
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <AsyncJson.h>
|
||||||
|
#include <LittleFS.h>
|
||||||
|
|
||||||
|
|
||||||
|
WebApiDatabaseClass::WebApiDatabaseClass()
|
||||||
|
: _sendDataTask(1 * TASK_MINUTE, TASK_FOREVER, std::bind(&WebApiDatabaseClass::sendDataTaskCb, this))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebApiDatabaseClass::init(AsyncWebServer& server, Scheduler& scheduler)
|
||||||
|
{
|
||||||
|
using std::placeholders::_1;
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
scheduler.addTask(_sendDataTask);
|
||||||
|
_sendDataTask.enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebApiDatabaseClass::sendDataTaskCb()
|
||||||
|
{
|
||||||
|
if (!Hoymiles.isAllRadioIdle()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
write(Datastore.getTotalAcYieldTotalEnabled()); // write value to database
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WebApiDatabaseClass::write(float energy)
|
||||||
|
{
|
||||||
|
static uint8_t old_hour = 255;
|
||||||
|
static float old_energy = 0.0;
|
||||||
|
|
||||||
|
// LittleFS.remove(DATABASE_FILENAME);
|
||||||
|
|
||||||
|
// MessageOutput.println(energy, 6);
|
||||||
|
|
||||||
|
struct tm timeinfo;
|
||||||
|
if (!getLocalTime(&timeinfo, 5)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (timeinfo.tm_hour == old_hour) // must be new hour
|
||||||
|
return (false);
|
||||||
|
if (old_hour == 255) { // don't write to database after reboot
|
||||||
|
old_hour = timeinfo.tm_hour;
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
// MessageOutput.println("Next hour.");
|
||||||
|
if (energy <= old_energy) // enery must have increased
|
||||||
|
return (false);
|
||||||
|
// MessageOutput.println("Energy difference > 0");
|
||||||
|
|
||||||
|
struct pvData d;
|
||||||
|
d.tm_hour = timeinfo.tm_hour - 1;
|
||||||
|
old_hour = timeinfo.tm_hour;
|
||||||
|
d.tm_year = timeinfo.tm_year - 100; // year counting from 2000
|
||||||
|
d.tm_mon = timeinfo.tm_mon + 1;
|
||||||
|
d.tm_mday = timeinfo.tm_mday;
|
||||||
|
d.energy = old_energy = energy;
|
||||||
|
|
||||||
|
// create database file if it does not exist
|
||||||
|
// if (!LittleFS.exists(DATABASE_FILENAME)) {
|
||||||
|
// MessageOutput.println("Database file does not exist.");
|
||||||
|
// File f = LittleFS.open(DATABASE_FILENAME, "w", true);
|
||||||
|
// f.flush();
|
||||||
|
// f.close();
|
||||||
|
// MessageOutput.println("New database file created.");
|
||||||
|
//}
|
||||||
|
|
||||||
|
File f = LittleFS.open(DATABASE_FILENAME, "a", true);
|
||||||
|
if (!f) {
|
||||||
|
MessageOutput.println("Failed to append the database.");
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
f.write((const uint8_t*)&d, sizeof(pvData));
|
||||||
|
f.close();
|
||||||
|
// MessageOutput.println("Write data point.");
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// read chunk from database
|
||||||
|
size_t WebApiDatabaseClass::readchunk(uint8_t* buffer, size_t maxLen, size_t index)
|
||||||
|
{
|
||||||
|
static bool first = true;
|
||||||
|
static bool last = false;
|
||||||
|
static File f;
|
||||||
|
uint8_t* pr = buffer;
|
||||||
|
uint8_t* pre = pr + maxLen - 50;
|
||||||
|
size_t r;
|
||||||
|
struct pvData d;
|
||||||
|
|
||||||
|
if (first) {
|
||||||
|
f = LittleFS.open(DATABASE_FILENAME, "r", false);
|
||||||
|
if (!f) {
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
*pr++ = '[';
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
r = f.read(reinterpret_cast<uint8_t*>(&d), sizeof(pvData)); // read from database
|
||||||
|
if (r <= 0) {
|
||||||
|
if (last) {
|
||||||
|
f.close();
|
||||||
|
first = true;
|
||||||
|
last = false;
|
||||||
|
return (0); // end transmission
|
||||||
|
}
|
||||||
|
last = true;
|
||||||
|
*pr++ = ']';
|
||||||
|
return (pr - buffer); // last chunk
|
||||||
|
}
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
*pr++ = ',';
|
||||||
|
}
|
||||||
|
int len = snprintf(reinterpret_cast<char*>(pr), maxLen, "[%d,%d,%d,%d,%f]",
|
||||||
|
d.tm_year, d.tm_mon, d.tm_mday, d.tm_hour, d.energy * 1e3);
|
||||||
|
if (len >= 0) {
|
||||||
|
pr += len;
|
||||||
|
}
|
||||||
|
if (pr >= pre)
|
||||||
|
return (pr - buffer); // buffer full, return number of chars
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
return (x);
|
||||||
|
}
|
||||||
|
|
||||||
|
// read chunk from database for the last 25 hours
|
||||||
|
size_t WebApiDatabaseClass::readchunkHour(uint8_t* buffer, size_t maxLen, size_t index)
|
||||||
|
{
|
||||||
|
static bool first = true;
|
||||||
|
static bool last = false;
|
||||||
|
static bool valid = false;
|
||||||
|
static float oldenergy = 0.0;
|
||||||
|
static File f;
|
||||||
|
static bool fileopen = false;
|
||||||
|
union datehour {
|
||||||
|
uint32_t dh;
|
||||||
|
uint8_t dd[4];
|
||||||
|
};
|
||||||
|
static datehour startdate;
|
||||||
|
uint8_t* pr = buffer;
|
||||||
|
uint8_t* pre = pr + maxLen - 50;
|
||||||
|
size_t r;
|
||||||
|
struct pvData d;
|
||||||
|
|
||||||
|
if (!fileopen) {
|
||||||
|
time_t now;
|
||||||
|
struct tm sdate;
|
||||||
|
time(&now);
|
||||||
|
time_t stime = now - (60 * 60 * 25); // subtract 25h
|
||||||
|
localtime_r(&stime, &sdate);
|
||||||
|
if (sdate.tm_year <= (2016 - 1900)) {
|
||||||
|
return (false); // time not set
|
||||||
|
}
|
||||||
|
startdate.dd[3] = sdate.tm_year - 100;
|
||||||
|
startdate.dd[2] = sdate.tm_mon + 1;
|
||||||
|
startdate.dd[1] = sdate.tm_mday;
|
||||||
|
startdate.dd[0] = sdate.tm_hour;
|
||||||
|
|
||||||
|
f = LittleFS.open(DATABASE_FILENAME, "r", false);
|
||||||
|
if (!f) {
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
|
fileopen = true;
|
||||||
|
*pr++ = '[';
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
r = f.read(reinterpret_cast<uint8_t*>(&d), sizeof(pvData)); // read from database
|
||||||
|
if (r <= 0) {
|
||||||
|
if (last) {
|
||||||
|
f.close();
|
||||||
|
fileopen = false;
|
||||||
|
first = true;
|
||||||
|
last = false;
|
||||||
|
valid = false;
|
||||||
|
startdate.dh = 0L;
|
||||||
|
return (0); // end transmission
|
||||||
|
}
|
||||||
|
last = true;
|
||||||
|
*pr++ = ']';
|
||||||
|
return (pr - buffer); // last chunk
|
||||||
|
}
|
||||||
|
if (!valid) {
|
||||||
|
datehour cd;
|
||||||
|
cd.dd[3] = d.tm_year;
|
||||||
|
cd.dd[2] = d.tm_mon;
|
||||||
|
cd.dd[1] = d.tm_mday;
|
||||||
|
cd.dd[0] = d.tm_hour;
|
||||||
|
// MessageOutput.println(cd,16);
|
||||||
|
if ((cd.dh >= startdate.dh) && (oldenergy > 0.0)) {
|
||||||
|
valid = true;
|
||||||
|
} else
|
||||||
|
oldenergy = d.energy;
|
||||||
|
}
|
||||||
|
if (valid) {
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else {
|
||||||
|
*pr++ = ',';
|
||||||
|
}
|
||||||
|
int len = snprintf(reinterpret_cast<char*>(pr), maxLen, "[%d,%d,%d,%d,%f]",
|
||||||
|
d.tm_year, d.tm_mon, d.tm_mday, d.tm_hour,
|
||||||
|
(d.energy - oldenergy) * 1e3);
|
||||||
|
oldenergy = d.energy;
|
||||||
|
if (len >= 0) {
|
||||||
|
pr += len;
|
||||||
|
}
|
||||||
|
if (pr >= pre) {
|
||||||
|
return (pr - buffer); // buffer full, return number of chars
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// read chunk from database for calendar view
|
||||||
|
size_t WebApiDatabaseClass::readchunkDay(uint8_t* buffer, size_t maxLen, size_t index)
|
||||||
|
{
|
||||||
|
static bool first = true;
|
||||||
|
static bool last = false;
|
||||||
|
static float startenergy = 0.0;
|
||||||
|
static struct pvData endofday = { 0, 0, 0, 0, 0.0 };
|
||||||
|
static File f;
|
||||||
|
uint8_t* pr = buffer;
|
||||||
|
uint8_t* pre = pr + maxLen - 50;
|
||||||
|
size_t r;
|
||||||
|
struct pvData d;
|
||||||
|
|
||||||
|
if (first) {
|
||||||
|
f = LittleFS.open(DATABASE_FILENAME, "r", false);
|
||||||
|
if (!f) {
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
*pr++ = '[';
|
||||||
|
}
|
||||||
|
while (true) {
|
||||||
|
r = f.read(reinterpret_cast<uint8_t*>(&d), sizeof(pvData)); // read from database
|
||||||
|
if (r <= 0) {
|
||||||
|
if (last) {
|
||||||
|
f.close();
|
||||||
|
first = true;
|
||||||
|
last = false;
|
||||||
|
endofday = { 0, 0, 0, 0, 0.0 };
|
||||||
|
startenergy = 0.0;
|
||||||
|
return (0); // end transmission
|
||||||
|
}
|
||||||
|
last = true;
|
||||||
|
if (!first)
|
||||||
|
*pr++ = ',';
|
||||||
|
int len = snprintf(reinterpret_cast<char*>(pr), maxLen, "[%d,%d,%d,%d,%f]",
|
||||||
|
endofday.tm_year, endofday.tm_mon, endofday.tm_mday, endofday.tm_hour,
|
||||||
|
(endofday.energy - startenergy) * 1e3);
|
||||||
|
pr += len;
|
||||||
|
*pr++ = ']';
|
||||||
|
return (pr - buffer); // last chunk
|
||||||
|
}
|
||||||
|
if (startenergy == 0.0) {
|
||||||
|
if (d.energy > 0.0) {
|
||||||
|
startenergy = d.energy;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (endofday.tm_mday != d.tm_mday) { // next day
|
||||||
|
if (first) {
|
||||||
|
first = false;
|
||||||
|
} else
|
||||||
|
*pr++ = ',';
|
||||||
|
int len = snprintf(reinterpret_cast<char*>(pr), maxLen, "[%d,%d,%d,%d,%f]",
|
||||||
|
endofday.tm_year, endofday.tm_mon, endofday.tm_mday, endofday.tm_hour,
|
||||||
|
(endofday.energy - startenergy) * 1e3);
|
||||||
|
startenergy = endofday.energy;
|
||||||
|
if (len >= 0)
|
||||||
|
pr += len;
|
||||||
|
if (pr >= pre)
|
||||||
|
return (pr - buffer); // buffer full, return number of chars
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endofday = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebApiDatabaseClass::onDatabase(AsyncWebServerRequest* request)
|
||||||
|
{
|
||||||
|
if (!WebApi.checkCredentialsReadonly(request)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AsyncWebServerResponse* response = request->beginChunkedResponse("application/json", readchunk);
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebApiDatabaseClass::onDatabaseHour(AsyncWebServerRequest* request)
|
||||||
|
{
|
||||||
|
if (!WebApi.checkCredentialsReadonly(request)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AsyncWebServerResponse* response = request->beginChunkedResponse("application/json", readchunkHour);
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebApiDatabaseClass::onDatabaseDay(AsyncWebServerRequest* request)
|
||||||
|
{
|
||||||
|
if (!WebApi.checkCredentialsReadonly(request)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AsyncWebServerResponse* response = request->beginChunkedResponse("application/json", readchunkDay);
|
||||||
|
request->send(response);
|
||||||
|
}
|
||||||
BIN
webapp/.yarn/install-state.gz
Normal file
BIN
webapp/.yarn/install-state.gz
Normal file
Binary file not shown.
1
webapp/.yarnrc.yml
Normal file
1
webapp/.yarnrc.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
nodeLinker: node-modules
|
||||||
3878
webapp/package-lock.json
generated
Normal file
3878
webapp/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -13,6 +13,9 @@
|
|||||||
"format": "prettier --write src/"
|
"format": "prettier --write src/"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"vue-google-charts": "^1.1.0",
|
||||||
|
"vue3-calendar-heatmap": "^2.0.5",
|
||||||
|
"tippy.js": "^6.3.7",
|
||||||
"@popperjs/core": "^2.11.8",
|
"@popperjs/core": "^2.11.8",
|
||||||
"bootstrap": "^5.3.3",
|
"bootstrap": "^5.3.3",
|
||||||
"bootstrap-icons-vue": "^1.11.3",
|
"bootstrap-icons-vue": "^1.11.3",
|
||||||
|
|||||||
96
webapp/src/components/BarChart.vue
Normal file
96
webapp/src/components/BarChart.vue
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
<template>
|
||||||
|
<div class="card row" v-if="dataLoaded">
|
||||||
|
<GChart type="ColumnChart" :data="chartData" :options="chartOptions" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
import { GChart } from 'vue-google-charts';
|
||||||
|
import { authHeader, handleResponse } from '@/utils/authentication';
|
||||||
|
//import { DatetimeFormat } from 'vue-i18n';
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
let data_col: any;
|
||||||
|
|
||||||
|
const options_col = {
|
||||||
|
height: 300,
|
||||||
|
chartArea: {
|
||||||
|
top: 25,
|
||||||
|
width: '85%',
|
||||||
|
height: '80%',
|
||||||
|
},
|
||||||
|
bar: {
|
||||||
|
groupWidth: '90%',
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
position: 'none',
|
||||||
|
},
|
||||||
|
hAxis: {
|
||||||
|
format: 'HH',
|
||||||
|
minorGridlines: {
|
||||||
|
count: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
vAxis: {
|
||||||
|
minValue: 0,
|
||||||
|
format: '# Wh',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export default defineComponent({
|
||||||
|
components: {
|
||||||
|
GChart,
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
chartData: data_col,
|
||||||
|
chartOptions: options_col,
|
||||||
|
dataLoaded: false,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.getInitialData();
|
||||||
|
this.startautorefresh();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getInitialData() {
|
||||||
|
this.dataLoaded = false;
|
||||||
|
fetch('/api/databaseHour', { headers: authHeader() })
|
||||||
|
.then((response) => handleResponse(response, this.$emitter, this.$router))
|
||||||
|
.then((energy) => {
|
||||||
|
if (energy) {
|
||||||
|
this.chartData = [
|
||||||
|
[
|
||||||
|
{ type: 'date', id: 'Time' },
|
||||||
|
{ type: 'number', id: 'Energy' },
|
||||||
|
],
|
||||||
|
];
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
energy.forEach((x: any[]) => {
|
||||||
|
const d = new Date(x[0] + 2000, x[1] - 1, x[2], x[3]);
|
||||||
|
this.chartData.push([d, Math.round(x[4])]);
|
||||||
|
});
|
||||||
|
this.dataLoaded = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// let date_formatter = new google.visualization.DateFormat({
|
||||||
|
// pattern: "dd.MM.YY HH:mm"
|
||||||
|
// });
|
||||||
|
// date_formatter.format(data, 0);
|
||||||
|
},
|
||||||
|
callEveryHour() {
|
||||||
|
this.getInitialData();
|
||||||
|
setInterval(this.getInitialData, 1000 * 60 * 60); // refresh every hour
|
||||||
|
},
|
||||||
|
startautorefresh() {
|
||||||
|
const nextDate = new Date();
|
||||||
|
nextDate.setHours(nextDate.getHours() + 1);
|
||||||
|
nextDate.setMinutes(0);
|
||||||
|
nextDate.setSeconds(5);
|
||||||
|
const difference: number = nextDate.valueOf() - Date.now();
|
||||||
|
setTimeout(this.callEveryHour, difference);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
66
webapp/src/components/CalendarChart.vue
Normal file
66
webapp/src/components/CalendarChart.vue
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<template>
|
||||||
|
<div class="card row" v-if="dataLoaded">
|
||||||
|
<CalendarHeatmap
|
||||||
|
:values="values"
|
||||||
|
:round="1"
|
||||||
|
:end-date="endDate"
|
||||||
|
:style="{ 'font-size': '10px' }"
|
||||||
|
tooltip-unit="Wh"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
import { CalendarHeatmap } from 'vue3-calendar-heatmap';
|
||||||
|
import { authHeader, handleResponse } from '@/utils/authentication';
|
||||||
|
const data: Array<{ date: Date; count: number }> = [];
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
components: {
|
||||||
|
CalendarHeatmap,
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
values: data,
|
||||||
|
endDate: new Date(),
|
||||||
|
dataLoaded: false,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
created() {
|
||||||
|
this.getInitialData();
|
||||||
|
this.startautorefresh();
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
getInitialData() {
|
||||||
|
this.dataLoaded = false;
|
||||||
|
fetch('/api/databaseDay', { headers: authHeader() })
|
||||||
|
.then((response) => handleResponse(response, this.$emitter, this.$router))
|
||||||
|
.then((energy) => {
|
||||||
|
if (energy) {
|
||||||
|
this.values = [];
|
||||||
|
let d: Date;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
energy.forEach((x: any[]) => {
|
||||||
|
d = new Date(x[0] + 2000, x[1] - 1, x[2], x[3]);
|
||||||
|
this.values.push({ date: d, count: Math.round(x[4]) });
|
||||||
|
});
|
||||||
|
this.dataLoaded = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
callEveryHour() {
|
||||||
|
this.getInitialData();
|
||||||
|
setInterval(this.getInitialData, 1000 * 60 * 60); // refresh every hour
|
||||||
|
},
|
||||||
|
startautorefresh() {
|
||||||
|
const nextDate = new Date();
|
||||||
|
nextDate.setHours(nextDate.getHours() + 1);
|
||||||
|
nextDate.setMinutes(0);
|
||||||
|
nextDate.setSeconds(5);
|
||||||
|
const difference: number = nextDate.valueOf() - Date.now();
|
||||||
|
setTimeout(this.callEveryHour, difference);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@ -22,6 +22,7 @@
|
|||||||
:total="systemStatus.psram_total"
|
:total="systemStatus.psram_total"
|
||||||
:used="systemStatus.psram_used"
|
:used="systemStatus.psram_used"
|
||||||
/>
|
/>
|
||||||
|
<a href="/api/database">Read Database</a>
|
||||||
<FsInfo
|
<FsInfo
|
||||||
:name="$t('memoryinfo.LittleFs')"
|
:name="$t('memoryinfo.LittleFs')"
|
||||||
:total="systemStatus.littlefs_total"
|
:total="systemStatus.littlefs_total"
|
||||||
|
|||||||
@ -61,6 +61,7 @@
|
|||||||
<option v-for="file in restoreList" :key="file.name" :value="file.name">
|
<option v-for="file in restoreList" :key="file.name" :value="file.name">
|
||||||
{{ file.descr }}
|
{{ file.descr }}
|
||||||
</option>
|
</option>
|
||||||
|
<option selected value="database.bin">Database (database.bin)</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
|
|||||||
@ -9,6 +9,12 @@
|
|||||||
>
|
>
|
||||||
<HintView :hints="liveData.hints" />
|
<HintView :hints="liveData.hints" />
|
||||||
<InverterTotalInfo :totalData="liveData.total" /><br />
|
<InverterTotalInfo :totalData="liveData.total" /><br />
|
||||||
|
<div class="card">
|
||||||
|
<div class="card-body">
|
||||||
|
<BarChart />
|
||||||
|
<CalendarChart />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="row gy-3">
|
<div class="row gy-3">
|
||||||
<div class="col-sm-3 col-md-2" :style="[inverterData.length == 1 ? { display: 'none' } : {}]">
|
<div class="col-sm-3 col-md-2" :style="[inverterData.length == 1 ? { display: 'none' } : {}]">
|
||||||
<div
|
<div
|
||||||
@ -498,6 +504,8 @@ import DevInfo from '@/components/DevInfo.vue';
|
|||||||
import EventLog from '@/components/EventLog.vue';
|
import EventLog from '@/components/EventLog.vue';
|
||||||
import GridProfile from '@/components/GridProfile.vue';
|
import GridProfile from '@/components/GridProfile.vue';
|
||||||
import HintView from '@/components/HintView.vue';
|
import HintView from '@/components/HintView.vue';
|
||||||
|
import BarChart from '@/components/BarChart.vue';
|
||||||
|
import CalendarChart from '@/components/CalendarChart.vue';
|
||||||
import InverterChannelInfo from '@/components/InverterChannelInfo.vue';
|
import InverterChannelInfo from '@/components/InverterChannelInfo.vue';
|
||||||
import InverterTotalInfo from '@/components/InverterTotalInfo.vue';
|
import InverterTotalInfo from '@/components/InverterTotalInfo.vue';
|
||||||
import ModalDialog from '@/components/ModalDialog.vue';
|
import ModalDialog from '@/components/ModalDialog.vue';
|
||||||
@ -536,6 +544,8 @@ export default defineComponent({
|
|||||||
GridProfile,
|
GridProfile,
|
||||||
HintView,
|
HintView,
|
||||||
InverterChannelInfo,
|
InverterChannelInfo,
|
||||||
|
BarChart,
|
||||||
|
CalendarChart,
|
||||||
InverterTotalInfo,
|
InverterTotalInfo,
|
||||||
ModalDialog,
|
ModalDialog,
|
||||||
BIconArrowCounterclockwise,
|
BIconArrowCounterclockwise,
|
||||||
|
|||||||
@ -15,7 +15,7 @@ try {
|
|||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
proxy_target = require('./vite.user.ts').proxy_target;
|
proxy_target = require('./vite.user.ts').proxy_target;
|
||||||
} catch {
|
} catch {
|
||||||
proxy_target = '192.168.20.110';
|
proxy_target = '192.168.2.93';
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
|
|||||||
1
webapp/yarn
Symbolic link
1
webapp/yarn
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
/usr/share/nodejs/yarn/bin/yarn
|
||||||
1982
webapp/yarn.lock
1982
webapp/yarn.lock
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user