Rewrite electricity-logger to use an sqlite3 database

This commit is contained in:
2022-06-25 22:17:46 +02:00
parent 458d824dc8
commit 5b09b06bcf
62 changed files with 5937 additions and 3 deletions

View File

@@ -0,0 +1,25 @@
#pragma once
#include <cstdint>
#include <sqlite3.h>
#include <string>
struct Row
{
time_t epochTime;
std::int32_t watt;
double kilowattPerHour;
};
class Database {
private:
sqlite3 * connectionPtr;
std::string ToSqlInsertStatement(Row const & row) const;
std::string ToSqlUpsertStatement(Row const & row) const;
public:
bool Insert(Row & row);
Database(std::string const & databasePath);
~Database();
};

View File

@@ -0,0 +1,33 @@
#pragma once
#include <cstdio>
#include <ctime>
#include <curl/curl.h> // tested with libcurl4-openSSH
#include <sstream>
#include <string>
/*
This class holds all the data retrieved from the Zeverlution combox /
Zeverlution Sxxxx smart inverters / ZeverSolar box.
For output formatting it uses a timestamp to log the datetime alongside the
watts and kilowatts.
*/
struct ZeverData
{
int number0, number1;
std::string registeryID, registeryKey, hardwareVersion, appVersion, wifiVersion;
std::string timeValue, dateValue, zeverCloudStatus;
int number3;
std::string inverterSN;
int watt;
double kilowattPerHour;
std::string OKmsg, ERRORmsg;
// Parses the data string coming from the zeverlution home.cgi webpage
bool ParseString(const std::string & str);
bool FetchDataFromURL(const std::string & url, const unsigned int timeout);
ZeverData();
};