mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-07 03:56:57 +03:00
* Implement individual influx topic * Update interface_influxdb.cpp * Update interface_influxdb.cpp * Update FieldName * analogROI: Activate save button after ROI creation (#2326) * Migration of PlatformIO 5.2.0 to 6.1.0 (resp. ESP IDF from 4.4.2 to 5.0.1) (#2305) * Migration to PlatformIO 6.1.0 * Disable RMTMEM usage as it is no longer allowed -> Smart LEDs not functional! * moved miniz into subfolder of jomjol_fileserver_ota, else it does not build anymore. * cleanup * fix leading NaN (#2310) * Migration to PlatformIO 6.1.0 * Disable RMTMEM usage as it is no longer allowed -> Smart LEDs not functional! * moved miniz into subfolder of jomjol_fileserver_ota, else it does not build anymore. * cleanup * Task watchdog has new config name * Fix return value check. It must be something else than ESP_FAIL, but it does not need to be ESP_OK! * add missing strucures to work around new RMTMEM restriction (untested) --------- Co-authored-by: CaCO3 <caco@ruinelli.ch> * Keep MainFlowTask alive to handle reboot (#2325) * Shared PSRAM memory (#2285) * enable PSRAM logging * add extra functions for psram shared memroy handling * CImageBasis objects still should used dynamic memory (eg. rawImage), haw ever tmpImage must be placed inside the shared memory * Place all STBI allocs inside the shared memory * The models are placed in the shared PSRAM reagion and must be allocated through the dedicated functions * . * renaming * fix cast warning * add flag to switch STBI PSRAM usage * improve PSRAM shared handling * reserve shared PSRAM as early as possible * init logging eralier so we can use it in PSRAM shared alloc * move Wifi_LWIP, BSS_SEG and MQTT Outbox into PSRAM to ffree internal memory * Check if model fits into reserved shared memory * Update code/components/jomjol_tfliteclass/CTfLiteClass.cpp * Update code/components/jomjol_helper/psram.cpp * Update code/components/jomjol_helper/psram.cpp * Update code/components/jomjol_flowcontroll/ClassFlowControll.cpp * Update code/components/jomjol_helper/psram.cpp * Update code/components/jomjol_helper/psram.cpp * Update code/components/jomjol_helper/psram.cpp * Update code/components/jomjol_image_proc/CImageBasis.cpp * Update code/components/jomjol_helper/psram.cpp * Update code/components/jomjol_helper/psram.cpp * Update code/components/jomjol_helper/psram.cpp * Update code/components/jomjol_helper/psram.cpp * Update code/components/jomjol_helper/psram.cpp * Update code/components/jomjol_helper/psram.cpp * Update code/components/jomjol_helper/psram.cpp * . * . * . * . * Korrektur Merge Conflict in main.cpp --------- Co-authored-by: CaCO3 <caco@ruinelli.ch> Co-authored-by: jomjol <30766535+jomjol@users.noreply.github.com> * fix PSRAM init return value check * Extend incl. indiv. Measurement * Implement UX * Update ClassFlowInfluxDBv2.cpp * Implement individual influx topic * Update interface_influxdb.cpp * Update interface_influxdb.cpp * Update FieldName * Extend incl. indiv. Measurement * Implement UX * Update ClassFlowInfluxDBv2.cpp * Update main.cpp --------- Co-authored-by: Slider0007 <115730895+Slider0007@users.noreply.github.com> Co-authored-by: CaCO3 <caco3@ruinelli.ch> Co-authored-by: CaCO3 <caco@ruinelli.ch>
225 lines
6.4 KiB
C++
225 lines
6.4 KiB
C++
#ifdef ENABLE_INFLUXDB
|
|
#include <sstream>
|
|
#include "ClassFlowInfluxDB.h"
|
|
#include "Helper.h"
|
|
#include "connect_wlan.h"
|
|
|
|
#include "time_sntp.h"
|
|
#include "interface_influxdb.h"
|
|
|
|
#include "ClassFlowPostProcessing.h"
|
|
#include "esp_log.h"
|
|
#include "../../include/defines.h"
|
|
|
|
#include "ClassLogFile.h"
|
|
|
|
#include <time.h>
|
|
|
|
static const char* TAG = "INFLUXDB";
|
|
|
|
void ClassFlowInfluxDB::SetInitialParameter(void)
|
|
{
|
|
uri = "";
|
|
database = "";
|
|
|
|
OldValue = "";
|
|
flowpostprocessing = NULL;
|
|
user = "";
|
|
password = "";
|
|
previousElement = NULL;
|
|
ListFlowControll = NULL;
|
|
disabled = false;
|
|
InfluxDBenable = false;
|
|
}
|
|
|
|
ClassFlowInfluxDB::ClassFlowInfluxDB()
|
|
{
|
|
SetInitialParameter();
|
|
}
|
|
|
|
ClassFlowInfluxDB::ClassFlowInfluxDB(std::vector<ClassFlow*>* lfc)
|
|
{
|
|
SetInitialParameter();
|
|
|
|
ListFlowControll = lfc;
|
|
for (int i = 0; i < ListFlowControll->size(); ++i)
|
|
{
|
|
if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0)
|
|
{
|
|
flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
ClassFlowInfluxDB::ClassFlowInfluxDB(std::vector<ClassFlow*>* lfc, ClassFlow *_prev)
|
|
{
|
|
SetInitialParameter();
|
|
|
|
previousElement = _prev;
|
|
ListFlowControll = lfc;
|
|
|
|
for (int i = 0; i < ListFlowControll->size(); ++i)
|
|
{
|
|
if (((*ListFlowControll)[i])->name().compare("ClassFlowPostProcessing") == 0)
|
|
{
|
|
flowpostprocessing = (ClassFlowPostProcessing*) (*ListFlowControll)[i];
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
bool ClassFlowInfluxDB::ReadParameter(FILE* pfile, string& aktparamgraph)
|
|
{
|
|
std::vector<string> splitted;
|
|
|
|
aktparamgraph = trim(aktparamgraph);
|
|
|
|
if (aktparamgraph.size() == 0)
|
|
if (!this->GetNextParagraph(pfile, aktparamgraph))
|
|
return false;
|
|
|
|
if (toUpper(aktparamgraph).compare("[INFLUXDB]") != 0)
|
|
return false;
|
|
|
|
while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
|
|
{
|
|
ESP_LOGD(TAG, "while loop reading line: %s", aktparamgraph.c_str());
|
|
splitted = ZerlegeZeile(aktparamgraph);
|
|
std::string _param = GetParameterName(splitted[0]);
|
|
|
|
if ((toUpper(_param) == "USER") && (splitted.size() > 1))
|
|
{
|
|
this->user = splitted[1];
|
|
}
|
|
if ((toUpper(_param) == "PASSWORD") && (splitted.size() > 1))
|
|
{
|
|
this->password = splitted[1];
|
|
}
|
|
if ((toUpper(_param) == "URI") && (splitted.size() > 1))
|
|
{
|
|
this->uri = splitted[1];
|
|
}
|
|
if (((toUpper(_param) == "DATABASE")) && (splitted.size() > 1))
|
|
{
|
|
this->database = splitted[1];
|
|
}
|
|
if (((toUpper(_param) == "MEASUREMENT")) && (splitted.size() > 1))
|
|
{
|
|
handleMeasurement(splitted[0], splitted[1]);
|
|
}
|
|
if (((toUpper(_param) == "FIELD")) && (splitted.size() > 1))
|
|
{
|
|
handleFieldname(splitted[0], splitted[1]);
|
|
}
|
|
}
|
|
|
|
if ((uri.length() > 0) && (database.length() > 0))
|
|
{
|
|
// ESP_LOGD(TAG, "Init InfluxDB with uri: %s, measurement: %s, user: %s, password: %s", uri.c_str(), measurement.c_str(), user.c_str(), password.c_str());
|
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Init InfluxDB with uri: " + uri + ", user: " + user + ", password: " + password);
|
|
InfluxDBInit(uri, database, user, password);
|
|
InfluxDBenable = true;
|
|
} else {
|
|
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "InfluxDB init skipped as we are missing some parameters");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool ClassFlowInfluxDB::doFlow(string zwtime)
|
|
{
|
|
if (!InfluxDBenable)
|
|
return true;
|
|
|
|
std::string result;
|
|
std::string measurement;
|
|
std::string resulterror = "";
|
|
std::string resultraw = "";
|
|
std::string resultrate = "";
|
|
std::string resulttimestamp = "";
|
|
string zw = "";
|
|
string namenumber = "";
|
|
|
|
if (flowpostprocessing)
|
|
{
|
|
std::vector<NumberPost*>* NUMBERS = flowpostprocessing->GetNumbers();
|
|
|
|
for (int i = 0; i < (*NUMBERS).size(); ++i)
|
|
{
|
|
measurement = (*NUMBERS)[i]->MeasurementV1;
|
|
result = (*NUMBERS)[i]->ReturnValue;
|
|
resultraw = (*NUMBERS)[i]->ReturnRawValue;
|
|
resulterror = (*NUMBERS)[i]->ErrorMessageText;
|
|
resultrate = (*NUMBERS)[i]->ReturnRateValue;
|
|
resulttimestamp = (*NUMBERS)[i]->timeStamp;
|
|
|
|
if ((*NUMBERS)[i]->FieldV1.length() > 0)
|
|
{
|
|
namenumber = (*NUMBERS)[i]->FieldV1;
|
|
}
|
|
else
|
|
{
|
|
namenumber = (*NUMBERS)[i]->name;
|
|
if (namenumber == "default")
|
|
namenumber = "value";
|
|
else
|
|
namenumber = namenumber + "/value";
|
|
}
|
|
|
|
if (result.length() > 0)
|
|
InfluxDBPublish(measurement, namenumber, result, resulttimestamp);
|
|
}
|
|
}
|
|
|
|
OldValue = result;
|
|
|
|
return true;
|
|
}
|
|
|
|
void ClassFlowInfluxDB::handleMeasurement(string _decsep, string _value)
|
|
{
|
|
string _digit, _decpos;
|
|
int _pospunkt = _decsep.find_first_of(".");
|
|
// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
|
|
if (_pospunkt > -1)
|
|
_digit = _decsep.substr(0, _pospunkt);
|
|
else
|
|
_digit = "default";
|
|
for (int j = 0; j < flowpostprocessing->NUMBERS.size(); ++j)
|
|
{
|
|
if (_digit == "default") // Set to default first (if nothing else is set)
|
|
{
|
|
flowpostprocessing->NUMBERS[j]->MeasurementV1 = _value;
|
|
}
|
|
if (flowpostprocessing->NUMBERS[j]->name == _digit)
|
|
{
|
|
flowpostprocessing->NUMBERS[j]->MeasurementV1 = _value;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void ClassFlowInfluxDB::handleFieldname(string _decsep, string _value)
|
|
{
|
|
string _digit, _decpos;
|
|
int _pospunkt = _decsep.find_first_of(".");
|
|
// ESP_LOGD(TAG, "Name: %s, Pospunkt: %d", _decsep.c_str(), _pospunkt);
|
|
if (_pospunkt > -1)
|
|
_digit = _decsep.substr(0, _pospunkt);
|
|
else
|
|
_digit = "default";
|
|
for (int j = 0; j < flowpostprocessing->NUMBERS.size(); ++j)
|
|
{
|
|
if (_digit == "default") // Set to default first (if nothing else is set)
|
|
{
|
|
flowpostprocessing->NUMBERS[j]->FieldV1 = _value;
|
|
}
|
|
if (flowpostprocessing->NUMBERS[j]->name == _digit)
|
|
{
|
|
flowpostprocessing->NUMBERS[j]->FieldV1 = _value;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#endif //ENABLE_INFLUXDB
|