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