diff --git a/code/components/jomjol_helper/Helper.cpp b/code/components/jomjol_helper/Helper.cpp index f5af0125..c35642ed 100644 --- a/code/components/jomjol_helper/Helper.cpp +++ b/code/components/jomjol_helper/Helper.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -792,6 +793,30 @@ string getResetReason(void) { return reasonText; } +/** + * Returns the current uptime formated ad xxf xxh xxm [xxs] + */ +std::string getFormatedUptime(bool compact) { + char buf[20]; + #pragma GCC diagnostic ignored "-Wformat-truncation" + + int uptime = (uint32_t)(esp_timer_get_time()/1000/1000); // in seconds + + int days = int(floor(uptime / (3600*24))); + int hours = int(floor((uptime - days * 3600*24) / (3600))); + int minutes = int(floor((uptime - days * 3600*24 - hours * 3600) / (60))); + int seconds = uptime - days * 3600*24 - hours * 3600 - minutes * 60; + + if (compact) { + snprintf(buf, sizeof(buf), "%dd%02dh%02dm%02ds", days, hours, minutes, seconds); + } + else { + snprintf(buf, sizeof(buf), "%3dd %02dh %02dm %02ds", days, hours, minutes, seconds); + } + + return std::string(buf); +} + const char* get404(void) { return "
\n\n\n\n"
diff --git a/code/components/jomjol_helper/Helper.h b/code/components/jomjol_helper/Helper.h
index fd8ddf3d..2f2cb05f 100644
--- a/code/components/jomjol_helper/Helper.h
+++ b/code/components/jomjol_helper/Helper.h
@@ -64,5 +64,6 @@ string getSDCardSectorSize();
 
 string getMac(void);
 string getResetReason(void);
+std::string getFormatedUptime(bool compact);
 
 const char* get404(void);
diff --git a/code/components/jomjol_logfile/ClassLogFile.cpp b/code/components/jomjol_logfile/ClassLogFile.cpp
index d0220559..99b5fc3b 100644
--- a/code/components/jomjol_logfile/ClassLogFile.cpp
+++ b/code/components/jomjol_logfile/ClassLogFile.cpp
@@ -115,7 +115,7 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level,
 {
     FILE* pFile;
     std::string zwtime;
-    std::string logline = "";
+    std::string ntpTime = "";
 
     if (level > loglevel) {// Only write to file if loglevel is below threshold
         return;
@@ -138,7 +138,7 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level,
             strftime(buffer, 80, "%Y-%m-%dT%H:%M:%S", timeinfo);
 
             zwtime = std::string(buffer);
-            logline = zwtime;
+            ntpTime = zwtime;
         }
 
         std::string loglevelString; 
@@ -163,11 +163,11 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level,
                 loglevelString = "NONE";
                 break;
         }
-        
-        char uptime[20];
-        snprintf(uptime, sizeof(uptime), "%8d", (uint32_t)(esp_timer_get_time()/1000/1000)); // in seconds
-        logline = "[" + std::string(uptime) + "] "  + logline + "\t<" + loglevelString + ">\t" + message + "\n";
-        fputs(logline.c_str(), pFile);
+
+        std::string formatedUptime = getFormatedUptime(true);
+
+        ntpTime = "[" + formatedUptime + "] "  + ntpTime + "\t<" + loglevelString + ">\t" + message + "\n";
+        fputs(ntpTime.c_str(), pFile);
         fclose(pFile);    
     } else {
         ESP_LOGE(TAG, "Can't open log file %s", _fn.c_str());
diff --git a/code/components/jomjol_tfliteclass/server_tflite.cpp b/code/components/jomjol_tfliteclass/server_tflite.cpp
index e46a0db9..df17f049 100644
--- a/code/components/jomjol_tfliteclass/server_tflite.cpp
+++ b/code/components/jomjol_tfliteclass/server_tflite.cpp
@@ -614,7 +614,7 @@ esp_err_t handler_cputemp(httpd_req_t *req)
     const char* resp_str;
     char cputemp[20];
     
-    sprintf(cputemp, "CPU Temp: %4.1f°C", temperatureRead());
+    sprintf(cputemp, "%4.1f°C", temperatureRead());
 
     resp_str = cputemp;
 
@@ -639,7 +639,7 @@ esp_err_t handler_rssi(httpd_req_t *req)
     const char* resp_str;
     char rssi[20];
 
-    sprintf(rssi, "RSSI: %idBm", get_WIFI_RSSI());
+    sprintf(rssi, "%idBm", get_WIFI_RSSI());
 
     resp_str = rssi;
 
@@ -655,6 +655,34 @@ esp_err_t handler_rssi(httpd_req_t *req)
     return ESP_OK;
 };
 
+
+esp_err_t handler_uptime(httpd_req_t *req)
+{
+
+#ifdef DEBUG_DETAIL_ON       
+    LogFile.WriteHeapInfo("handler_uptime - Start");       
+#endif
+
+    const char* resp_str;
+    
+    std::string formatedUptime = getFormatedUptime(false);
+
+    httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*");
+    httpd_resp_send(req, formatedUptime.c_str(), strlen(formatedUptime.c_str()));   
+    /* Respond with an empty chunk to signal HTTP response completion */
+    httpd_resp_send_chunk(req, NULL, 0);      
+
+#ifdef DEBUG_DETAIL_ON       
+    LogFile.WriteHeapInfo("handler_uptime - End");       
+#endif
+
+    return ESP_OK;
+}
+
+
+
+
+
 esp_err_t handler_prevalue(httpd_req_t *req)
 {
 #ifdef DEBUG_DETAIL_ON       
@@ -721,6 +749,7 @@ void task_autodoFlow(void *pvParameter)
         LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Restarted due to an Exception/panic! Postponing first round start by 5 minutes to allow for an OTA or to fetch the log!"); 
         LogFile.WriteToFile(ESP_LOG_WARN, TAG, "Setting logfile level to DEBUG until the next reboot!");
         LogFile.setLogLevel(ESP_LOG_DEBUG);
+        //MQTTPublish(GetMQTTMainTopic() + "/" + "status", "Postponing first round", false);
         vTaskDelay(60*5000 / portTICK_RATE_MS); // Wait 5 minutes to give time to do an OTA or fetch the log
     }
 
@@ -873,6 +902,11 @@ void register_server_tflite_uri(httpd_handle_t server)
     camuri.user_ctx  = (void*) "Light Off";
     httpd_register_uri_handler(server, &camuri);
 
+    camuri.uri       = "/uptime";
+    camuri.handler   = handler_uptime;
+    camuri.user_ctx  = (void*) "Light Off";
+    httpd_register_uri_handler(server, &camuri);
+
     camuri.uri       = "/editflow";
     camuri.handler   = handler_editflow;
     camuri.user_ctx  = (void*) "EditFlow"; 
diff --git a/sd-card/html/info.html b/sd-card/html/info.html
index 257abb8e..1592d3e9 100644
--- a/sd-card/html/info.html
+++ b/sd-card/html/info.html
@@ -37,6 +37,16 @@ div {
 			
 		
 	
+	
+		
+			Uptime:
+		
+		
+			
+ +
+ +

Build Info

diff --git a/sd-card/html/overview.html b/sd-card/html/overview.html index 7b834f2c..f382410b 100644 --- a/sd-card/html/overview.html +++ b/sd-card/html/overview.html @@ -46,7 +46,7 @@ - Error: + Status: @@ -59,6 +59,7 @@
+
@@ -87,6 +88,7 @@ function addZero(i) { loadStatus(); loadCPUTemp(); loadRSSI(); + loadUptime(); refresh(); }); @@ -117,11 +119,11 @@ function refresh() { if (this.readyState == 4 && this.status == 200) { var _rsp = xhttp.responseText; _rsp = "Status: " + _rsp; - $('#statusflow').html(_rsp); + $('#statusflow').html("Status: " + _rsp); } } xhttp.open("GET", url, true); - xhttp.send(); + xhttp.send(); } function loadCPUTemp() { @@ -130,11 +132,11 @@ function refresh() { xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var _rsp = xhttp.responseText; - $('#cputemp').html(_rsp); + $('#cputemp').html("CPU Temperature: " +_rsp); } } xhttp.open("GET", url, true); - xhttp.send(); + xhttp.send(); } function loadRSSI() { @@ -143,12 +145,25 @@ function refresh() { xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var _rsp = xhttp.responseText; - $('#rssi').html(_rsp); + $('#rssi').html("RSSI: " + _rsp); } } xhttp.open("GET", url, true); xhttp.send(); } + + function loadUptime() { + url = basepath + '/uptime'; + var xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + var _rsp = xhttp.responseText; + $('#uptime').html("Uptime: " + _rsp); + } + } + xhttp.open("GET", url, true); + xhttp.send(); + } function loadValue(_type, _div, _style) { url = basepath + '/value?all=true&type=' + _type; @@ -199,6 +214,7 @@ function refresh() { loadStatus(); loadCPUTemp(); loadRSSI(); + loadUptime(); } init();