From beb27402c976a7d113e0c264ffe749baecdea278 Mon Sep 17 00:00:00 2001 From: jomjol <30766535+jomjol@users.noreply.github.com> Date: Thu, 20 Apr 2023 22:00:13 +0200 Subject: [PATCH] Extend InfluxDBv1 with individual topic names (#2319) * 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 * 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 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 Co-authored-by: CaCO3 --- .../ClassFlowDefineTypes.h | 7 +- .../jomjol_flowcontroll/ClassFlowInfluxDB.cpp | 99 +++++++++---- .../jomjol_flowcontroll/ClassFlowInfluxDB.h | 9 +- .../ClassFlowInfluxDBv2.cpp | 53 +++++-- .../jomjol_flowcontroll/ClassFlowInfluxDBv2.h | 6 +- .../jomjol_influxdb/interface_influxdb.cpp | 22 ++- .../jomjol_influxdb/interface_influxdb.h | 8 +- code/main/main.cpp | 12 ++ sd-card/html/common.js | 2 +- sd-card/html/edit_config_param.html | 130 +++++++++++++----- sd-card/html/readconfigparam.js | 9 +- 11 files changed, 257 insertions(+), 100 deletions(-) diff --git a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h index 4a35773fc..10c7b8e58 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h +++ b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h @@ -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; diff --git a/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp b/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp index dd331eed4..abe524ed8 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.cpp @@ -21,7 +21,6 @@ void ClassFlowInfluxDB::SetInitialParameter(void) { uri = ""; database = ""; - measurement = ""; OldValue = ""; flowpostprocessing = NULL; @@ -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"); @@ -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 = ""; @@ -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); } } @@ -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 \ No newline at end of file diff --git a/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.h b/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.h index f79496a50..31885ff71 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.h +++ b/code/components/jomjol_flowcontroll/ClassFlowInfluxDB.h @@ -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* lfc); ClassFlowInfluxDB(std::vector* lfc, ClassFlow *_prev); - string GetInfluxDBMeasurement(); +// string GetInfluxDBMeasurement(); bool ReadParameter(FILE* pfile, string& aktparamgraph); bool doFlow(string time); diff --git a/code/components/jomjol_flowcontroll/ClassFlowInfluxDBv2.cpp b/code/components/jomjol_flowcontroll/ClassFlowInfluxDBv2.cpp index 0df9e29bb..67d917e30 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowInfluxDBv2.cpp +++ b/code/components/jomjol_flowcontroll/ClassFlowInfluxDBv2.cpp @@ -21,7 +21,6 @@ void ClassFlowInfluxDBv2::SetInitialParameter(void) { uri = ""; database = ""; - measurement = ""; dborg = ""; dbtoken = ""; // dbfield = ""; @@ -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)) { @@ -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 { @@ -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) { @@ -154,15 +153,36 @@ 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) @@ -170,6 +190,7 @@ bool ClassFlowInfluxDBv2::doFlow(string zwtime) if (!InfluxDBenable) return true; + std::string measurement; std::string result; std::string resulterror = ""; std::string resultraw = ""; @@ -178,21 +199,23 @@ bool ClassFlowInfluxDBv2::doFlow(string zwtime) string zw = ""; string namenumber = ""; + if (flowpostprocessing) { std::vector* 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 { @@ -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); } } diff --git a/code/components/jomjol_flowcontroll/ClassFlowInfluxDBv2.h b/code/components/jomjol_flowcontroll/ClassFlowInfluxDBv2.h index a1832025c..1c73d0c15 100644 --- a/code/components/jomjol_flowcontroll/ClassFlowInfluxDBv2.h +++ b/code/components/jomjol_flowcontroll/ClassFlowInfluxDBv2.h @@ -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; @@ -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* lfc); ClassFlowInfluxDBv2(std::vector* lfc, ClassFlow *_prev); - string GetInfluxDBMeasurement(); +// string GetInfluxDBMeasurement(); bool ReadParameter(FILE* pfile, string& aktparamgraph); bool doFlow(string time); diff --git a/code/components/jomjol_influxdb/interface_influxdb.cpp b/code/components/jomjol_influxdb/interface_influxdb.cpp index 028616d00..e338bf934 100644 --- a/code/components/jomjol_influxdb/interface_influxdb.cpp +++ b/code/components/jomjol_influxdb/interface_influxdb.cpp @@ -12,28 +12,25 @@ static const char *TAG = "INFLUXDB"; std::string _influxDBURI; std::string _influxDBDatabase; -std::string _influxDBMeasurement; std::string _influxDBUser; std::string _influxDBPassword; std::string _influxDB_V2_URI; std::string _influxDB_V2_Database; -std::string _influxDB_V2_Measurement; std::string _influxDB_V2_Token; std::string _influxDB_V2_Org; static esp_err_t http_event_handler(esp_http_client_event_t *evt); -void InfluxDB_V2_Init(std::string _uri, std::string _database, std::string _measurement, std::string _org, std::string _token) +void InfluxDB_V2_Init(std::string _uri, std::string _database, std::string _org, std::string _token) { _influxDB_V2_URI = _uri; _influxDB_V2_Database = _database; - _influxDB_V2_Measurement = _measurement; _influxDB_V2_Org = _org; _influxDB_V2_Token = _token; } -void InfluxDB_V2_Publish(std::string _key, std::string _content, std::string _timestamp) +void InfluxDB_V2_Publish(std::string _measurement, std::string _key, std::string _content, std::string _timestamp) { char response_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; esp_http_client_config_t http_config = { @@ -66,11 +63,11 @@ void InfluxDB_V2_Publish(std::string _key, std::string _content, std::string _ti sprintf(nowTimestamp,"%ld000000000", (long) t); // UTC - payload = _influxDB_V2_Measurement + " " + _key + "=" + _content + " " + nowTimestamp; + payload = _measurement + " " + _key + "=" + _content + " " + nowTimestamp; } else { - payload = _influxDB_V2_Measurement + " " + _key + "=" + _content; + payload = _measurement + " " + _key + "=" + _content; } payload.shrink_to_fit(); @@ -144,7 +141,7 @@ static esp_err_t http_event_handler(esp_http_client_event_t *evt) return ESP_OK; } -void InfluxDBPublish(std::string _key, std::string _content, std::string _timestamp) { +void InfluxDBPublish(std::string _measurement, std::string _key, std::string _content, std::string _timestamp) { char response_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; esp_http_client_config_t http_config = { .user_agent = "ESP32 Meter reader", @@ -182,11 +179,11 @@ void InfluxDBPublish(std::string _key, std::string _content, std::string _timest sprintf(nowTimestamp,"%ld000000000", (long) t); // UTC - payload = _influxDBMeasurement + " " + _key + "=" + _content + " " + nowTimestamp; + payload = _measurement + " " + _key + "=" + _content + " " + nowTimestamp; } else { - payload = _influxDB_V2_Measurement + " " + _key + "=" + _content; + payload = _measurement + " " + _key + "=" + _content; } payload.shrink_to_fit(); @@ -196,6 +193,8 @@ void InfluxDBPublish(std::string _key, std::string _content, std::string _timest // use the default retention policy of the database std::string apiURI = _influxDBURI + "/write?db=" + _influxDBDatabase; +// std::string apiURI = _influxDBURI + "/api/v2/write?bucket=" + _influxDBDatabase + "/"; + apiURI.shrink_to_fit(); http_config.url = apiURI.c_str(); @@ -223,10 +222,9 @@ void InfluxDBPublish(std::string _key, std::string _content, std::string _timest } -void InfluxDBInit(std::string _uri, std::string _database, std::string _measurement, std::string _user, std::string _password){ +void InfluxDBInit(std::string _uri, std::string _database, std::string _user, std::string _password){ _influxDBURI = _uri; _influxDBDatabase = _database; - _influxDBMeasurement = _measurement; _influxDBUser = _user; _influxDBPassword = _password; diff --git a/code/components/jomjol_influxdb/interface_influxdb.h b/code/components/jomjol_influxdb/interface_influxdb.h index 919e4a3da..bc29bf21d 100644 --- a/code/components/jomjol_influxdb/interface_influxdb.h +++ b/code/components/jomjol_influxdb/interface_influxdb.h @@ -9,12 +9,12 @@ #include // Interface to InfluxDB v1.x -void InfluxDBInit(std::string _influxDBURI, std::string _database, std::string _measurement, std::string _user, std::string _password); -void InfluxDBPublish(std::string _key, std::string _content, std::string _timestamp); +void InfluxDBInit(std::string _influxDBURI, std::string _database, std::string _user, std::string _password); +void InfluxDBPublish(std::string _measurement, std::string _key, std::string _content, std::string _timestamp); // Interface to InfluxDB v2.x -void InfluxDB_V2_Init(std::string _uri, std::string _database, std::string _measurement, std::string _org, std::string _token); -void InfluxDB_V2_Publish(std::string _key, std::string _content, std::string _timestamp); +void InfluxDB_V2_Init(std::string _uri, std::string _database, std::string _org, std::string _token); +void InfluxDB_V2_Publish(std::string _measurement, std::string _key, std::string _content, std::string _timestamp); diff --git a/code/main/main.cpp b/code/main/main.cpp index 8b77d4464..5bf42d984 100644 --- a/code/main/main.cpp +++ b/code/main/main.cpp @@ -622,7 +622,19 @@ void migrateConfiguration(void) { } if (section == "[InfluxDB]") { + /* Fieldname has a as prefix! */ + if (isInString(configLines[i], "Fieldname")) { // It is the parameter "Fieldname" + migrated = migrated | replaceString(configLines[i], "Fieldname", "Field"); // Rename it to Field + migrated = migrated | replaceString(configLines[i], ";", ""); // Enable it + } + } + if (section == "[InfluxDBv2]") { + /* Fieldname has a as prefix! */ + if (isInString(configLines[i], "Fieldname")) { // It is the parameter "Fieldname" + migrated = migrated | replaceString(configLines[i], "Fieldname", "Field"); // Rename it to Field + migrated = migrated | replaceString(configLines[i], ";", ""); // Enable it + } } if (section == "[GPIO]") { diff --git a/sd-card/html/common.js b/sd-card/html/common.js index 3c73bb516..bd0eea352 100644 --- a/sd-card/html/common.js +++ b/sd-card/html/common.js @@ -1,7 +1,7 @@ /* The UI can also be run locally, but you have to set the IP of your devide accordingly. * And you also might have to disable CORS in your webbrowser! */ -var domainname_for_testing = "192.168.1.153"; +var domainname_for_testing = "192.168.178.23"; diff --git a/sd-card/html/edit_config_param.html b/sd-card/html/edit_config_param.html index 2c7c883c6..398957462 100644 --- a/sd-card/html/edit_config_param.html +++ b/sd-card/html/edit_config_param.html @@ -688,16 +688,6 @@

$TOOLTIP_InfluxDB_Database - - - - - - - - - $TOOLTIP_InfluxDB_Measurement - @@ -718,6 +708,34 @@

$TOOLTIP_InfluxDB_password + + +
+ InfluxDB Individual Parameters: + + + + + + + + + + + + $TOOLTIP_InfluxDB_NUMBER.Measurement + + + + + + + + + + $TOOLTIP_InfluxDB_NUMBER.Field + @@ -749,16 +767,6 @@

$TOOLTIP_InfluxDBv2_Database - - - - - - - - - $TOOLTIP_InfluxDBv2_Measurement - @@ -782,20 +790,30 @@


- Postprocessing Individual Parameters: - - - + + + + + + + $TOOLTIP_InfluxDBv2_NUMBER.Measurement + + + + + - + - $TOOLTIP_InfluxDBv2_NUMBER.Fieldname + $TOOLTIP_InfluxDBv2_NUMBER.Field @@ -1423,11 +1441,16 @@

By default GPIO4 is used for the built-in flash LED! If you enable the GPIO var _index = document.getElementById("Numbers_value1"); while (_index.length) _index.remove(0); - var _indexInflux = document.getElementById("NumbersInfluxDB_value1"); + + var _indexInflux = document.getElementById("NumbersInfluxDBv2_value1"); while (_indexInflux.length) _indexInflux.remove(0); - for (var i = 0; i < NUMBERS.length; ++i){ + var _indexInfluxv1 = document.getElementById("NumbersInfluxDB_value1"); + while (_indexInflux.length) + _indexInfluxv1.remove(0); + + for (var i = 0; i < NUMBERS.length; ++i){ var option = document.createElement("option"); option.text = NUMBERS[i]["name"]; option.value = i; @@ -1437,9 +1460,16 @@
By default GPIO4 is used for the built-in flash LED! If you enable the GPIO optionInflux.text = NUMBERS[i]["name"]; optionInflux.value = i; _indexInflux.add(optionInflux); - } + + var optionInfluxv1 = document.createElement("option"); + optionInfluxv1.text = NUMBERS[i]["name"]; + optionInfluxv1.value = i; + _indexInfluxv1.add(optionInfluxv1); + + } _index.selectedIndex = 0; _indexInflux.selectedIndex = 0; + _indexInfluxv1.selectedIndex = 0; } @@ -1741,7 +1771,10 @@
By default GPIO4 is used for the built-in flash LED! If you enable the GPIO ReadParameter(param, "PostProcessing", "ExtendedResolution", false, NUNBERSAkt) ReadParameter(param, "PostProcessing", "IgnoreLeadingNaN", false, NUNBERSAkt) ReadParameter(param, "PostProcessing", "AllowNegativeRates", false, NUNBERSAkt) - ReadParameter(param, "InfluxDBv2", "Fieldname", true, NUNBERSAkt) + ReadParameter(param, "InfluxDB", "Field", true, NUNBERSAkt) + ReadParameter(param, "InfluxDBv2", "Field", true, NUNBERSAkt) + ReadParameter(param, "InfluxDB", "Measurement", true, NUNBERSAkt) + ReadParameter(param, "InfluxDBv2", "Measurement", true, NUNBERSAkt) } // var sel = document.getElementById("Numbers_value1"); @@ -1753,7 +1786,10 @@
By default GPIO4 is used for the built-in flash LED! If you enable the GPIO WriteParameter(param, category, "PostProcessing", "ExtendedResolution", false, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "IgnoreLeadingNaN", false, NUNBERSAkt); WriteParameter(param, category, "PostProcessing", "AllowNegativeRates", false, NUNBERSAkt); - WriteParameter(param, category, "InfluxDBv2", "Fieldname", true, NUNBERSAkt); + WriteParameter(param, category, "InfluxDB", "Field", true, NUNBERSAkt); + WriteParameter(param, category, "InfluxDBv2", "Field", true, NUNBERSAkt); + WriteParameter(param, category, "InfluxDB", "Measurement", true, NUNBERSAkt); + WriteParameter(param, category, "InfluxDBv2", "Measurement", true, NUNBERSAkt); } function UpdateInput() { @@ -1805,16 +1841,17 @@
By default GPIO4 is used for the built-in flash LED! If you enable the GPIO WriteParameter(param, category, "InfluxDB", "Uri", true); WriteParameter(param, category, "InfluxDB", "Database", true); - WriteParameter(param, category, "InfluxDB", "Measurement", true); +// WriteParameter(param, category, "InfluxDB", "Measurement", true); WriteParameter(param, category, "InfluxDB", "user", true); WriteParameter(param, category, "InfluxDB", "password", true); +// WriteParameter(param, category, "InfluxDB", "Field", true); WriteParameter(param, category, "InfluxDBv2", "Uri", true); WriteParameter(param, category, "InfluxDBv2", "Database", true); - WriteParameter(param, category, "InfluxDBv2", "Measurement", true); +// WriteParameter(param, category, "InfluxDBv2", "Measurement", true); WriteParameter(param, category, "InfluxDBv2", "Org", true); WriteParameter(param, category, "InfluxDBv2", "Token", true); - WriteParameter(param, category, "InfluxDBv2", "Fieldname", true); +// WriteParameter(param, category, "InfluxDBv2", "Field", true); WriteParameter(param, category, "GPIO", "IO0", true); WriteParameter(param, category, "GPIO", "IO1", true); @@ -1945,7 +1982,7 @@
By default GPIO4 is used for the built-in flash LED! If you enable the GPIO ReadParameter(param, "InfluxDBv2", "Measurement", true); ReadParameter(param, "InfluxDBv2", "Org", true); ReadParameter(param, "InfluxDBv2", "Token", true); -// ReadParameter(param, "InfluxDB", "Fieldname", true); +// ReadParameter(param, "InfluxDB", "Field", true); ReadParameter(param, "GPIO", "IO0", true); ReadParameter(param, "GPIO", "IO1", true); @@ -2086,11 +2123,26 @@
By default GPIO4 is used for the built-in flash LED! If you enable the GPIO _neu = sel.selectedIndex; UpdateInputIndividual(sel); - var _selInflux = document.getElementById("NumbersInfluxDB_value1"); + var _selInflux = document.getElementById("NumbersInfluxDBv2_value1"); if (_selInflux.selectedIndex != _neu) _selInflux.selectedIndex = _neu } +function numberInfluxDBv2Changed() +{ + var sel = document.getElementById("NumbersInfluxDBv2_value1"); + _neu = sel.selectedIndex; + UpdateInputIndividual(sel); + + var _sel2 = document.getElementById("Numbers_value1"); + if (_sel2.selectedIndex != _neu) + _sel2.selectedIndex = _neu + + var _sel3 = document.getElementById("NumbersInfluxDB_value1"); + if (_sel3.selectedIndex != _neu) + _sel3.selectedIndex = _neu +} + function numberInfluxDBChanged() { var sel = document.getElementById("NumbersInfluxDB_value1"); @@ -2099,7 +2151,11 @@
By default GPIO4 is used for the built-in flash LED! If you enable the GPIO var _sel2 = document.getElementById("Numbers_value1"); if (_sel2.selectedIndex != _neu) - _sel2.selectedIndex = _neu + _sel2.selectedIndex = _neu + + var _sel3 = document.getElementById("NumbersInfluxDBv2_value1"); + if (_sel3.selectedIndex != _neu) + _sel3.selectedIndex = _neu } LoadConfigNeu(); diff --git a/sd-card/html/readconfigparam.js b/sd-card/html/readconfigparam.js index 5fa7ed0f7..a2138143d 100644 --- a/sd-card/html/readconfigparam.js +++ b/sd-card/html/readconfigparam.js @@ -191,9 +191,11 @@ function ParseConfig() { param[catname] = new Object(); ParamAddValue(param, catname, "Uri"); ParamAddValue(param, catname, "Database"); - ParamAddValue(param, catname, "Measurement"); +// ParamAddValue(param, catname, "Measurement"); ParamAddValue(param, catname, "user"); ParamAddValue(param, catname, "password"); + ParamAddValue(param, catname, "Measurement", 1, true); + ParamAddValue(param, catname, "Field", 1, true); var catname = "InfluxDBv2"; category[catname] = new Object(); @@ -202,10 +204,11 @@ function ParseConfig() { param[catname] = new Object(); ParamAddValue(param, catname, "Uri"); ParamAddValue(param, catname, "Database"); - ParamAddValue(param, catname, "Measurement"); +// ParamAddValue(param, catname, "Measurement"); ParamAddValue(param, catname, "Org"); ParamAddValue(param, catname, "Token"); - ParamAddValue(param, catname, "Fieldname", 1, true); + ParamAddValue(param, catname, "Measurement", 1, true); + ParamAddValue(param, catname, "Field", 1, true); var catname = "GPIO"; category[catname] = new Object();