Skip to content

Commit

Permalink
Extend InfluxDBv1 with individual topic names (#2319)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
4 people authored Apr 20, 2023
1 parent 262d83e commit 2a7f3b3
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 100 deletions.
7 changes: 6 additions & 1 deletion code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ struct NumberPost {
int DecimalShiftInitial;
float AnalogDigitalTransitionStart; // When is the digit > x.1, i.e. when does it start to tilt?
int Nachkomma;
string Fieldname; // Fieldname in InfluxDB2

string FieldV1; // Fieldname in InfluxDBv1
string MeasurementV1; // Measurement in InfluxDBv1

string FieldV2; // Fieldname in InfluxDBv2
string MeasurementV2; // Measurement in InfluxDBv2

bool isExtendedResolution;

Expand Down
99 changes: 76 additions & 23 deletions code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ void ClassFlowInfluxDB::SetInitialParameter(void)
{
uri = "";
database = "";
measurement = "";

OldValue = "";
flowpostprocessing = NULL;
Expand Down Expand Up @@ -86,33 +85,39 @@ bool ClassFlowInfluxDB::ReadParameter(FILE* pfile, string& aktparamgraph)
{
ESP_LOGD(TAG, "while loop reading line: %s", aktparamgraph.c_str());
splitted = ZerlegeZeile(aktparamgraph);
if ((toUpper(splitted[0]) == "USER") && (splitted.size() > 1))
std::string _param = GetParameterName(splitted[0]);

if ((toUpper(_param) == "USER") && (splitted.size() > 1))
{
this->user = splitted[1];
}
if ((toUpper(splitted[0]) == "PASSWORD") && (splitted.size() > 1))
if ((toUpper(_param) == "PASSWORD") && (splitted.size() > 1))
{
this->password = splitted[1];
}
if ((toUpper(splitted[0]) == "URI") && (splitted.size() > 1))
if ((toUpper(_param) == "URI") && (splitted.size() > 1))
{
this->uri = splitted[1];
}
if (((toUpper(splitted[0]) == "MEASUREMENT")) && (splitted.size() > 1))
if (((toUpper(_param) == "DATABASE")) && (splitted.size() > 1))
{
this->measurement = splitted[1];
this->database = splitted[1];
}
if (((toUpper(splitted[0]) == "DATABASE")) && (splitted.size() > 1))
if (((toUpper(_param) == "MEASUREMENT")) && (splitted.size() > 1))
{
this->database = splitted[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) && (measurement.length() > 0))
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 + ", measurement: " + measurement + ", user: " + user + ", password: " + password);
InfluxDBInit(uri, database, measurement, user, password);
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");
Expand All @@ -121,19 +126,13 @@ bool ClassFlowInfluxDB::ReadParameter(FILE* pfile, string& aktparamgraph)
return true;
}


string ClassFlowInfluxDB::GetInfluxDBMeasurement()
{
return measurement;
}


bool ClassFlowInfluxDB::doFlow(string zwtime)
{
if (!InfluxDBenable)
return true;

std::string result;
std::string measurement;
std::string resulterror = "";
std::string resultraw = "";
std::string resultrate = "";
Expand All @@ -147,20 +146,28 @@ bool ClassFlowInfluxDB::doFlow(string zwtime)

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;

namenumber = (*NUMBERS)[i]->name;
if (namenumber == "default")
namenumber = "value";
if ((*NUMBERS)[i]->FieldV1.length() > 0)
{
namenumber = (*NUMBERS)[i]->FieldV1;
}
else
namenumber = namenumber + "/value";
{
namenumber = (*NUMBERS)[i]->name;
if (namenumber == "default")
namenumber = "value";
else
namenumber = namenumber + "/value";
}

if (result.length() > 0)
InfluxDBPublish(namenumber, result, resulttimestamp);
InfluxDBPublish(measurement, namenumber, result, resulttimestamp);
}
}

Expand All @@ -169,4 +176,50 @@ bool ClassFlowInfluxDB::doFlow(string zwtime)
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
9 changes: 7 additions & 2 deletions code/components/jomjol_flowcontroll/ClassFlowInfluxDB.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ class ClassFlowInfluxDB :
std::string user, password;
bool InfluxDBenable;

void SetInitialParameter(void);
void SetInitialParameter(void);

void handleFieldname(string _decsep, string _value);
void handleMeasurement(string _decsep, string _value);



public:
ClassFlowInfluxDB();
ClassFlowInfluxDB(std::vector<ClassFlow*>* lfc);
ClassFlowInfluxDB(std::vector<ClassFlow*>* lfc, ClassFlow *_prev);

string GetInfluxDBMeasurement();
// string GetInfluxDBMeasurement();

bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
Expand Down
53 changes: 38 additions & 15 deletions code/components/jomjol_flowcontroll/ClassFlowInfluxDBv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ void ClassFlowInfluxDBv2::SetInitialParameter(void)
{
uri = "";
database = "";
measurement = "";
dborg = "";
dbtoken = "";
// dbfield = "";
Expand Down Expand Up @@ -102,13 +101,13 @@ bool ClassFlowInfluxDBv2::ReadParameter(FILE* pfile, string& aktparamgraph)
{
this->uri = splitted[1];
}
if (((toUpper(_param) == "MEASUREMENT")) && (splitted.size() > 1))
if (((toUpper(_param) == "FIELD")) && (splitted.size() > 1))
{
this->measurement = splitted[1];
handleFieldname(splitted[0], splitted[1]);
}
if (((toUpper(_param) == "FIELDNAME")) && (splitted.size() > 1))
if (((toUpper(_param) == "MEASUREMENT")) && (splitted.size() > 1))
{
handleFieldname(splitted[0], splitted[1]);
handleMeasurement(splitted[0], splitted[1]);
}
if (((toUpper(splitted[0]) == "DATABASE")) && (splitted.size() > 1))
{
Expand All @@ -117,15 +116,14 @@ bool ClassFlowInfluxDBv2::ReadParameter(FILE* pfile, string& aktparamgraph)
}

printf("uri: %s\n", uri.c_str());
printf("measurement: %s\n", measurement.c_str());
printf("org: %s\n", dborg.c_str());
printf("token: %s\n", dbtoken.c_str());

if ((uri.length() > 0) && (database.length() > 0) && (measurement.length() > 0) && (dbtoken.length() > 0) && (dborg.length() > 0))
if ((uri.length() > 0) && (database.length() > 0) && (dbtoken.length() > 0) && (dborg.length() > 0))
{
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Init InfluxDB with uri: " + uri + ", measurement: " + measurement + ", org: " + dborg + ", token: *****");
LogFile.WriteToFile(ESP_LOG_DEBUG, TAG, "Init InfluxDB with uri: " + uri + ", org: " + dborg + ", token: *****");
// printf("vor V2 Init\n");
InfluxDB_V2_Init(uri, database, measurement, dborg, dbtoken);
InfluxDB_V2_Init(uri, database, dborg, dbtoken);
// printf("nach V2 Init\n");
InfluxDBenable = true;
} else {
Expand All @@ -135,11 +133,12 @@ bool ClassFlowInfluxDBv2::ReadParameter(FILE* pfile, string& aktparamgraph)
return true;
}


/*
string ClassFlowInfluxDBv2::GetInfluxDBMeasurement()
{
return measurement;
}
*/

void ClassFlowInfluxDBv2::handleFieldname(string _decsep, string _value)
{
Expand All @@ -154,22 +153,44 @@ void ClassFlowInfluxDBv2::handleFieldname(string _decsep, string _value)
{
if (_digit == "default") // Set to default first (if nothing else is set)
{
flowpostprocessing->NUMBERS[j]->Fieldname = _value;
flowpostprocessing->NUMBERS[j]->FieldV2 = _value;
}
if (flowpostprocessing->NUMBERS[j]->name == _digit)
{
flowpostprocessing->NUMBERS[j]->Fieldname = _value;
flowpostprocessing->NUMBERS[j]->FieldV2 = _value;
}
}
}

void ClassFlowInfluxDBv2::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]->MeasurementV2 = _value;
}
if (flowpostprocessing->NUMBERS[j]->name == _digit)
{
flowpostprocessing->NUMBERS[j]->MeasurementV2 = _value;
}
}
}


bool ClassFlowInfluxDBv2::doFlow(string zwtime)
{
if (!InfluxDBenable)
return true;

std::string measurement;
std::string result;
std::string resulterror = "";
std::string resultraw = "";
Expand All @@ -178,21 +199,23 @@ bool ClassFlowInfluxDBv2::doFlow(string zwtime)
string zw = "";
string namenumber = "";


if (flowpostprocessing)
{
std::vector<NumberPost*>* NUMBERS = flowpostprocessing->GetNumbers();

for (int i = 0; i < (*NUMBERS).size(); ++i)
{
measurement = (*NUMBERS)[i]->MeasurementV2;
result = (*NUMBERS)[i]->ReturnValue;
resultraw = (*NUMBERS)[i]->ReturnRawValue;
resulterror = (*NUMBERS)[i]->ErrorMessageText;
resultrate = (*NUMBERS)[i]->ReturnRateValue;
resulttimestamp = (*NUMBERS)[i]->timeStamp;

if ((*NUMBERS)[i]->Fieldname.length() > 0)
if ((*NUMBERS)[i]->FieldV2.length() > 0)
{
namenumber = (*NUMBERS)[i]->Fieldname;
namenumber = (*NUMBERS)[i]->FieldV2;
}
else
{
Expand All @@ -206,7 +229,7 @@ bool ClassFlowInfluxDBv2::doFlow(string zwtime)
printf("vor sende Influx_DB_V2 - namenumber. %s, result: %s, timestampt: %s", namenumber.c_str(), result.c_str(), resulttimestamp.c_str());

if (result.length() > 0)
InfluxDB_V2_Publish(namenumber, result, resulttimestamp);
InfluxDB_V2_Publish(measurement, namenumber, result, resulttimestamp);
// InfluxDB_V2_Publish(namenumber, result, resulttimestamp);
}
}
Expand Down
6 changes: 4 additions & 2 deletions code/components/jomjol_flowcontroll/ClassFlowInfluxDBv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ClassFlowInfluxDBv2 :
public ClassFlow
{
protected:
std::string uri, database, measurement;
std::string uri, database;
std::string dborg, dbtoken, dbfield;
std::string OldValue;
ClassFlowPostProcessing* flowpostprocessing;
Expand All @@ -24,13 +24,15 @@ class ClassFlowInfluxDBv2 :
void SetInitialParameter(void);

void handleFieldname(string _decsep, string _value);
void handleMeasurement(string _decsep, string _value);


public:
ClassFlowInfluxDBv2();
ClassFlowInfluxDBv2(std::vector<ClassFlow*>* lfc);
ClassFlowInfluxDBv2(std::vector<ClassFlow*>* lfc, ClassFlow *_prev);

string GetInfluxDBMeasurement();
// string GetInfluxDBMeasurement();

bool ReadParameter(FILE* pfile, string& aktparamgraph);
bool doFlow(string time);
Expand Down
Loading

0 comments on commit 2a7f3b3

Please sign in to comment.