mirror of
https://github.com/jomjol/AI-on-the-edge-device.git
synced 2025-12-08 12:36:52 +03:00
Logfile: Print start indication block after time sync (#2106)
* logfile: Print start indication after time sync * No time set at boot -> keep log_1970-01-01.txt
This commit is contained in:
@@ -15,6 +15,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "Helper.h"
|
#include "Helper.h"
|
||||||
|
#include "time_sntp.h"
|
||||||
#include "../../include/defines.h"
|
#include "../../include/defines.h"
|
||||||
|
|
||||||
static const char *TAG = "LOGFILE";
|
static const char *TAG = "LOGFILE";
|
||||||
@@ -322,14 +323,22 @@ void ClassLogFile::RemoveOldLogFile()
|
|||||||
if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) {
|
if ((strlen(entry->d_name) == strlen(cmpfilename)) && (strcmp(entry->d_name, cmpfilename) < 0)) {
|
||||||
//ESP_LOGD(TAG, "delete log file: %s", entry->d_name);
|
//ESP_LOGD(TAG, "delete log file: %s", entry->d_name);
|
||||||
std::string filepath = logroot + "/" + entry->d_name;
|
std::string filepath = logroot + "/" + entry->d_name;
|
||||||
if (unlink(filepath.c_str()) == 0) {
|
if ((strcmp(entry->d_name, "log_1970-01-01.txt") == 0) && getTimeWasNotSetAtBoot()) { // keep logfile log_1970-01-01.txt if time was not set at boot (some boot logs are in there)
|
||||||
deleted ++;
|
//ESP_LOGD(TAG, "Skip deleting this file: %s", entry->d_name);
|
||||||
} else {
|
notDeleted++;
|
||||||
ESP_LOGE(TAG, "can't delete file: %s", entry->d_name);
|
|
||||||
notDeleted ++;
|
|
||||||
}
|
}
|
||||||
} else {
|
else {
|
||||||
notDeleted ++;
|
if (unlink(filepath.c_str()) == 0) {
|
||||||
|
deleted++;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ESP_LOGE(TAG, "can't delete file: %s", entry->d_name);
|
||||||
|
notDeleted++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
notDeleted++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ static const char *TAG = "SNTP";
|
|||||||
static std::string timeZone = "";
|
static std::string timeZone = "";
|
||||||
static std::string timeServer = "undefined";
|
static std::string timeServer = "undefined";
|
||||||
static bool useNtp = true;
|
static bool useNtp = true;
|
||||||
|
static bool timeWasNotSetAtBoot = false;
|
||||||
|
|
||||||
std::string getNtpStatusText(sntp_sync_status_t status);
|
std::string getNtpStatusText(sntp_sync_status_t status);
|
||||||
static void setTimeZone(std::string _tzstring);
|
static void setTimeZone(std::string _tzstring);
|
||||||
@@ -59,7 +60,12 @@ std::string getCurrentTimeString(const char * frm)
|
|||||||
|
|
||||||
void time_sync_notification_cb(struct timeval *tv)
|
void time_sync_notification_cb(struct timeval *tv)
|
||||||
{
|
{
|
||||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Time is now successfully synced with NTP Server " +
|
if (timeWasNotSetAtBoot) {
|
||||||
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "=================================================");
|
||||||
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "==================== Start ======================");
|
||||||
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "== Logs before time sync -> log_1970-01-01.txt ==");
|
||||||
|
}
|
||||||
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Time is synced with NTP Server " +
|
||||||
getServerName() + ": " + getCurrentTimeString("%Y-%m-%d %H:%M:%S"));
|
getServerName() + ": " + getCurrentTimeString("%Y-%m-%d %H:%M:%S"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,6 +117,11 @@ bool getUseNtp(void) {
|
|||||||
return useNtp;
|
return useNtp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool getTimeWasNotSetAtBoot(void)
|
||||||
|
{
|
||||||
|
return timeWasNotSetAtBoot;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string getServerName(void) {
|
std::string getServerName(void) {
|
||||||
char buf[100];
|
char buf[100];
|
||||||
@@ -225,6 +236,7 @@ bool setupTime() {
|
|||||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "The local time is unknown, starting with " + std::string(strftime_buf));
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "The local time is unknown, starting with " + std::string(strftime_buf));
|
||||||
if (useNtp) {
|
if (useNtp) {
|
||||||
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Once the NTP server provides a time, we will switch to that one");
|
LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Once the NTP server provides a time, we will switch to that one");
|
||||||
|
timeWasNotSetAtBoot = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ std::string ConvertTimeToString(time_t _time, const char * frm);
|
|||||||
|
|
||||||
|
|
||||||
bool getTimeIsSet(void);
|
bool getTimeIsSet(void);
|
||||||
|
bool getTimeWasNotSetAtBoot(void);
|
||||||
|
|
||||||
bool getUseNtp(void);
|
bool getUseNtp(void);
|
||||||
bool setupTime();
|
bool setupTime();
|
||||||
|
|||||||
Reference in New Issue
Block a user