jomjol 5 anni fa
parent
commit
a08144cc9f

+ 9 - 2
README.md

@@ -27,10 +27,17 @@ A 3d-printable housing can be found here: https://www.thingiverse.com/thing:4571
 
 
 
-##### Rolling - (2020-09-23)
+##### Rolling - (2020-09-25)
 
-* Error Correction for Chrome and Firefox Support
+* Reduce logging to minimum to reduce `log.txt`. Extended logging can be enabled via `config.ini`: `Logfile = True`
+* Update default CNN for digits to v6.4.0
+* Improvement HTML
+* Bug fixing: Parameter `PreValueAgeStartup` not correctly used
+* Mechanism for reducing spontaneous reboots further
+
+2020-09-23
 
+* Error Correction for Chrome and Firefox Support
 * Update CNN for digits to v6.4.0 (**Update of `config.ini` and upload of `dig0640s3.tflite` necessary)
 
 2020-09-21

+ 12 - 1
code/lib/jomjol_flowcontroll/ClassFlowAnalog.cpp

@@ -10,6 +10,8 @@
 #include "CTfLiteClass.h"
 #endif
 
+#include "ClassLogFile.h"
+
 ClassFlowAnalog::ClassFlowAnalog()
 {
     isLogImage = false;
@@ -140,7 +142,10 @@ string ClassFlowAnalog::getHTMLSingleStep(string host)
 
 bool ClassFlowAnalog::doFlow(string time)
 {
-    doAlignAndCut(time);
+    if (!doAlignAndCut(time)){
+        return false;
+    };
+
     doNeuralNetwork(time);
 
     return true;
@@ -160,6 +165,12 @@ bool ClassFlowAnalog::doAlignAndCut(string time)
     CImageBasis *img_roi = NULL;
     CAlignAndCutImage *caic = new CAlignAndCutImage(input);
 
+    if (!caic->ImageOkay()){
+        LogFile.WriteToFile("ClassFlowAnalog::doAlignAndCut not okay!");
+        delete caic;
+        return false;
+    }
+
     if (input_roi.length() > 0)
         img_roi = new CImageBasis(input_roi);    
 

+ 294 - 0
code/lib/jomjol_flowcontroll/ClassFlowControll._c_pp

@@ -0,0 +1,294 @@
+#include "ClassFlowControll.h"
+
+#include "ClassLogFile.h"
+#include "time_sntp.h"
+#include "Helper.h"
+#include "server_ota.h"
+
+std::string ClassFlowControll::doSingleStep(std::string _stepname, std::string _host){
+    bool found = false;
+    std::string _classname = "";
+    std::string result = "";
+    if (_stepname.compare("[MakeImage]") == 0){
+        _classname = "ClassFlowMakeImage";
+    }
+    if (_stepname.compare("[Alignment]") == 0){
+        _classname = "ClassFlowAlignment";
+    }
+    if (_stepname.compare("[Digits]") == 0){
+        _classname = "ClassFlowDigit";
+    }
+    if (_stepname.compare("[Analog]") == 0){
+        _classname = "ClassFlowAnalog";
+    }
+//    std::string zw = "Classname: " + _classname + "\n";
+//    printf(zw.c_str());
+
+    for (int i = 0; i < FlowControll.size(); ++i)
+        if (FlowControll[i]->name().compare(_classname) == 0){
+ //           printf(FlowControll[i]->name().c_str()); printf("\n");
+            FlowControll[i]->doFlow("");
+            result = FlowControll[i]->getHTMLSingleStep(_host);
+            found = true;
+        }
+
+    return result;
+}
+
+std::vector<HTMLInfo*> ClassFlowControll::GetAllDigital()
+{
+    for (int i = 0; i < FlowControll.size(); ++i)
+        if (FlowControll[i]->name().compare("ClassFlowDigit") == 0)
+            return ((ClassFlowDigit*) (FlowControll[i]))->GetHTMLInfo();
+
+    std::vector<HTMLInfo*> empty;
+    return empty;
+}
+
+std::vector<HTMLInfo*> ClassFlowControll::GetAllAnalog()
+{
+    for (int i = 0; i < FlowControll.size(); ++i)
+        if (FlowControll[i]->name().compare("ClassFlowAnalog") == 0)
+            return ((ClassFlowAnalog*) (FlowControll[i]))->GetHTMLInfo();
+
+    std::vector<HTMLInfo*> empty;
+    return empty;
+}
+
+
+void ClassFlowControll::SetInitialParameter(void)
+{
+    AutoStart = false;
+    AutoIntervall = 10;
+}
+
+bool ClassFlowControll::isAutoStart(long &_intervall)
+{
+    _intervall = AutoIntervall * 60 * 1000; // AutoIntervall: Minuten -> ms
+    return AutoStart;
+}
+
+ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
+{
+    ClassFlow* cfc = NULL;
+
+    _type = trim(_type);
+
+    if (_type.compare("[MakeImage]") == 0)
+        cfc = new ClassFlowMakeImage(&FlowControll);
+    if (_type.compare("[Alignment]") == 0)
+        cfc = new ClassFlowAlignment(&FlowControll);
+    if (_type.compare("[Analog]") == 0)
+        cfc = new ClassFlowAnalog(&FlowControll);
+    if (_type.compare("[Digits]") == 0)
+        cfc = new ClassFlowDigit(&FlowControll);
+    if (_type.compare("[PostProcessing]") == 0)
+    {
+        cfc = new ClassFlowPostProcessing(&FlowControll); 
+        flowpostprocessing = (ClassFlowPostProcessing*) cfc;
+    }
+
+    if (cfc)                            // Wird nur angehangen, falls es nicht [AutoTimer] ist, denn dieses ist für FlowControll
+        FlowControll.push_back(cfc);
+
+    if (_type.compare("[AutoTimer]") == 0)
+        cfc = this;   
+
+    if (_type.compare("[Debug]") == 0)
+        cfc = this;           
+
+    return cfc;
+}
+
+void ClassFlowControll::InitFlow(std::string config)
+{
+    string line;
+
+    flowpostprocessing = NULL;
+
+    ClassFlow* cfc;
+    FILE* pFile;
+    config = FormatFileName(config);
+    pFile = fopen(config.c_str(), "r");
+
+    line = "";
+
+    char zw[1024];
+    if (pFile != NULL)
+    {
+        fgets(zw, 1024, pFile);
+        printf("%s", zw);
+        line = std::string(zw);
+    }
+
+    while ((line.size() > 0) && !(feof(pFile)))
+    {
+        cfc = CreateClassFlow(line);
+        if (cfc)
+        {
+            cfc->ReadParameter(pFile, line);
+        }
+        else
+        {
+            fgets(zw, 1024, pFile);
+            printf("%s", zw);
+            line = std::string(zw);
+        }
+    }
+
+    fclose(pFile);
+
+}
+
+std::string ClassFlowControll::getActStatus(){
+    return aktstatus;
+}
+
+bool ClassFlowControll::doFlow(string time)
+{
+    bool result = true;
+    std::string zw_time;
+    int repeat = 0;
+
+    for (int i = 0; i < FlowControll.size(); ++i)
+    {
+        zw_time = gettimestring("%Y%m%d-%H%M%S");
+        aktstatus = zw_time + ": " + FlowControll[i]->name();
+        string zw = "FlowControll.doFlow - " + FlowControll[i]->name();
+        LogFile.WriteToFile(zw);
+        if (!FlowControll[i]->doFlow(time)){
+            repeat++;
+            LogFile.WriteToFile("Fehler im vorheriger Schritt - wird zum " + to_string(repeat) + ". Mal wiederholt");
+            i = -1;    // Soll wieder bei i = 0 anfangen ==> komplett von vorne !!!
+            result = false;
+            if (repeat > 5) {
+                LogFile.WriteToFile("Wiederholung 5x nicht erfolgreich --> reboot");
+                doReboot();
+                // Schritt wurde 5x wiederholt --> reboot
+            }
+        }
+        else
+        {
+            result = true;
+        }
+    }
+    zw_time = gettimestring("%Y%m%d-%H%M%S");    
+    aktstatus = zw_time + ": Flow is done";
+    return result;
+}
+
+string ClassFlowControll::getReadout(bool _rawvalue = false, bool _noerror = false)
+{
+    if (flowpostprocessing)
+        return flowpostprocessing->getReadoutParam(_rawvalue, _noerror);
+
+    string zw = "";
+    string result = "";
+
+    for (int i = 0; i < FlowControll.size(); ++i)
+    {
+        zw = FlowControll[i]->getReadout();
+        if (zw.length() > 0)
+        {
+            if (result.length() == 0)
+                result = zw;
+            else
+                result = result + "\t" + zw;
+        }
+    }
+
+    return result;
+}
+
+string ClassFlowControll::GetPrevalue()	
+{
+    if (flowpostprocessing)
+    {
+        return flowpostprocessing->GetPreValue();   
+    }
+
+    return std::string();    
+}
+
+std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue)
+{
+    float zw;
+    char* p;
+
+    _newvalue = trim(_newvalue);
+//    printf("Input UpdatePreValue: %s\n", _newvalue.c_str());
+
+    if (_newvalue.compare("0.0") == 0)
+    {
+        zw = 0;
+    }
+    else
+    {
+        zw = strtof(_newvalue.c_str(), &p);
+        if (zw == 0)
+            return "- Error in String to Value Conversion!!! Must be of format value=123.456";
+    }
+    
+
+    if (flowpostprocessing)
+    {
+        flowpostprocessing->SavePreValue(zw);
+        return to_string(zw);    
+    }
+
+    return std::string();
+}
+
+bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
+{
+    std::vector<string> zerlegt;
+
+    aktparamgraph = trim(aktparamgraph);
+
+    if (aktparamgraph.size() == 0)
+        if (!this->GetNextParagraph(pfile, aktparamgraph)){
+            return false;
+        }
+
+//    if ((aktparamgraph.compare("[Autotimer]") != 0) && (aktparamgraph.compare("[Debug]") != 0))      // Paragraph passt nich zu MakeImage
+    if (aktparamgraph.compare("[Autotimer]") != 0)      // Paragraph passt nich zu MakeImage
+        return false;
+
+//    if ((toUpper(aktparamgraph) != "[AUTOTIMER]") && (toUpper(aktparamgraph) != ("[DEBUG]")))      // Paragraph passt nich zu MakeImage
+//        return false;
+
+    while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
+    {
+        zerlegt = this->ZerlegeZeile(aktparamgraph);
+        if ((toUpper(zerlegt[0]) == "AUTOSTART") && (zerlegt.size() > 1))
+        {
+            if (toUpper(zerlegt[1]) == "TRUE")
+            {
+                AutoStart = true;
+            }
+        }
+
+        if ((toUpper(zerlegt[0]) == "INTERVALL") && (zerlegt.size() > 1))
+        {
+            AutoIntervall = std::stof(zerlegt[1]);
+        }
+
+/*
+        if ((toUpper(zerlegt[0]) == "LOGFILE") && (zerlegt.size() > 1))
+        {
+            if (toUpper(zerlegt[1]) == "TRUE")
+            {
+                LogFile.SwitchOnOff(true);
+                printf("TurnLogFile On\n");
+            }
+            if (toUpper(zerlegt[1]) == "FALSE")
+            {
+                LogFile.SwitchOnOff(false);
+                printf("TurnLogFile Off\n");
+            }            
+        }
+*/
+    }
+    return true;
+}
+

+ 24 - 10
code/lib/jomjol_flowcontroll/ClassFlowControll.cpp

@@ -74,15 +74,15 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
 
     _type = trim(_type);
 
-    if (_type.compare("[MakeImage]") == 0)
+    if (toUpper(_type).compare("[MAKEIMAGE]") == 0)
         cfc = new ClassFlowMakeImage(&FlowControll);
-    if (_type.compare("[Alignment]") == 0)
+    if (toUpper(_type).compare("[ALIGNMENT]") == 0)
         cfc = new ClassFlowAlignment(&FlowControll);
-    if (_type.compare("[Analog]") == 0)
+    if (toUpper(_type).compare("[ANALOG]") == 0)
         cfc = new ClassFlowAnalog(&FlowControll);
-    if (_type.compare("[Digits]") == 0)
+    if (toUpper(_type).compare("[DIGITS]") == 0)
         cfc = new ClassFlowDigit(&FlowControll);
-    if (_type.compare("[PostProcessing]") == 0)
+    if (toUpper(_type).compare("[POSTPROCESSING]") == 0)
     {
         cfc = new ClassFlowPostProcessing(&FlowControll); 
         flowpostprocessing = (ClassFlowPostProcessing*) cfc;
@@ -91,9 +91,12 @@ ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
     if (cfc)                            // Wird nur angehangen, falls es nicht [AutoTimer] ist, denn dieses ist für FlowControll
         FlowControll.push_back(cfc);
 
-    if (_type.compare("[AutoTimer]") == 0)
+    if (toUpper(_type).compare("[AUTOTIMER]") == 0)
         cfc = this;    
 
+    if (toUpper(_type).compare("[DEBUG]") == 0)
+        cfc = this;  
+
     return cfc;
 }
 
@@ -230,7 +233,7 @@ std::string ClassFlowControll::UpdatePrevalue(std::string _newvalue)
     if (flowpostprocessing)
     {
         flowpostprocessing->SavePreValue(zw);
-        return to_string(zw);    
+        return _newvalue;    
     }
 
     return std::string();
@@ -247,23 +250,34 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
             return false;
 
 
-    if (aktparamgraph.compare("[AutoTimer]") != 0)       // Paragraph passt nich zu MakeImage
+    if ((toUpper(aktparamgraph).compare("[AUTOTIMER]") != 0) && (toUpper(aktparamgraph).compare("[DEBUG]") != 0))      // Paragraph passt nicht zu MakeImage
         return false;
 
     while (this->getNextLine(pfile, &aktparamgraph) && !this->isNewParagraph(aktparamgraph))
     {
         zerlegt = this->ZerlegeZeile(aktparamgraph);
-        if ((zerlegt[0] == "AutoStart") && (zerlegt.size() > 1))
+        if ((toUpper(zerlegt[0]) == "AUTOSTART") && (zerlegt.size() > 1))
         {
             if (toUpper(zerlegt[1]) == "TRUE")
             {
                 AutoStart = true;
             }
         }
-        if ((zerlegt[0] == "Intervall") && (zerlegt.size() > 1))
+        if ((toUpper(zerlegt[0]) == "INTERVALL") && (zerlegt.size() > 1))
         {
             AutoIntervall = std::stof(zerlegt[1]);
         }
+        if ((toUpper(zerlegt[0]) == "LOGFILE") && (zerlegt.size() > 1))
+        {
+            if (toUpper(zerlegt[1]) == "TRUE")
+            {
+                LogFile.SwitchOnOff(true);
+            }
+            if (toUpper(zerlegt[1]) == "FALSE")
+            {
+                LogFile.SwitchOnOff(false);
+            }
+        }      
     }
     return true;
 }

+ 11 - 1
code/lib/jomjol_flowcontroll/ClassFlowDigit.cpp

@@ -11,6 +11,8 @@
 
 // #include "bitmap_image.hpp"
 
+#include "ClassLogFile.h"
+
 ClassFlowDigit::ClassFlowDigit()
 {
     isLogImage = false;
@@ -119,7 +121,10 @@ string ClassFlowDigit::getHTMLSingleStep(string host)
 
 bool ClassFlowDigit::doFlow(string time)
 {
-    doAlignAndCut(time);
+    if (!doAlignAndCut(time)){
+        return false;
+    };
+
     doNeuralNetwork(time);
 
     return true;
@@ -138,6 +143,11 @@ bool ClassFlowDigit::doAlignAndCut(string time)
     CResizeImage *rs;
     CImageBasis *img_roi = NULL;
     CAlignAndCutImage *caic = new CAlignAndCutImage(input);
+    if (!caic->ImageOkay()){
+        LogFile.WriteToFile("ClassFlowDigit::doAlignAndCut not okay!");
+        delete caic;
+        return false;
+    }
 
     if (input_roi.length() > 0)
         img_roi = new CImageBasis(input_roi);

+ 11 - 1
code/lib/jomjol_logfile/ClassLogFile.cpp

@@ -8,6 +8,10 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, std::string info, bool
     FILE* pFile;
     std::string zwtime;
 
+    if (!doLogFile){
+        return;
+    }
+
     pFile = fopen(_fn.c_str(), "a+");
 
     if (_time)
@@ -30,6 +34,11 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, std::string info, bool
     fclose(pFile);    
 }
 
+void ClassLogFile::SwitchOnOff(bool _doLogFile){
+    doLogFile = _doLogFile;
+};
+
+
 void ClassLogFile::WriteToFile(std::string info, bool _time)
 {
     WriteToDedicatedFile(logfile, info, _time);
@@ -37,5 +46,6 @@ void ClassLogFile::WriteToFile(std::string info, bool _time)
 
 ClassLogFile::ClassLogFile(std::string _logfile)
 {
-    logfile = _logfile;
+    logfile = _logfile; 
+    doLogFile = true;
 }

+ 3 - 0
code/lib/jomjol_logfile/ClassLogFile.h

@@ -6,9 +6,12 @@ class ClassLogFile
 {
 private:
     std::string logfile;
+    bool doLogFile;
 public:
     ClassLogFile(std::string _logfile);
 
+    void SwitchOnOff(bool _doLogFile);
+
     void WriteToFile(std::string info, bool _time = true);
     void WriteToDedicatedFile(std::string _fn, std::string info, bool _time = true);
 };

+ 7 - 7
code/src/main.cpp

@@ -107,31 +107,31 @@ extern "C" void app_main()
 {
     printf("Do Reset Camera\n");
     PowerResetCamera();
-//    LogFile.WriteToFile("Startsequence 01");
     Init_NVS_SDCard();
-    LogFile.WriteToFile("Startsequence 02");
+//    LogFile.WriteToFile("Startsequence 02");
     CheckOTAUpdate();
-    LogFile.WriteToFile("Startsequence 03");
+//    LogFile.WriteToFile("Startsequence 03");
     std::string ssid = "";
     std::string password = "";
     std::string hostname = "";
 
     LoadWlanFromFile("/sdcard/wlan.ini", ssid, password, hostname); 
-    LogFile.WriteToFile("Startsequence 04");    
+//    LogFile.WriteToFile("Startsequence 04");    
     printf("To use WLan: %s, %s\n", ssid.c_str(), password.c_str());
     printf("To set Hostename: %s\n", hostname.c_str());
    
     initialise_wifi(ssid, password, hostname);
-    LogFile.WriteToFile("Startsequence 05");  
+//    LogFile.WriteToFile("Startsequence 05");  
 
     TickType_t xDelay;
     xDelay = 2000 / portTICK_PERIOD_MS;
     printf("Autoflow: sleep for : %ldms\n", (long) xDelay);
-    LogFile.WriteToFile("Startsequence 06");      
+//    LogFile.WriteToFile("Startsequence 06");      
     vTaskDelay( xDelay );   
-    LogFile.WriteToFile("Startsequence 07");  
+//    LogFile.WriteToFile("Startsequence 07");  
     setup_time();
     LogFile.WriteToFile("======================== Main Started ================================");
+    LogFile.SwitchOnOff(false);
 
     std::string zw = gettimestring("%Y%m%d-%H%M%S");
     printf("time %s\n", zw.c_str());    

BIN
firmware/firmware.bin


BIN
firmware/html.zip


BIN
sd-card/config/ana0622.tfl


+ 4 - 0
sd-card/config/config.ini

@@ -11,6 +11,7 @@ InitalRotate=180
 SearchFieldX = 20
 SearchFieldY = 20
 
+
 [Digits]
 Model=/config/dig0640s3.tflite
 LogImageLocation = /log/digit
@@ -42,4 +43,7 @@ CheckDigitIncreaseConsistency = True
 AutoStart= True
 Intervall = 4.85
 
+[Debug]
+Logfile = True
+
 [Ende]

BIN
sd-card/config/dig0622.tfl


BIN
sd-card/config/dig0630s3.tflite


+ 17 - 3
sd-card/html/edit_config.html

@@ -29,12 +29,15 @@ textarea {
     <tr><td><h2>Config.ini:</h2></td></tr>
     <tr>
         <td colspan="3">
-            <textarea id="inputTextToSave" cols="117" rows="38"></textarea>
+            <textarea id="inputTextToSave" cols="100" rows="33"></textarea>
         </td>
     </tr>
     <tr>
-        <td><button class="button" onclick="saveTextAsFile()">Update Config.ini</button></td>		
-    </tr>
+		<td><button class="button" onclick="saveTextAsFile()">Update Config.ini</button></td>
+	</tr>
+	<tr>
+		<td><button class="button" id="reboot" type="button" onclick="doReboot()">Reboot to activate updates</button></td>
+	</tr>
 </table>
 
 <script type="text/javascript" src="./gethost.js"></script> 
@@ -59,6 +62,17 @@ function saveTextAsFile()
 		FileSendContent(textToSave, "/config/config.ini", basepath);
 	}
 }
+
+function doReboot() {
+	if (confirm("Are you sure you want to reboot the ESP32?")) {
+		var stringota = "/reboot";
+		window.location = stringota;
+		window.location.href = stringota;
+		window.location.assign(stringota);
+		window.location.replace(stringota);
+	}
+}
+
  
 LoadConfigNeu();