mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
логирование в процессе
This commit is contained in:
@@ -16,7 +16,8 @@
|
||||
"descr": "График",
|
||||
"int": 60,
|
||||
"logid": "tmp",
|
||||
"num": 1
|
||||
"num": 1,
|
||||
"points": 255
|
||||
},
|
||||
{
|
||||
"name": "2. Таймер",
|
||||
|
||||
@@ -32,7 +32,7 @@ void mqttCallback(char* topic, uint8_t* payload, size_t length);
|
||||
void handleMqttStatus(bool send);
|
||||
void handleMqttStatus(bool send, int state);
|
||||
void sendAllFilesToMQTT();
|
||||
void sendLogData(String file, String topic);
|
||||
void createOneSingleJson(String& json_array, String file);
|
||||
|
||||
const String getStateStr(int e);
|
||||
|
||||
|
||||
@@ -11,3 +11,4 @@ extern void synchTime();
|
||||
extern const String getTimeLocal_hhmm();
|
||||
extern const String getTimeLocal_hhmmss();
|
||||
extern const String getDateTimeDotFormated();
|
||||
extern unsigned long strDateToUnix(String date);
|
||||
|
||||
@@ -70,6 +70,7 @@ void setup() {
|
||||
|
||||
// test
|
||||
Serial.println("-------test start--------");
|
||||
Serial.println(strDateToUnix("25.08.2022"));
|
||||
Serial.println("--------test end---------");
|
||||
|
||||
// симуляция добавления внешних событий
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "MqttClient.h"
|
||||
#include "NTP.h"
|
||||
|
||||
void mqttInit() {
|
||||
mqtt.setCallback(mqttCallback);
|
||||
@@ -316,20 +317,34 @@ void sendAllFilesToMQTT() {
|
||||
String directory = "logs";
|
||||
SerialPrint("I", "Loging", "in directory '" + directory + "' files:");
|
||||
auto dir = FileFS.openDir(directory);
|
||||
String json_array;
|
||||
|
||||
String reqUnixTimeStr = "25.08.2022";
|
||||
unsigned long reqUnixTime = strDateToUnix(reqUnixTimeStr);
|
||||
|
||||
while (dir.next()) {
|
||||
String fname = dir.fileName();
|
||||
String id = selectToMarker(fname, "-");
|
||||
unsigned long fileUnixTime = deleteBeforeDelimiter(deleteToMarkerLast(fname, "."), "-").toInt() + START_DATETIME;
|
||||
|
||||
SerialPrint("I", "Loging", "found file '" + String(fileUnixTime) + "'");
|
||||
|
||||
if (isItemExist(id)) {
|
||||
SerialPrint("I", "Loging", fname);
|
||||
sendLogData("/logs/" + fname, id);
|
||||
//выбираем только те файлы которые входят в выбранные сутки
|
||||
if (fileUnixTime > reqUnixTime && fileUnixTime < reqUnixTime + 86400) {
|
||||
SerialPrint("I", "Loging", "file sent to MQTT: '" + fname + "'");
|
||||
createOneSingleJson(json_array, "/logs/" + fname);
|
||||
}
|
||||
} else {
|
||||
SerialPrint("i", "Loging", "file '" + fname + "' not used, deleted");
|
||||
removeFile(directory + "/" + fname);
|
||||
}
|
||||
}
|
||||
Serial.println("final: ");
|
||||
Serial.println(json_array);
|
||||
}
|
||||
|
||||
void sendLogData(String file, String topic) {
|
||||
void createOneSingleJson(String& json_array, String file) {
|
||||
File configFile = FileFS.open(file, "r");
|
||||
if (!configFile) {
|
||||
return;
|
||||
@@ -337,7 +352,6 @@ void sendLogData(String file, String topic) {
|
||||
configFile.seek(0, SeekSet);
|
||||
int i = 0;
|
||||
String buf = "{}";
|
||||
String json_array;
|
||||
String unix_time;
|
||||
String value;
|
||||
unsigned int psn;
|
||||
@@ -353,13 +367,17 @@ void sendLogData(String file, String topic) {
|
||||
if (unix_time != "" || value != "") {
|
||||
json_array += buf + ",";
|
||||
}
|
||||
|
||||
} while (psn < sz);
|
||||
|
||||
Serial.println(file);
|
||||
Serial.println(json_array);
|
||||
|
||||
configFile.close();
|
||||
|
||||
json_array = "{\"status\":[" + json_array + "]}";
|
||||
json_array.replace("},]}", "}]}");
|
||||
publishChart(topic, json_array);
|
||||
// json_array = "{\"status\":[" + json_array + "]}";
|
||||
// json_array.replace("},]}", "}]}");
|
||||
// publishChart(topic, json_array);
|
||||
}
|
||||
|
||||
const String getStateStr(int e) {
|
||||
|
||||
21
src/NTP.cpp
21
src/NTP.cpp
@@ -116,3 +116,24 @@ const String getDateTimeDotFormated() {
|
||||
sprintf(buf, "%02d.%02d.%02d %02d:%02d:%02d", _time_local.day_of_month, _time_local.month, _time_local.year, _time_local.hour, _time_local.minute, _time_local.second);
|
||||
return String(buf);
|
||||
}
|
||||
|
||||
unsigned long strDateToUnix(String date) {
|
||||
int day = selectToMarker(date, ".").toInt();
|
||||
date = deleteBeforeDelimiter(date, ".");
|
||||
int month = selectToMarker(date, ".").toInt();
|
||||
date = deleteBeforeDelimiter(date, ".");
|
||||
int year = selectToMarker(date, ".").toInt();
|
||||
int secsInOneDay = 86400;
|
||||
int daysInOneYear = 365;
|
||||
int daysInLeepYear = 366;
|
||||
int numberOfLeepYears = 12;
|
||||
int totalNormalYears = year - 1970 - numberOfLeepYears;
|
||||
unsigned int daysInMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
int numberOfDaysInPastMonths = 0;
|
||||
for (int i = 0; i <= 11; i++) {
|
||||
if (i <= month - 2) {
|
||||
numberOfDaysInPastMonths = numberOfDaysInPastMonths + daysInMonth[i];
|
||||
}
|
||||
}
|
||||
return (day * secsInOneDay) + (numberOfDaysInPastMonths * secsInOneDay) + (totalNormalYears * daysInOneYear * secsInOneDay) + (numberOfLeepYears * daysInLeepYear * secsInOneDay);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ void IoTItem::setValue(String valStr) {
|
||||
setValue(value);
|
||||
}
|
||||
|
||||
//непонятный метод к удалению
|
||||
//установить
|
||||
void IoTItem::setValue(IoTValue Value) {
|
||||
value = Value;
|
||||
if (value.isDecimal) {
|
||||
|
||||
@@ -5,16 +5,24 @@ class Loging : public IoTItem {
|
||||
private:
|
||||
String logval;
|
||||
String id;
|
||||
int points;
|
||||
String fileName = "";
|
||||
|
||||
public:
|
||||
Loging(String parameters) : IoTItem(parameters) {
|
||||
jsonRead(parameters, F("logid"), logval);
|
||||
jsonRead(parameters, F("id"), id);
|
||||
jsonRead(parameters, F("points"), points);
|
||||
}
|
||||
|
||||
void setValue(IoTValue Value) {
|
||||
value = Value;
|
||||
regEvent((String)(int)value.valD, "VButton");
|
||||
}
|
||||
|
||||
String getValue() {
|
||||
return "";
|
||||
// return (String)(int)value.valD;
|
||||
}
|
||||
|
||||
void doByInterval() {
|
||||
@@ -26,7 +34,7 @@ class Loging : public IoTItem {
|
||||
} else {
|
||||
//если время было получено из интернета
|
||||
if (isTimeSynch) {
|
||||
regEvent(value, "Loging");
|
||||
// regEvent(value, "Loging");
|
||||
String logData = String(unixTimeShort) + " " + value;
|
||||
|
||||
static bool firstTime = true;
|
||||
|
||||
@@ -11,7 +11,8 @@
|
||||
"descr": "График",
|
||||
"int": 60,
|
||||
"logid": "tmp",
|
||||
"num": 1
|
||||
"num": 1,
|
||||
"points": 255
|
||||
}
|
||||
],
|
||||
"about": {
|
||||
|
||||
Reference in New Issue
Block a user