mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-07 12:06:58 +03:00
show uptime on overview page, moved labels from firmware to Web UI (#1543)
* show uptime on overview page, moved labels from firmware to Web UI * show uptime on info page * also use formated time in log Co-authored-by: CaCO3 <caco@ruinelli.ch>
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <math.h>
|
||||
|
||||
#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
|
||||
"<pre>\n\n\n\n"
|
||||
|
||||
@@ -64,5 +64,6 @@ string getSDCardSectorSize();
|
||||
|
||||
string getMac(void);
|
||||
string getResetReason(void);
|
||||
std::string getFormatedUptime(bool compact);
|
||||
|
||||
const char* get404(void);
|
||||
|
||||
@@ -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;
|
||||
@@ -164,10 +164,10 @@ void ClassLogFile::WriteToDedicatedFile(std::string _fn, esp_log_level_t level,
|
||||
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());
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -37,6 +37,16 @@ div {
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
Uptime:
|
||||
</td>
|
||||
<td>
|
||||
<div id="uptime">
|
||||
<object data="/uptime"></object>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h3>Build Info</h3>
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th class="th">Error:</th>
|
||||
<th class="th">Status:</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="tg-2">
|
||||
@@ -59,6 +59,7 @@
|
||||
<div id="statusflow" ></div>
|
||||
<div id="cputemp" ></div>
|
||||
<div id="rssi" ></div>
|
||||
<div id="uptime" ></div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -87,6 +88,7 @@ function addZero(i) {
|
||||
loadStatus();
|
||||
loadCPUTemp();
|
||||
loadRSSI();
|
||||
loadUptime();
|
||||
refresh();
|
||||
});
|
||||
|
||||
@@ -117,7 +119,7 @@ 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);
|
||||
@@ -130,7 +132,7 @@ 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);
|
||||
@@ -143,7 +145,20 @@ 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);
|
||||
@@ -199,6 +214,7 @@ function refresh() {
|
||||
loadStatus();
|
||||
loadCPUTemp();
|
||||
loadRSSI();
|
||||
loadUptime();
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
Reference in New Issue
Block a user