last version

This commit is contained in:
Dmitry Borisenko
2020-09-17 18:32:39 +03:00
parent 8568e945a4
commit d6f5506812
4 changed files with 65 additions and 41 deletions

View File

@@ -3,7 +3,7 @@
#include "Global.h"
void SerialPrint(String errorLevel, String module, String msg) {
//if (module == "Stat") {
if (module == "Stat") {
Serial.println(prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg);
//}
}
}

View File

@@ -14,7 +14,7 @@ void initSt() {
ts.add(
STATISTICS, TELEMETRY_UPDATE_INTERVAL_MIN * 60000, [&](void*) {
static bool secondTime = false;
if (secondTime) plusOneHour();
if (secondTime) getNextNumber("totalhrs.txt");
secondTime = true;
updateDeviceStatus();
},
@@ -24,7 +24,7 @@ void initSt() {
void decide() {
if ((WiFi.status() == WL_CONNECTED)) {
uint8_t cnt = getNewElementNumber("stat.txt");
uint8_t cnt = getNextNumber("stat.txt");
SerialPrint("I","Stat","Total resets number: " + String(cnt));
if (cnt <= 3) {
//Serial.println("(get)");
@@ -127,7 +127,8 @@ String updateDeviceStatus() {
"&resetReason=" + ESP.getResetReason() +
"&uptime=" + timeNow->getUptime() +
"&uptimeTotal=" + getUptimeTotal() +
"&version=" + FIRMWARE_VERSION + "");
"&version=" + FIRMWARE_VERSION +
"&resetsTotal=" + String(getCurrentNumber("stat.txt")) + "");
if (httpCode > 0) {
ret = httpCode;
if (httpCode == HTTP_CODE_OK) {
@@ -144,46 +145,66 @@ String updateDeviceStatus() {
}
String getUptimeTotal() {
static int hrs;
EEPROM.begin(512);
hrs = eeGetInt(0);
SerialPrint("I","Stat","Total running hrs: " + String(hrs));
uint8_t hrs = getCurrentNumber("totalhrs.txt");
String hrsStr = prettySeconds(hrs * 60 * 60);
SerialPrint("I","Stat","Total running hrs (f): " + hrsStr);
SerialPrint("I","Stat","Total running time: " + hrsStr);
return hrsStr;
}
int plusOneHour() {
static int hrs;
EEPROM.begin(512);
hrs = eeGetInt(0);
hrs++;
eeWriteInt(0, hrs);
return hrs;
uint8_t getNextNumber(String file) {
uint8_t number = readFile(file, 100).toInt();
number++;
removeFile(file);
addFile(file, String(number));
return number;
}
void eeWriteInt(int pos, int val) {
byte* p = (byte*)&val;
EEPROM.write(pos, *p);
EEPROM.write(pos + 1, *(p + 1));
EEPROM.write(pos + 2, *(p + 2));
EEPROM.write(pos + 3, *(p + 3));
EEPROM.commit();
uint8_t getCurrentNumber(String file) {
uint8_t number = readFile(file, 100).toInt();
return number;
}
int eeGetInt(int pos) {
int val;
byte* p = (byte*)&val;
*p = EEPROM.read(pos);
*(p + 1) = EEPROM.read(pos + 1);
*(p + 2) = EEPROM.read(pos + 2);
*(p + 3) = EEPROM.read(pos + 3);
if (val < 0) {
return 0;
} else {
return val;
}
}
//String getUptimeTotal() {
// static int hrs;
// EEPROM.begin(512);
// hrs = eeGetInt(0);
// SerialPrint("I","Stat","Total running hrs: " + String(hrs));
// String hrsStr = prettySeconds(hrs * 60 * 60);
// SerialPrint("I","Stat","Total running hrs (f): " + hrsStr);
// return hrsStr;
//}
//int plusOneHour() {
// static int hrs;
// EEPROM.begin(512);
// hrs = eeGetInt(0);
// hrs++;
// eeWriteInt(0, hrs);
// return hrs;
//}
//
//void eeWriteInt(int pos, int val) {
// byte* p = (byte*)&val;
// EEPROM.write(pos, *p);
// EEPROM.write(pos + 1, *(p + 1));
// EEPROM.write(pos + 2, *(p + 2));
// EEPROM.write(pos + 3, *(p + 3));
// EEPROM.commit();
//}
//
//int eeGetInt(int pos) {
// int val;
// byte* p = (byte*)&val;
// *p = EEPROM.read(pos);
// *(p + 1) = EEPROM.read(pos + 1);
// *(p + 2) = EEPROM.read(pos + 2);
// *(p + 3) = EEPROM.read(pos + 3);
// if (val < 0) {
// return 0;
// } else {
// return val;
// }
//}
//========for updating list of device=================
/*
void updateDeviceList() {

View File

@@ -85,7 +85,7 @@ void setup() {
ts.add(
TEST, 1000 * 60, [&](void*) {
SerialPrint("I","module",printMemoryStatus());
SerialPrint("I","System",printMemoryStatus());
},
nullptr, true);