mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
запись в файл данных для графика
This commit is contained in:
@@ -129,6 +129,8 @@ struct Time_t {
|
||||
unsigned long valid;
|
||||
};
|
||||
|
||||
extern unsigned long unixTime;
|
||||
extern bool isTimeSynch;
|
||||
extern Time_t _time_local;
|
||||
extern Time_t _time_utc;
|
||||
extern bool _time_isTrust;
|
||||
|
||||
@@ -6,8 +6,8 @@ extern void writeFileUint8tByFrames(const String& filename, uint8_t*& big_buf, s
|
||||
extern void writeFileUint8tByByte(const String& filename, uint8_t*& payload, size_t length, size_t headerLenth);
|
||||
extern File seekFile(const String& filename, size_t position = 0);
|
||||
extern const String writeFile(const String& filename, const String& str);
|
||||
extern const String addFileLn(const String& filename, const String& str);
|
||||
extern const String readFile(const String& filename, size_t max_size);
|
||||
extern const String filepath(const String& filename);
|
||||
extern bool cutFile(const String& src, const String& dst);
|
||||
extern const String addFileLn(const String& filename, const String& str);
|
||||
extern void onFlashWrite();
|
||||
@@ -65,6 +65,8 @@ String scenario = "";
|
||||
String mqttRootDevice = "";
|
||||
|
||||
// Time
|
||||
unsigned long unixTime = 0;
|
||||
bool isTimeSynch = false;
|
||||
Time_t _time_local;
|
||||
Time_t _time_utc;
|
||||
bool _time_isTrust = false;
|
||||
|
||||
@@ -8,14 +8,16 @@ void ntpInit() {
|
||||
|
||||
ts.add(
|
||||
TIME, 1000, [&](void*) {
|
||||
unsigned long unixTime = getSystemTime();
|
||||
unixTime = getSystemTime();
|
||||
if (unixTime < MIN_DATETIME) {
|
||||
isTimeSynch = false;
|
||||
// SerialPrint("E", "NTP", "Time not synched");
|
||||
synchTime();
|
||||
return;
|
||||
}
|
||||
breakEpochToTime(unixTime + jsonReadInt(settingsFlashJson, F("timezone")) * 60 * 60, _time_local);
|
||||
breakEpochToTime(unixTime, _time_utc);
|
||||
isTimeSynch = true;
|
||||
String timenow = getTimeLocal_hhmm();
|
||||
static String prevTime;
|
||||
if (prevTime != timenow) {
|
||||
@@ -25,7 +27,7 @@ void ntpInit() {
|
||||
jsonWriteStr_(errorsHeapJson, F("timenow"), dateAndTime);
|
||||
SerialPrint("I", F("NTP"), "✔ " + dateAndTime);
|
||||
}
|
||||
_time_isTrust = true; // доверяем значению времени
|
||||
_time_isTrust = true; // доверяем значению времени
|
||||
},
|
||||
nullptr, true);
|
||||
|
||||
|
||||
@@ -20,9 +20,13 @@ class Loging : public IoTItem {
|
||||
if (value == "") {
|
||||
SerialPrint("E", F("Logging"), F("no value set"));
|
||||
} else {
|
||||
regEvent(value, "Logging");
|
||||
String logData = String(_time_local.second) + " " + value + "\r\n";
|
||||
writeFile("log.txt", logData);
|
||||
if (isTimeSynch) {
|
||||
regEvent(value, "Logging");
|
||||
String logData = String(unixTime) + " " + value + "\r\n";
|
||||
addFileLn("/log.txt", logData);
|
||||
} else {
|
||||
SerialPrint("E", F("Logging"), F("cant logging - no time Synch"));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -101,6 +101,18 @@ const String writeFile(const String& filename, const String& str) {
|
||||
onFlashWrite();
|
||||
}
|
||||
|
||||
const String addFileLn(const String& filename, const String& str) {
|
||||
String path = filepath(filename);
|
||||
auto file = FileFS.open(path, "a");
|
||||
if (!file) {
|
||||
return "failed";
|
||||
}
|
||||
file.println(str);
|
||||
file.close();
|
||||
return "sucсess";
|
||||
onFlashWrite();
|
||||
}
|
||||
|
||||
const String readFile(const String& filename, size_t max_size) {
|
||||
String path = filepath(filename);
|
||||
auto file = FileFS.open(path, "r");
|
||||
@@ -146,17 +158,7 @@ bool cutFile(const String& src, const String& dst) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const String addFileLn(const String& filename, const String& str) {
|
||||
String path = filepath(filename);
|
||||
auto file = FileFS.open(path, "a");
|
||||
if (!file) {
|
||||
return "failed";
|
||||
}
|
||||
file.println(str);
|
||||
file.close();
|
||||
onFlashWrite();
|
||||
return "sucсess";
|
||||
}
|
||||
|
||||
|
||||
void onFlashWrite() {
|
||||
flashWriteNumber++;
|
||||
|
||||
Reference in New Issue
Block a user