diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
new file mode 100644
index 00000000..f9f7216a
--- /dev/null
+++ b/.github/workflows/build.yaml
@@ -0,0 +1,106 @@
+name: Build and Pack
+
+on: [push]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Cache PlatformIO
+ uses: actions/cache@v2
+ with:
+ path: ~/.platformio
+ key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
+
+ - name: Set up Python
+ uses: actions/setup-python@v2
+ - name: Install PlatformIO
+ run: |
+ python -m pip install --upgrade pip
+ pip install --upgrade platformio
+
+ - name: Set Variables
+ id: vars
+ run: |
+ echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"
+ echo "::set-output name=date_time::$(git log -1 --format="%at" | xargs -I{} date -d @{} '+%Y-%m-%d %H:%M:%S')"
+ echo "::set-output name=date_time_filename::$(git log -1 --format="%at" | xargs -I{} date -d @{} '+%Y-%m-%d_%H-%M-%S')"
+ #echo "::set-output name=version_string::${{ steps.vars.outputs.date_time_filename }}__${{ github.ref_name }}_(${{ steps.vars.outputs.sha_short }})"
+ #echo "Version String: ${{ steps.vars.outputs.version_string }}"
+
+
+ - name: Set Version used in HTML Info page
+ run: echo "${{ steps.vars.outputs.date_time }}, ${{ github.ref_name }} (${{ steps.vars.outputs.sha_short }})" > "sd-card/html/version.txt"
+
+
+ - name: Build Firmware
+# run: mkdir -p ./code/.pio/build/esp32cam/; touch ./code/.pio/build/esp32cam/firmware.bin # Testing
+ run: cd code; platformio run --environment esp32cam
+
+
+
+ # Old OTA concept
+ # firmware__*.zip needs to be unpacked before attaching to the release!
+ # The bin filename can contain versioning.
+ - name: Rename firmware file to contain versioning (old ota)
+ run: |
+ mkdir -p ./dist_old_ota
+ cp "./code/.pio/build/esp32cam/firmware.bin" "./dist_old_ota/firmware__${{ steps.vars.outputs.date_time_filename }}__${{ github.ref_name }}_(${{ steps.vars.outputs.sha_short }}).bin"
+ ls -l ./dist_old_ota
+
+ - name: Upload Firmware artifact (old OTA concept)
+ uses: actions/upload-artifact@v3
+ with:
+ name: "firmware__extract_before_upload__only_needed_for_migration_from_11.2.0"
+ path: ./dist_old_ota/*
+
+ - name: Upload Web interface artifact (old OTA concept)
+ uses: actions/upload-artifact@v3
+ with:
+ name: "html__only_needed_for_migration_from_11.2.0__${{ steps.vars.outputs.date_time_filename }}__${{ github.ref_name }}_(${{ steps.vars.outputs.sha_short }})"
+ path: ./sd-card/html/*
+
+
+
+ # New OTA concept
+ # update__version.zip file with following content:
+ # - /firmware.bin
+ # - (optional) /html/*
+ # - (optional) /config/*.tfl
+ - name: Prepare update.zip artifact
+ run: |
+ mkdir -p ./dist
+ cp "./code/.pio/build/esp32cam/firmware.bin" "dist/firmware.bin"
+
+ - name: Upload update.zip Artifact (Firmware only)
+ uses: actions/upload-artifact@v3
+ with:
+ name: "update_firmware_only__${{ steps.vars.outputs.date_time_filename }}__${{ github.ref_name }}_(${{ steps.vars.outputs.sha_short }})"
+ path: ./dist/*
+
+
+ - name: Prepare update.zip artifact (Firmware + Web UI)
+ run: cp -r ./sd-card/html ./dist/
+
+ - name: Upload update.zip artifact (Firmware + Web UI)
+ uses: actions/upload-artifact@v3
+ with:
+ name: "update_firmware+web_ui__${{ steps.vars.outputs.date_time_filename }}__${{ github.ref_name }}_(${{ steps.vars.outputs.sha_short }})"
+ path: ./dist/*
+
+
+ - name: Prepare update.zip artifact (Firmware + Web UI + CNN)
+ run: |
+ mkdir ./dist/config/
+ cp ./sd-card/config/*.tfl ./dist/config/ 2>/dev/null || true
+ cp ./sd-card/config/*.tflite ./dist/config/ 2>/dev/null || true
+
+ - name: Upload update.zip artifact (Firmware + Web UI + CNN)
+ uses: actions/upload-artifact@v3
+ with:
+ name: "update_firmware+web_ui+cnn__${{ steps.vars.outputs.date_time_filename }}__${{ github.ref_name }}_(${{ steps.vars.outputs.sha_short }})"
+ path: ./dist/*
diff --git a/README.md b/README.md
index c6561a19..2ed672a2 100644
--- a/README.md
+++ b/README.md
@@ -40,6 +40,27 @@ In other cases you can contact the developer via email:
0)
+ {
+ zw = _main + zw;
+ }
+ else
+ {
+ zw = _target_zip + zw;
+ }
+
+ }
+
+ printf("Filename to extract: %s", zw.c_str());
+ DeleteFile(zw);
+ FILE* fpTargetFile = OpenFileAndWait(zw.c_str(), "wb");
+ fwrite(p, 1, (uint)uncomp_size, fpTargetFile);
+ fclose(fpTargetFile);
+
+ printf("Successfully extracted file \"%s\", size %u\n", archive_filename, (uint)uncomp_size);
+ // printf("File data: \"%s\"\n", (const char*)p);
+
+ // We're done.
+ mz_free(p);
+ }
+
+ // Close the archive, freeing any resources it was using
+ mz_zip_reader_end(&zip_archive);
+ }
+
+ printf("Success.\n");
+ return ret;
+}
+
void unzip(std::string _in_zip_file, std::string _target_directory){
int i, sort_iter;
mz_bool status;
@@ -860,15 +945,4 @@ void register_server_file_uri(httpd_handle_t server, const char *base_path)
};
httpd_register_uri_handler(server, &file_delete);
-
- /* URI handler for getting tflite files from server */
-/*
- httpd_uri_t file_tflite = {
- .uri = "/tflite", // Match all URIs of type /delete/path/to/file
- .method = HTTP_GET,
- .handler = get_tflite_file_handler,
- .user_ctx = server_data // Pass server data as context
- };
- httpd_register_uri_handler(server, &file_tflite);
-*/
}
diff --git a/code/components/jomjol_fileserver_ota/server_file.h b/code/components/jomjol_fileserver_ota/server_file.h
index c179e36e..9dbcc88f 100644
--- a/code/components/jomjol_fileserver_ota/server_file.h
+++ b/code/components/jomjol_fileserver_ota/server_file.h
@@ -4,6 +4,8 @@
void register_server_file_uri(httpd_handle_t server, const char *base_path);
void unzip(std::string _in_zip_file, std::string _target_directory);
+std::string unzip_new(std::string _in_zip_file, std::string _target_zip, std::string _target_bin, std::string _main = "/sdcard/");
+
void delete_all_in_directory(std::string _directory);
diff --git a/code/components/jomjol_fileserver_ota/server_help.cpp b/code/components/jomjol_fileserver_ota/server_help.cpp
index 4bb06ffa..e8238b84 100644
--- a/code/components/jomjol_fileserver_ota/server_help.cpp
+++ b/code/components/jomjol_fileserver_ota/server_help.cpp
@@ -43,6 +43,7 @@ esp_err_t send_file(httpd_req_t *req, std::string filename)
}
ESP_LOGI(TAG, "Sending file : %s ...", filename.c_str());
+// httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
set_content_type_from_file(req, filename.c_str());
/* Retrieve the pointer to scratch buffer for temporary storage */
@@ -120,6 +121,8 @@ esp_err_t set_content_type_from_file(httpd_req_t *req, const char *filename)
return httpd_resp_set_type(req, "image/x-icon");
} else if (IS_FILE_EXT(filename, ".js")) {
return httpd_resp_set_type(req, "text/javascript");
+ } else if (IS_FILE_EXT(filename, ".css")) {
+ return httpd_resp_set_type(req, "text/css");
}
/* This is a limited set only */
/* For any other type always set as plain text */
diff --git a/code/components/jomjol_fileserver_ota/server_ota.cpp b/code/components/jomjol_fileserver_ota/server_ota.cpp
index c9b11b08..3d41b78f 100644
--- a/code/components/jomjol_fileserver_ota/server_ota.cpp
+++ b/code/components/jomjol_fileserver_ota/server_ota.cpp
@@ -50,6 +50,8 @@ static char ota_write_data[BUFFSIZE + 1] = { 0 };
#define OTA_URL_SIZE 256
static const char *TAGPARTOTA = "server_ota";
+esp_err_t handler_reboot(httpd_req_t *req);
+
static void infinite_loop(void)
{
@@ -207,24 +209,6 @@ static void print_sha256 (const uint8_t *image_hash, const char *label)
static bool diagnostic(void)
{
-/*
- gpio_config_t io_conf;
- io_conf.intr_type = (gpio_int_type_t) GPIO_PIN_INTR_DISABLE;
- io_conf.mode = GPIO_MODE_INPUT;
- io_conf.pin_bit_mask = (1ULL << CONFIG_EXAMPLE_GPIO_DIAGNOSTIC);
- io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
- io_conf.pull_up_en = GPIO_PULLUP_ENABLE;
- gpio_config(&io_conf);
-
- ESP_LOGI(TAGPARTOTA, "Diagnostics (5 sec)...");
- vTaskDelay(5000 / portTICK_PERIOD_MS);
-
- bool diagnostic_is_ok = gpio_get_level(CONFIG_EXAMPLE_GPIO_DIAGNOSTIC);
-
- gpio_reset_pin(CONFIG_EXAMPLE_GPIO_DIAGNOSTIC);
-
- return diagnostic_is_ok;
-*/
return true;
}
@@ -326,7 +310,7 @@ esp_err_t handler_ota_update(httpd_req_t *req)
if (httpd_query_key_value(_query, "task", _valuechar, 30) == ESP_OK)
{
- printf("task is found"); printf(_valuechar); printf("\n");
+ printf("task is found: "); printf(_valuechar); printf("\n");
_task = std::string(_valuechar);
}
@@ -344,16 +328,105 @@ esp_err_t handler_ota_update(httpd_req_t *req)
};
+ if (_task.compare("update") == 0)
+ {
+ std::string filetype = toUpper(getFileType(fn));
+ if (filetype.length() == 0)
+ {
+ std::string zw = "Update failed - no file specified (zip, bin, tfl, tlite)";
+ httpd_resp_sendstr_chunk(req, zw.c_str());
+ httpd_resp_sendstr_chunk(req, NULL);
+ return ESP_OK;
+ }
+
+
+ if ((filetype == "TFLITE") || (filetype == "TFL"))
+ {
+ std::string out = "/sdcard/config/" + getFileFullFileName(fn);
+ DeleteFile(out);
+ CopyFile(fn, out);
+ DeleteFile(fn);
+
+ const char* resp_str = "Neural Network File copied.";
+ httpd_resp_sendstr_chunk(req, resp_str);
+ httpd_resp_sendstr_chunk(req, NULL);
+ return ESP_OK;
+ }
+
+
+ if (filetype == "ZIP")
+ {
+ std::string in, out, outbin, zw, retfirmware;
+
+// in = "/sdcard/firmware/html.zip";
+ out = "/sdcard/html";
+ outbin = "/sdcard/firmware";
+
+// delete_all_in_directory(out);
+
+ retfirmware = unzip_new(fn, out+"/", outbin+"/");
+
+ if (retfirmware.length() > 0)
+ {
+ filetype = "BIN";
+ fn = retfirmware;
+ zw = "HTML Update Successfull!
Additioal firmware found in ZIP file.\n";
+ httpd_resp_sendstr_chunk(req, zw.c_str());
+ }
+ else
+ {
+ zw = "HTML Update Successfull!
No reboot necessary.\n";
+ httpd_resp_sendstr_chunk(req, zw.c_str());
+ httpd_resp_sendstr_chunk(req, NULL);
+ return ESP_OK;
+ }
+ }
+
+
+ if (filetype == "BIN")
+ {
+ const char* resp_str;
+ KillTFliteTasks();
+ gpio_handler_deinit();
+ if (ota_update_task(fn))
+ {
+// resp_str = "rebooting - Firmware Update Successfull!
You can restart now.";
+// httpd_resp_send(req, resp_str, strlen(resp_str));
+// httpd_resp_sendstr_chunk(req, NULL);
+ return handler_reboot(req);
+ }
+ else
+ {
+ resp_str = "Error during Firmware Update!!!
Please check output of console.";
+ }
+
+ httpd_resp_send(req, resp_str, strlen(resp_str));
+
+ #ifdef DEBUG_DETAIL_ON
+ LogFile.WriteHeapInfo("handler_ota_update - Done");
+ #endif
+
+ return ESP_OK;
+ }
+
+
+ std::string zw = "Update failed - no valid file specified (zip, bin, tfl, tlite)";
+ httpd_resp_sendstr_chunk(req, zw.c_str());
+ httpd_resp_sendstr_chunk(req, NULL);
+ return ESP_OK;
+ }
+
+
if (_task.compare("unziphtml") == 0)
{
std::string in, out, zw;
in = "/sdcard/firmware/html.zip";
- out = "/sdcard/html/";
+ out = "/sdcard/html";
delete_all_in_directory(out);
- unzip(in, out);
+ unzip(in, out+"/");
zw = "HTML Update Successfull!
No reboot necessary";
httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_sendstr_chunk(req, NULL);
@@ -371,6 +444,8 @@ esp_err_t handler_ota_update(httpd_req_t *req)
unlink(fn.c_str());
}
/* Respond with an empty chunk to signal HTTP response completion */
+ std::string zw = "file deleted!\n";
+ httpd_resp_sendstr_chunk(req, zw.c_str());
httpd_resp_send_chunk(req, NULL, 0);
return ESP_OK;
}
@@ -437,7 +512,7 @@ esp_err_t handler_reboot(httpd_req_t *req)
LogFile.WriteToFile("handler_reboot");
ESP_LOGI(TAGPARTOTA, "!!! System will restart within 5 sec!!!");
- const char* resp_str = "
";
+ const char* resp_str = " ";
httpd_resp_send(req, resp_str, strlen(resp_str));
doReboot();
diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp
index da6ddfd5..a60735f6 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.cpp
@@ -10,7 +10,7 @@
static const char* TAG = "flow_analog";
-bool debugdetailgeneral = false;
+bool debugdetailgeneral = true;
ClassFlowCNNGeneral::ClassFlowCNNGeneral(ClassFlowAlignment *_flowalign, t_CNNType _cnntype) : ClassFlowImage(NULL, TAG)
{
@@ -201,7 +201,7 @@ int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger,
if (AnalogerVorgaenger)
{
// result = ZeigerEvalAnalogToDigitNeu(zahl, eval_vorgaenger);
- result = ZeigerEvalAnalogToDigitNeu(zahl, zahl_vorgaenger);
+ result = ZeigerEvalAnalogToDigitNeu(zahl, zahl_vorgaenger, eval_vorgaenger);
if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalHybridNeu - Analoger Vorgänger, Bewertung über ZeigerEvalAnalogNeu = " + std::to_string(result) +
" zahl: " + std::to_string(zahl) + " zahl_vorgaenger = " + std::to_string(zahl_vorgaenger)+ " eval_vorgaenger = " + std::to_string(eval_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe));
return result;
@@ -232,20 +232,20 @@ int ClassFlowCNNGeneral::ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger,
}
// bleibt nur >= 9.5 --> noch kein Nulldurchgang --> 2.8 --> 2, und 3.1 --> 2
- // hier auf 4 reduziert, da erst ab Vorgänder 9 anfängt umzustellen. Bei 9.5 Vorgänger kann die aktuelle
- // Zahl noch x.4 - x.5 sein.
+ // alles >=x.4 kann als aktuelle Zahl gelten im Übergang. Bei 9.5 Vorgänger kann die aktuelle
+ // Zahl noch x.6 - x.7 sein.
if (ergebnis_nachkomma >= 4)
result = ergebnis_vorkomma;
else
result = (ergebnis_vorkomma - 1 + 10) % 10;
if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEvalHybridNeu - KEIN Analoger Vorgänger, >= 9.5 --> noch kein Nulldurchgang = " + std::to_string(result) +
- " zahl: " + std::to_string(zahl) + " zahl_vorgaenger = " + std::to_string(zahl_vorgaenger)+ " eval_vorgaenger = " + std::to_string(eval_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe));
+ " zahl: " + std::to_string(zahl) + " zahl_vorgaenger = " + std::to_string(zahl_vorgaenger)+ " eval_vorgaenger = " + std::to_string(eval_vorgaenger) + " DigitalUnschaerfe = " + std::to_string(DigitalUnschaerfe) + " ergebnis_nachkomma = " + std::to_string(ergebnis_nachkomma));
return result;
}
-int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger)
+int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger)
{
int result;
int ergebnis_nachkomma = ((int) floor(zahl * 10)) % 10;
@@ -272,7 +272,8 @@ int ClassFlowCNNGeneral::ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vor
return result;
}
- if (ziffer_vorgaenger <= 1) // Nulldurchgang hat stattgefunden (!Bewertung über Prev_value und nicht Zahl!) --> hier aufrunden (2.8 --> 3, aber auch 3.1 --> 3)
+ if (ziffer_vorgaenger <= 1 && eval_vorgaenger<9) // Nulldurchgang hat stattgefunden (!Bewertung über Prev_value und nicht Zahl!) --> hier aufrunden (2.8 --> 3, aber auch 3.1 --> 3)
+ // aber Sonderfall ziffer_vorgaeger = 0.1 vor_vorgaenger 9.9 => eval_vorgaenger ist 9, damit hat Nulldurchgang nicht stattgefunden.
{
if (ergebnis_nachkomma > 5)
result = (ergebnis_vorkomma + 1) % 10;
@@ -339,38 +340,6 @@ int ClassFlowCNNGeneral::ZeigerEvalAnalogNeu(float zahl, int ziffer_vorgaenger)
}
-/*
-int ClassFlowCNNGeneral::ZeigerEval(float zahl, int ziffer_vorgaenger)
-{
- int ergebnis_nachkomma = ((int) floor(zahl * 10) + 10) % 10;
- int ergebnis_vorkomma = ((int) floor(zahl) + 10) % 10;
- int ergebnis;
- float ergebnis_rating;
- if (debugdetailgeneral) LogFile.WriteToFile("ClassFlowCNNGeneral::ZeigerEval erg_v=" + std::to_string(ergebnis_vorkomma) + ", erg_n=" + std::to_string(ergebnis_nachkomma) + ", ziff_v=" + std::to_string(ziffer_vorgaenger));
-
- if (ziffer_vorgaenger == -1)
- return ergebnis_vorkomma % 10;
-
- // Ist die aktuelle Stelle schon umgesprungen und die Vorstelle noch nicht?
- // Akt.: 2.1, Vorstelle = 0.9 => 1.9
- // Problem sind mehrere Rundungen
- // Bsp. zahl=4.5, Vorgänger= 9.6 (ziffer_vorgaenger=0)
- // Tritt nur auf bei Übergang von analog auf digit
- ergebnis_rating = ergebnis_nachkomma - ziffer_vorgaenger;
- if (ergebnis_nachkomma >= 5)
- ergebnis_rating-=5.1;
- else
- ergebnis_rating+=5;
- ergebnis = (int) round(zahl);
- if (ergebnis_rating < 0)
- ergebnis-=1;
- if (ergebnis == -1)
- ergebnis+=10;
-
- ergebnis = (ergebnis + 10) % 10;
- return ergebnis;
-}
-*/
bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph)
{
@@ -416,11 +385,6 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph)
{
this->logfileRetentionInDays = std::stoi(zerlegt[1]);
}
-// if ((toUpper(zerlegt[0]) == "MODELTYPE") && (zerlegt.size() > 1))
-// {
-// if (toUpper(zerlegt[1]) == "DIGITHYPRID")
-// CNNType = DigitalHyprid;
-// }
if ((toUpper(zerlegt[0]) == "MODEL") && (zerlegt.size() > 1))
{
@@ -439,6 +403,11 @@ bool ClassFlowCNNGeneral::ReadParameter(FILE* pfile, string& aktparamgraph)
neuroi->posy = std::stoi(zerlegt[2]);
neuroi->deltax = std::stoi(zerlegt[3]);
neuroi->deltay = std::stoi(zerlegt[4]);
+ neuroi->CCW = false;
+ if (zerlegt.size() >= 6)
+ {
+ neuroi->CCW = toUpper(zerlegt[5]) == "TRUE";
+ }
neuroi->result_float = -1;
neuroi->image = NULL;
neuroi->image_org = NULL;
@@ -511,7 +480,7 @@ general* ClassFlowCNNGeneral::GetGENERAL(string _name, bool _create = true)
_ret->ROI.push_back(neuroi);
- printf("GetGENERAL - GENERAL %s - roi %s\n", _analog.c_str(), _roi.c_str());
+ printf("GetGENERAL - GENERAL %s - roi %s - CCW: %d\n", _analog.c_str(), _roi.c_str(), neuroi->CCW);
return _ret;
}
@@ -658,10 +627,11 @@ bool ClassFlowCNNGeneral::getNetworkParameter()
CNNType = Digital;
printf("TFlite-Type set to Digital\n");
break;
- case 20:
+/* case 20:
CNNType = DigitalHyprid10;
printf("TFlite-Type set to DigitalHyprid10\n");
break;
+*/
// case 22:
// CNNType = DigitalHyprid;
// printf("TFlite-Type set to DigitalHyprid\n");
@@ -724,8 +694,13 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time)
f1 = tflite->GetOutputValue(0);
f2 = tflite->GetOutputValue(1);
float result = fmod(atan2(f1, f2) / (M_PI * 2) + 2, 1);
- GENERAL[_ana]->ROI[i]->result_float = result * 10;
- printf("Result General(Analog)%i: %f\n", i, GENERAL[_ana]->ROI[i]->result_float);
+
+ if(GENERAL[_ana]->ROI[i]->CCW)
+ GENERAL[_ana]->ROI[i]->result_float = 10 - (result * 10);
+ else
+ GENERAL[_ana]->ROI[i]->result_float = result * 10;
+
+ printf("Result General(Analog)%i - CCW: %d - %f\n", i, GENERAL[_ana]->ROI[i]->CCW, GENERAL[_ana]->ROI[i]->result_float);
if (isLogImage)
LogImage(logPath, GENERAL[_ana]->ROI[i]->name, &GENERAL[_ana]->ROI[i]->result_float, NULL, time, GENERAL[_ana]->ROI[i]->image_org);
} break;
@@ -790,6 +765,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time)
}
} break;
*/
+/*
case DigitalHyprid10:
{
int _num, _nachkomma;
@@ -825,6 +801,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time)
}
}
} break;
+*/
case DoubleHyprid10:
{
@@ -858,7 +835,7 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time)
_fit = _val + _valminus;
}
- if (result > 10)
+ if (result >= 10)
result = result - 10;
if (result < 0)
result = result + 10;
@@ -916,15 +893,17 @@ bool ClassFlowCNNGeneral::doNeuralNetwork(string time)
_num = tflite->GetOutClassification();
- GENERAL[_ana]->ROI[i]->result_float = (float)_num / 10.0;
+ if(GENERAL[_ana]->ROI[i]->CCW)
+ GENERAL[_ana]->ROI[i]->result_float = 10 - ((float)_num / 10.0);
+ else
+ GENERAL[_ana]->ROI[i]->result_float = (float)_num / 10.0;
-
_result_save_file = GENERAL[_ana]->ROI[i]->result_float;
GENERAL[_ana]->ROI[i]->isReject = false;
- printf("Result General(Analog)%i: %f\n", i, GENERAL[_ana]->ROI[i]->result_float);
+ printf("Result General(Analog)%i - CCW: %d - %f\n", i, GENERAL[_ana]->ROI[i]->CCW, GENERAL[_ana]->ROI[i]->result_float);
if (isLogImage)
{
diff --git a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h
index fd58153c..06444ba7 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h
+++ b/code/components/jomjol_flowcontroll/ClassFlowCNNGeneral.h
@@ -10,7 +10,6 @@ enum t_CNNType {
Analogue,
Analogue100,
Digital,
-// DigitalHyprid,
DigitalHyprid10,
DoubleHyprid10,
Digital100,
@@ -30,21 +29,18 @@ protected:
int DigitalBand = 3;
float DigitalAnalogerVorgaengerUebergangsbereich = 2;
float DigitalUebergangsbereichVorgaengerAnalogToDigit = 1; // war vorher 2
- float DigitalUebergangsbereichVorgaenger = 0.9;
+ float DigitalUebergangsbereichVorgaenger = 0.7; // 9.3 - 0.7
string cnnmodelfile;
int modelxsize, modelysize, modelchannel;
bool isLogImageSelect;
string LogImageSelect;
ClassFlowAlignment* flowpostalignment;
-// ClassFlowPostProcessing *flowpostprocessing = NULL;
- bool SaveAllFiles;
-// bool extendedResolution;
-// int ZeigerEval(float zahl, int ziffer_vorgaenger);
-// int ZeigerEvalHybrid(float zahl, float zahl_vorgaenger, int eval_vorgaenger);
+ bool SaveAllFiles;
+
int ZeigerEvalAnalogNeu(float zahl, int ziffer_vorgaenger);
- int ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger);
+ int ZeigerEvalAnalogToDigitNeu(float zahl, float ziffer_vorgaenger, int eval_vorgaenger);
int ZeigerEvalHybridNeu(float zahl, float zahl_vorgaenger, int eval_vorgaenger, bool AnalogerVorgaenger = false);
diff --git a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h
index 98432886..c296ca27 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h
+++ b/code/components/jomjol_flowcontroll/ClassFlowDefineTypes.h
@@ -7,7 +7,7 @@ struct roi {
int posx, posy, deltax, deltay;
float result_float;
int result_klasse;
- bool isReject;
+ bool isReject, CCW;
string name;
CImageBasis *image, *image_org;
};
@@ -33,9 +33,9 @@ struct NumberPost {
bool checkDigitIncreaseConsistency;
time_t lastvalue;
string timeStamp;
- float FlowRateAct; // m3 / min
- float PreValue; // letzter Wert, der gut ausgelesen wurde
- float Value; // letzer ausgelesener Wert, inkl. Korrekturen
+ double FlowRateAct; // m3 / min
+ double PreValue; // letzter Wert, der gut ausgelesen wurde
+ double Value; // letzer ausgelesener Wert, inkl. Korrekturen
string ReturnRateValue; // RückgabewertRate
string ReturnChangeAbsolute; // RückgabewertRate
string ReturnRawValue; // Rohwert (mit N & führenden 0)
diff --git a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp
index c50b8cda..4053b5dc 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowImage.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowImage.cpp
@@ -63,7 +63,12 @@ void ClassFlowImage::LogImage(string logPath, string name, float *resultFloat, i
if (*resultFloat < 0)
sprintf(buf, "N.N_");
else
+ {
sprintf(buf, "%.1f_", *resultFloat);
+ if (strcmp(buf, "10.0_"))
+ sprintf(buf, "0.0_");
+ }
+
} else if (resultInt != NULL) {
sprintf(buf, "%d_", *resultInt);
} else {
diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp
index f4e014e9..b82f7afe 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.cpp
@@ -6,6 +6,7 @@
#include "time_sntp.h"
#include "interface_mqtt.h"
#include "ClassFlowPostProcessing.h"
+#include "ClassLogFile.h"
#include
@@ -31,9 +32,7 @@ void ClassFlowMQTT::SetInitialParameter(void)
ListFlowControll = NULL;
disabled = false;
MQTTenable = false;
-
-
-
+ keepAlive = 600; // TODO This must be greater than the Flow Interval!
}
ClassFlowMQTT::ClassFlowMQTT()
@@ -124,11 +123,50 @@ bool ClassFlowMQTT::ReadParameter(FILE* pfile, string& aktparamgraph)
printf("InitMQTTInit\n");
mainerrortopic = maintopic + "/connection";
printf("Init MQTT with uri: %s, clientname: %s, user: %s, password: %s, maintopic: %s\n", uri.c_str(), clientname.c_str(), user.c_str(), password.c_str(), mainerrortopic.c_str());
- MQTTInit(uri, clientname, user, password, mainerrortopic, 60);
- MQTTPublish(mainerrortopic, "connected", SetRetainFlag);
- MQTTenable = true;
+ if (!MQTTInit(uri, clientname, user, password, mainerrortopic, keepAlive))
+ { // Failed
+ MQTTenable = false;
+ return true; // We need to return true despite we failed, else it will retry 5x and then reboot!
+ }
}
+
+ // Try sending mainerrortopic. If it fails, re-run init
+ if (!MQTTPublish(mainerrortopic, "connected", SetRetainFlag))
+ { // Failed
+ LogFile.WriteToFile("MQTT - Re-running init...!");
+ if (!MQTTInit(this->uri, this->clientname, this->user, this->password, this->mainerrortopic, keepAlive))
+ { // Failed
+ MQTTenable = false;
+ return false;
+ }
+ }
+
+ // Try again and quit if it fails
+ if (!MQTTPublish(mainerrortopic, "connected", SetRetainFlag))
+ { // Failed
+ MQTTenable = false;
+ return false;
+ }
+
+
+
+ /* if (!MQTTPublish(mainerrortopic, "connected", SetRetainFlag))
+ { // Failed
+ LogFile.WriteToFile("MQTT - Could not publish connection status!");
+ MQTTenable = false;
+ return true; // We need to return true despite we failed, else it will retry 5x and then reboot!
+ }*/
+
+ /* if(!MQTTPublish(_LWTContext, "", 1))
+ {
+ LogFile.WriteToFile("MQTT - Could not publish LWT!");
+ MQTTenable = false;
+ return true; // We need to return true despite we failed, else it will retry 5x and then reboot!
+ }*/
+
+
+ MQTTenable = true;
return true;
}
@@ -141,8 +179,44 @@ string ClassFlowMQTT::GetMQTTMainTopic()
bool ClassFlowMQTT::doFlow(string zwtime)
{
- if (!MQTTenable)
- return true;
+ // if (!MQTTenable) {
+ // LogFile.WriteToFile("MQTT not enabled!");
+ //
+ // // Try again to init it
+ // if (!MQTTInit(this->uri, this->clientname, this->user, this->password, this->mainerrortopic, keepAlive))
+ // { // Failed
+ // MQTTenable = false;
+ // return true; // We need to return true despite we failed, else it will retry 5x and then reboot!
+ // }
+ //
+ // if (!MQTTPublish(mainerrortopic, "connected", SetRetainFlag))
+ // { // Failed
+ // MQTTenable = false;
+ // return true; // We need to return true despite we failed, else it will retry 5x and then reboot!
+ // }
+ //
+ // LogFile.WriteToFile("MQTT is now enabled");
+ // MQTTenable = true;
+ // }
+
+
+ // Try sending mainerrortopic. If it fails, re-run init
+ if (!MQTTPublish(mainerrortopic, "connected", SetRetainFlag))
+ { // Failed
+ LogFile.WriteToFile("MQTT - Re-running init...!");
+ if (!MQTTInit(this->uri, this->clientname, this->user, this->password, this->mainerrortopic, keepAlive))
+ { // Failed
+ MQTTenable = false;
+ return true; // We need to return true despite we failed, else it will retry 5x and then reboot!
+ }
+ }
+
+ // Try again and quit if it fails
+ if (!MQTTPublish(mainerrortopic, "connected", SetRetainFlag))
+ { // Failed
+ MQTTenable = false;
+ return true; // We need to return true despite we failed, else it will retry 5x and then reboot!
+ }
std::string result;
std::string resulterror = "";
@@ -153,7 +227,10 @@ bool ClassFlowMQTT::doFlow(string zwtime)
string zw = "";
string namenumber = "";
- MQTTPublish(mainerrortopic, "connected");
+ // if (!MQTTPublish(mainerrortopic, "connected", SetRetainFlag))
+ //{ // Failed, skip other topics
+ // return true; // We need to return true despite we failed, else it will retry 5x and then reboot!
+ //}
zw = maintopic + "/" + "uptime";
char uptimeStr[11];
@@ -163,13 +240,19 @@ bool ClassFlowMQTT::doFlow(string zwtime)
zw = maintopic + "/" + "freeMem";
char freeheapmem[11];
sprintf(freeheapmem, "%zu", esp_get_free_heap_size());
- MQTTPublish(zw, freeheapmem, SetRetainFlag);
+ if (!MQTTPublish(zw, freeheapmem, SetRetainFlag))
+ { // Failed, skip other topics
+ return true; // We need to return true despite we failed, else it will retry 5x and then reboot!
+ }
zw = maintopic + "/" + "wifiRSSI";
char rssi[11];
sprintf(rssi, "%d", get_WIFI_RSSI());
MQTTPublish(zw, rssi, SetRetainFlag);
+ zw = maintopic + "/" + "CPUtemp";
+ std::string cputemp = std::to_string(temperatureRead());
+ MQTTPublish(zw, cputemp, SetRetainFlag);
if (flowpostprocessing)
{
diff --git a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h
index 816389b1..3a990c7d 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowMQTT.h
+++ b/code/components/jomjol_flowcontroll/ClassFlowMQTT.h
@@ -15,6 +15,7 @@ protected:
std::string user, password;
int SetRetainFlag;
bool MQTTenable;
+ int keepAlive;
std::string maintopic, mainerrortopic;
void SetInitialParameter(void);
diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp
index 9d0f85c5..73feef3e 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp
+++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.cpp
@@ -9,6 +9,7 @@
#include
#include "time_sntp.h"
+//#define SERIAL_DEBUG // testing debug on serial enabled
#define PREVALUE_TIME_FORMAT_OUTPUT "%Y-%m-%dT%H:%M:%S"
@@ -68,7 +69,7 @@ string ClassFlowPostProcessing::GetPreValue(std::string _number)
return result;
}
-void ClassFlowPostProcessing::SetPreValue(float zw, string _numbers, bool _extern)
+void ClassFlowPostProcessing::SetPreValue(double zw, string _numbers, bool _extern)
{
printf("SetPrevalue: %f, %s\n", zw, _numbers.c_str());
for (int j = 0; j < NUMBERS.size(); ++j)
@@ -126,7 +127,7 @@ bool ClassFlowPostProcessing::LoadPreValue(void)
{
if (NUMBERS[j]->name == name)
{
- NUMBERS[j]->PreValue = stof(zwvalue.c_str());
+ NUMBERS[j]->PreValue = stod(zwvalue.c_str());
NUMBERS[j]->ReturnPreValue = RundeOutput(NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma + 1); // SIcherheitshalber 1 Stelle mehr, da ggf. Exgtended Resolution an ist (wird erst beim ersten Durchlauf gesetzt)
time_t tStart;
@@ -177,7 +178,7 @@ bool ClassFlowPostProcessing::LoadPreValue(void)
fclose(pFile);
printf("%s", zw);
zwvalue = trim(std::string(zw));
- NUMBERS[0]->PreValue = stof(zwvalue.c_str());
+ NUMBERS[0]->PreValue = stod(zwvalue.c_str());
time_t tStart;
int yy, month, dd, hh, mm, ss;
@@ -663,7 +664,9 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
previous_value = zw - 48;
}
}
-
+ #ifdef SERIAL_DEBUG
+ printf("After analog->getReadout: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str());
+ #endif
if (NUMBERS[j]->digit_roi && NUMBERS[j]->analog_roi)
NUMBERS[j]->ReturnRawValue = "." + NUMBERS[j]->ReturnRawValue;
@@ -674,16 +677,22 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
else
NUMBERS[j]->ReturnRawValue = flowDigit->getReadout(j, NUMBERS[j]->isExtendedResolution, previous_value); // Extended Resolution nur falls es keine analogen Ziffern gibt
}
-
+ #ifdef SERIAL_DEBUG
+ printf("After digital->getReadout: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str());
+ #endif
NUMBERS[j]->ReturnRawValue = ShiftDecimal(NUMBERS[j]->ReturnRawValue, NUMBERS[j]->DecimalShift);
- printf("ReturnRaw %s", NUMBERS[j]->ReturnRawValue.c_str());
-
+ #ifdef SERIAL_DEBUG
+ printf("After ShiftDecimal: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str());
+ #endif
if (IgnoreLeadingNaN)
while ((NUMBERS[j]->ReturnRawValue.length() > 1) && (NUMBERS[j]->ReturnRawValue[0] == 'N'))
NUMBERS[j]->ReturnRawValue.erase(0, 1);
+ #ifdef SERIAL_DEBUG
+ printf("After IgnoreLeadingNaN: ReturnRaw %s\n", NUMBERS[j]->ReturnRawValue.c_str());
+ #endif
NUMBERS[j]->ReturnValue = NUMBERS[j]->ReturnRawValue;
if (findDelimiterPos(NUMBERS[j]->ReturnValue, "N") != std::string::npos)
@@ -693,18 +702,38 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
else
continue; // es gibt keinen Zahl, da noch ein N vorhanden ist.
}
-
+ #ifdef SERIAL_DEBUG
+ printf("After findDelimiterPos: ReturnValue %s\n", NUMBERS[j]->ReturnRawValue.c_str());
+ #endif
// Lösche führende Nullen (außer es ist nur noch einen 0)
while ((NUMBERS[j]->ReturnValue.length() > 1) && (NUMBERS[j]->ReturnValue[0] == '0'))
NUMBERS[j]->ReturnValue.erase(0, 1);
-
- NUMBERS[j]->Value = std::stof(NUMBERS[j]->ReturnValue);
+ #ifdef SERIAL_DEBUG
+ printf("After removeLeadingZeros: ReturnValue %s\n", NUMBERS[j]->ReturnRawValue.c_str());
+ #endif
+ NUMBERS[j]->Value = std::stod(NUMBERS[j]->ReturnValue);
+ #ifdef SERIAL_DEBUG
+ printf("After setting the Value: Value %f and as double is %f\n", NUMBERS[j]->Value, std::stod(NUMBERS[j]->ReturnValue));
+ #endif
if (NUMBERS[j]->checkDigitIncreaseConsistency)
{
- NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
+ if (flowDigit)
+ {
+ if (flowDigit->getCNNType() != Digital)
+ printf("checkDigitIncreaseConsistency = true - ignored due to wrong CNN-Type (not Digital Classification)\n");
+ else
+ NUMBERS[j]->Value = checkDigitConsistency(NUMBERS[j]->Value, NUMBERS[j]->DecimalShift, NUMBERS[j]->analog_roi != NULL, NUMBERS[j]->PreValue);
+ }
+ else
+ {
+ printf("checkDigitIncreaseConsistency = true - no digital numbers defined!\n");
+ }
}
+ #ifdef SERIAL_DEBUG
+ printf("After checkDigitIncreaseConsistency: Value %f\n", NUMBERS[j]->Value);
+ #endif
if (!NUMBERS[j]->AllowNegativeRates)
@@ -717,7 +746,9 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
continue;
}
}
-
+ #ifdef SERIAL_DEBUG
+ printf("After AllowNegativeRates: Value %f\n", NUMBERS[j]->Value);
+ #endif
double difference = difftime(imagetime, NUMBERS[j]->lastvalue); // in Sekunden
difference /= 60;
NUMBERS[j]->FlowRateAct = (NUMBERS[j]->Value - NUMBERS[j]->PreValue) / difference;
@@ -725,7 +756,7 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
if (NUMBERS[j]->useMaxRateValue && PreValueUse && NUMBERS[j]->PreValueOkay)
{
- float _ratedifference;
+ double _ratedifference;
if (NUMBERS[j]->RateType == RateChange)
_ratedifference = NUMBERS[j]->FlowRateAct;
else
@@ -740,7 +771,9 @@ bool ClassFlowPostProcessing::doFlow(string zwtime)
continue;
}
}
-
+ #ifdef SERIAL_DEBUG
+ printf("After MaxRateCheck: Value %f\n", NUMBERS[j]->Value);
+ #endif
NUMBERS[j]->ReturnChangeAbsolute = RundeOutput(NUMBERS[j]->Value - NUMBERS[j]->PreValue, NUMBERS[j]->Nachkomma);
NUMBERS[j]->lastvalue = imagetime;
NUMBERS[j]->PreValue = NUMBERS[j]->Value;
@@ -818,7 +851,7 @@ string ClassFlowPostProcessing::getReadoutParam(bool _rawValue, bool _noerror, i
return NUMBERS[_number]->ReturnValue;
}
-string ClassFlowPostProcessing::RundeOutput(float _in, int _anzNachkomma){
+string ClassFlowPostProcessing::RundeOutput(double _in, int _anzNachkomma){
std::stringstream stream;
int _zw = _in;
// printf("AnzNachkomma: %d\n", _anzNachkomma);
@@ -842,7 +875,7 @@ string ClassFlowPostProcessing::RundeOutput(float _in, int _anzNachkomma){
}
-string ClassFlowPostProcessing::ErsetzteN(string input, float _prevalue)
+string ClassFlowPostProcessing::ErsetzteN(string input, double _prevalue)
{
int posN, posPunkt;
int pot, ziffer;
@@ -873,7 +906,7 @@ string ClassFlowPostProcessing::ErsetzteN(string input, float _prevalue)
return input;
}
-float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamshift, bool _isanalog, float _preValue){
+float ClassFlowPostProcessing::checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue){
int aktdigit, olddigit;
int aktdigit_before, olddigit_before;
int pot, pot_max;
@@ -885,8 +918,14 @@ float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamsh
{
pot++;
}
+ #ifdef SERIAL_DEBUG
+ printf("checkDigitConsistency: pot=%d, decimalshift=%d\n", pot, _decilamshift);
+ #endif
pot_max = ((int) log10(input)) + 1;
-
+ float not_checked_input = floorf(input * pow(10, pot)) / pow(10, pot);
+ #ifdef SERIAL_DEBUG
+ printf("checkDigitConsistency: not_checked_input=%f\n", not_checked_input);
+ #endif
while (pot <= pot_max)
{
zw = input / pow(10, pot-1);
@@ -915,11 +954,13 @@ float ClassFlowPostProcessing::checkDigitConsistency(float input, int _decilamsh
input = input + ((float) (1)) * pow(10, pot); // addiere 1 an der Stelle
}
}
-
+ #ifdef SERIAL_DEBUG
+ printf("checkDigitConsistency: input=%f", input);
+ #endif
pot++;
}
- return input;
+ return not_checked_input + input;
}
string ClassFlowPostProcessing::getReadoutRate(int _number)
diff --git a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h
index 34b2309c..0d99958d 100644
--- a/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h
+++ b/code/components/jomjol_flowcontroll/ClassFlowPostProcessing.h
@@ -32,9 +32,9 @@ protected:
bool LoadPreValue(void);
string ShiftDecimal(string in, int _decShift);
- string ErsetzteN(string, float _prevalue);
- float checkDigitConsistency(float input, int _decilamshift, bool _isanalog, float _preValue);
- string RundeOutput(float _in, int _anzNachkomma);
+ string ErsetzteN(string, double _prevalue);
+ float checkDigitConsistency(double input, int _decilamshift, bool _isanalog, double _preValue);
+ string RundeOutput(double _in, int _anzNachkomma);
void InitNUMBERS();
void handleDecimalSeparator(string _decsep, string _value);
@@ -58,7 +58,7 @@ public:
string getReadoutTimeStamp(int _number = 0);
void SavePreValue();
string GetPreValue(std::string _number = "");
- void SetPreValue(float zw, string _numbers, bool _extern = false);
+ void SetPreValue(double zw, string _numbers, bool _extern = false);
std::string GetJSON(std::string _id = "", std::string _mac = "", std::string _lineend = "\n");
diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp
index fe299f54..411553b0 100644
--- a/code/components/jomjol_helper/Helper.cpp
+++ b/code/components/jomjol_helper/Helper.cpp
@@ -209,6 +209,21 @@ size_t findDelimiterPos(string input, string delimiter)
return pos;
}
+void DeleteFile(string fn)
+{
+// ESP_LOGI(logTag, "Deleting file : %s", fn.c_str());
+ /* Delete file */
+ FILE* fpSourceFile = OpenFileAndWait(fn.c_str(), "rb");
+ if (!fpSourceFile) // Sourcefile existiert nicht sonst gibt es einen Fehler beim Kopierversuch!
+ {
+ printf("DeleteFile: File %s existiert nicht!\n", fn.c_str());
+ return;
+ }
+ fclose(fpSourceFile);
+
+ unlink(fn.c_str());
+}
+
void CopyFile(string input, string output)
{
@@ -243,18 +258,48 @@ void CopyFile(string input, string output)
// Close The Files
fclose(fpSourceFile);
fclose(fpTargetFile);
+ printf("File copied: %s to %s", input.c_str(), output.c_str());
}
+string getFileFullFileName(string filename)
+{
+ size_t lastpos = filename.find_last_of('/');
+
+ if (lastpos == string::npos)
+ return "";
+
+// printf("Last position: %d\n", lastpos);
+
+ string zw = filename.substr(lastpos + 1, filename.size() - lastpos);
+
+ return zw;
+}
+
+string getDirectory(string filename)
+{
+ size_t lastpos = filename.find('/');
+
+ if (lastpos == string::npos)
+ return "";
+
+// printf("Directory: %d\n", lastpos);
+
+ string zw = filename.substr(0, lastpos - 1);
+ return zw;
+}
string getFileType(string filename)
{
- int lastpos = filename.find(".", 0);
- int neu_pos;
+ size_t lastpos = filename.find(".", 0);
+ size_t neu_pos;
while ((neu_pos = filename.find(".", lastpos + 1)) > -1)
{
lastpos = neu_pos;
}
+ if (lastpos == string::npos)
+ return "";
+
string zw = filename.substr(lastpos + 1, filename.size() - lastpos);
zw = toUpper(zw);
diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h
index 46fbf8d6..ab263cf2 100644
--- a/code/components/jomjol_helper/Helper.h
+++ b/code/components/jomjol_helper/Helper.h
@@ -10,6 +10,7 @@ std::string FormatFileName(std::string input);
void FindReplace(std::string& line, std::string& oldString, std::string& newString);
void CopyFile(string input, string output);
+void DeleteFile(string fn);
FILE* OpenFileAndWait(const char* nm, const char* _mode, int _waitsec = 1);
@@ -19,6 +20,8 @@ string trim(string istring, string adddelimiter = "");
bool ctype_space(const char c, string adddelimiter);
string getFileType(string filename);
+string getFileFullFileName(string filename);
+string getDirectory(string filename);
int mkdir_r(const char *dir, const mode_t mode);
int removeFolder(const char* folderPath, const char* logTag);
diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp
index f9a790fe..f462e7a4 100644
--- a/code/components/jomjol_logfile/ClassLogFile.cpp
+++ b/code/components/jomjol_logfile/ClassLogFile.cpp
@@ -129,6 +129,7 @@ void ClassLogFile::WriteToFile(std::string info, bool _time)
std::string logpath = logroot + "/" + buffer;
WriteToDedicatedFile(logpath, info, _time);
+ printf((info + "\n").c_str());
}
std::string ClassLogFile::GetCurrentFileName()
diff --git a/code/components/jomjol_mqtt/interface_mqtt.cpp b/code/components/jomjol_mqtt/interface_mqtt.cpp
index ef98aff4..556a50d8 100644
--- a/code/components/jomjol_mqtt/interface_mqtt.cpp
+++ b/code/components/jomjol_mqtt/interface_mqtt.cpp
@@ -19,18 +19,43 @@ esp_mqtt_event_id_t esp_mmqtt_ID = MQTT_EVENT_ANY;
bool mqtt_connected = false;
esp_mqtt_client_handle_t client = NULL;
-void MQTTPublish(std::string _key, std::string _content, int retained_flag){
- if (client && mqtt_connected) {
- int msg_id;
- std::string zw;
- msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, retained_flag);
- zw = "sent publish successful in MQTTPublish, msg_id=" + std::to_string(msg_id) + ", " + _key + ", " + _content;
- if (debugdetail) LogFile.WriteToFile(zw);
- ESP_LOGD(TAG_INTERFACEMQTT, "sent publish successful in MQTTPublish, msg_id=%d, %s, %s", msg_id, _key.c_str(), _content.c_str());
+bool MQTTPublish(std::string _key, std::string _content, int retained_flag){
+
+ // if (!client) {
+ // LogFile.WriteToFile("MQTT - client not initialized!");
+ // return false;
+ // }
+ // LogFile.WriteToFile("MQTT - client initialized!"); // Debug
+ //
+ // if (!mqtt_connected) {
+ // LogFile.WriteToFile("MQTT - Can not publish, not connected!");
+ // ESP_LOGW(TAG_INTERFACEMQTT, "Problem with Publish, client=%d, mqtt_connected %d", (int) client, (int) mqtt_connected);
+ // return false;
+ // }
+ // LogFile.WriteToFile("MQTT - connected!"); // Debug
+
+ /* if (client && mqtt_connected) {
+ LogFile.WriteToFile("MQTT - connected!"); // Debug
}
- else {
- ESP_LOGW(TAG_INTERFACEMQTT, "Problem with Publish, client=%d, mqtt_connected %d", (int) client, (int) mqtt_connected);
+ else { // init needed
+ if (!MQTTInit(this->uri, this->clientname, this->user, password, mainerrortopic, keepAlive)) // validate{
+ { // Failed
+ return false;
+ }
+ }*/
+
+
+ int msg_id;
+ std::string zw;
+ msg_id = esp_mqtt_client_publish(client, _key.c_str(), _content.c_str(), 0, 1, retained_flag);
+ if (msg_id < 0) {
+ LogFile.WriteToFile("MQTT - Failed to publish '" + _key + "'!");
+ return false;
}
+ zw = "MQTT - sent publish successful in MQTTPublish, msg_id=" + std::to_string(msg_id) + ", " + _key + ", " + _content;
+ if (debugdetail) LogFile.WriteToFile(zw);
+ ESP_LOGD(TAG_INTERFACEMQTT, "sent publish successful in MQTTPublish, msg_id=%d, %s, %s", msg_id, _key.c_str(), _content.c_str());
+ return true;
}
@@ -90,11 +115,23 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
mqtt_event_handler_cb((esp_mqtt_event_handle_t) event_data);
}
-void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _LWTContext, int _keepalive){
+
+bool MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, std::string _password, std::string _LWTContext, int _keepalive){
std::string _zwmessage = "connection lost";
int _lzw = _zwmessage.length();
+/* LWTContext = _LWTContext;
+
+ mqtt_cfg.uri = _mqttURI.c_str();
+ mqtt_cfg.client_id = _clientid.c_str();
+ mqtt_cfg.lwt_topic = _LWTContext.c_str();
+ mqtt_cfg.lwt_msg = _zwmessage.c_str();
+ mqtt_cfg.lwt_retain = 1;
+ mqtt_cfg.lwt_msg_len = _lzw;
+ mqtt_cfg.keepalive = _keepalive;
+*/
+
esp_mqtt_client_config_t mqtt_cfg = {
.uri = _mqttURI.c_str(),
.client_id = _clientid.c_str(),
@@ -105,12 +142,51 @@ void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, st
.keepalive = _keepalive
};
+ LogFile.WriteToFile("MQTT - Init");
+
if (_user.length() && _password.length()){
mqtt_cfg.username = _user.c_str();
mqtt_cfg.password = _password.c_str();
ESP_LOGI(TAG_INTERFACEMQTT, "Connect to MQTT: %s, %s", mqtt_cfg.username, mqtt_cfg.password);
};
+ MQTTdestroy();
+ client = esp_mqtt_client_init(&mqtt_cfg);
+ if (client)
+ {
+ if (esp_mqtt_client_register_event(client, esp_mmqtt_ID, mqtt_event_handler, client) != ESP_OK)
+ {
+ LogFile.WriteToFile("MQTT - Could not register event!");
+ return false;
+ }
+ if (esp_mqtt_client_start(client) != ESP_OK)
+ {
+ LogFile.WriteToFile("MQTT - Could not start client!");
+ return false;
+ }
+
+ /* if(!MQTTPublish(_LWTContext, "", 1))
+ {
+ LogFile.WriteToFile("MQTT - Could not publish LWT!");
+ return false;
+ }*/
+ }
+ else
+ {
+ LogFile.WriteToFile("MQTT - Could not Init client!");
+ return false;
+ }
+
+ LogFile.WriteToFile("MQTT - Init successful");
+ return true;
+}
+
+/*
+void MQTTReConnect(){
+ std::string _zwmessage = "connection lost";
+ int _lzw = _zwmessage.length();
+
+>>>>>>> Stashed changes
client = esp_mqtt_client_init(&mqtt_cfg);
if (client)
{
@@ -119,14 +195,25 @@ void MQTTInit(std::string _mqttURI, std::string _clientid, std::string _user, st
if (esp_mqtt_client_start(client) != ESP_OK)
LogFile.WriteToFile("MQTT - Could not start client!");
- MQTTPublish(_LWTContext, "", 1);
+<<<<<<< Updated upstream
+ if(MQTTPublish(_LWTContext, "", 1)) {
+ LogFile.WriteToFile("MQTT - Client init successful");
+ }
+=======
+ if (mqtt_connected)
+ MQTTPublish(LWTContext, "", 1);
+ else
+ LogFile.WriteToFile("Problem with (Re)Connection not successful!");
+
+>>>>>>> Stashed changes
}
else
{
- LogFile.WriteToFile("MQTT - Could not Init MQTT Client!");
+ LogFile.WriteToFile("MQTT - Could not Init client!");
}
}
+*/
void MQTTdestroy() {
if (client != NULL) {
@@ -185,6 +272,7 @@ void MQTTregisterSubscribeFunction(std::string topic, std::function>::iterator it = connectFunktionMap->begin(); it != connectFunktionMap->end(); ++it) {
it->second();
@@ -192,10 +280,11 @@ void MQTTconnected(){
}
}
- if (subscribeFunktionMap != NULL) {
+ if (subscribeFunktionMap != NULL) {
for(std::map>::iterator it = subscribeFunktionMap->begin(); it != subscribeFunktionMap->end(); ++it) {
int msg_id = esp_mqtt_client_subscribe(client, it->first.c_str(), 0);
ESP_LOGD(TAG_INTERFACEMQTT, "topic %s subscribe successful, msg_id=%d", it->first.c_str(), msg_id);
+ LogFile.WriteToFile("MQTT - topic " + it->first + " subscribe successful, msg_id=" + std::to_string(msg_id));
}
}
}
diff --git a/code/components/jomjol_mqtt/interface_mqtt.h b/code/components/jomjol_mqtt/interface_mqtt.h
index 397d1787..06210782 100644
--- a/code/components/jomjol_mqtt/interface_mqtt.h
+++ b/code/components/jomjol_mqtt/interface_mqtt.h
@@ -5,12 +5,12 @@
#include