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