Debug changed

This commit is contained in:
Dmitry Borisenko
2020-09-17 17:27:44 +03:00
parent fc91a60bab
commit 0a212e0933
30 changed files with 157 additions and 148 deletions

View File

@@ -1,7 +1,7 @@
#include "Utils/FileUtils.h"
#include "Utils/PrintMessage.h"
static const char* MODULE = "FS";
const String filepath(const String& filename) {
return filename.startsWith("/") ? filename : "/" + filename;
@@ -9,7 +9,7 @@ const String filepath(const String& filename) {
bool fileSystemInit() {
if (!LittleFS.begin()) {
pm.error("init");
SerialPrint("[E]","module","init");
return false;
}
return true;
@@ -19,10 +19,10 @@ void removeFile(const String& filename) {
String path = filepath(filename);
if (LittleFS.exists(path)) {
if (!LittleFS.remove(path)) {
pm.error("remove " + path);
SerialPrint("[E]","module","remove " + path);
}
} else {
pm.info("not exist" + path);
SerialPrint("I","module","not exist" + path);
}
}
@@ -30,7 +30,7 @@ File seekFile(const String& filename, size_t position) {
String path = filepath(filename);
auto file = LittleFS.open(path, "r");
if (!file) {
pm.error("open " + path);
SerialPrint("[E]","module","open " + path);
}
// поставим курсор в начало файла
file.seek(position, SeekSet);
@@ -76,14 +76,14 @@ const String addFile(const String& filename, const String& str) {
bool copyFile(const String& src, const String& dst, bool overwrite) {
String srcPath = filepath(src);
String dstPath = filepath(dst);
pm.info("copy " + srcPath + " to " + dstPath);
SerialPrint("I","module","copy " + srcPath + " to " + dstPath);
if (!LittleFS.exists(srcPath)) {
pm.error("not exist: " + srcPath);
SerialPrint("[E]","module","not exist: " + srcPath);
return false;
}
if (LittleFS.exists(dstPath)) {
if (!overwrite) {
pm.error("already exist: " + dstPath);
SerialPrint("[E]","module","already exist: " + dstPath);
return false;
}
LittleFS.remove(dstPath);

View File

@@ -0,0 +1,8 @@
#include "Utils\SerialPrint.h"
#include "Global.h"
void SerialPrint(String errorLevel, String module, String msg) {
Serial.println(prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg);
}

View File

@@ -3,7 +3,6 @@
#include "Global.h"
#include "Utils/PrintMessage.h"
static const char* MODULE = "Main";
const String getUniqueId(const char* name) {
return String(name) + getMacAddress();
@@ -25,7 +24,7 @@ const String getChipId() {
void setChipId() {
chipId = getChipId();
pm.info("id: " + chipId);
SerialPrint("I","module","id: " + chipId);
}
#ifdef ESP8266

View File

@@ -1,10 +1,10 @@
#include "Utils/WiFiUtils.h"
static const char* MODULE = "WiFi";
void startSTAMode() {
setLedStatus(LED_SLOW);
pm.info("STA Mode");
SerialPrint("I","module","STA Mode");
String ssid = jsonReadStr(configSetupJson, "routerssid");
String passwd = jsonReadStr(configSetupJson, "routerpass");
@@ -14,7 +14,7 @@ void startSTAMode() {
WiFi.begin();
} else {
if (WiFi.begin(ssid.c_str(), passwd.c_str()) == WL_CONNECT_FAILED) {
pm.error("failed on start");
SerialPrint("[E]","module","failed on start");
}
}
@@ -29,17 +29,17 @@ void startSTAMode() {
#endif
switch (connRes) {
case WL_NO_SSID_AVAIL: {
pm.error("no network");
SerialPrint("[E]","module","no network");
keepConnecting = false;
} break;
case WL_CONNECTED: {
String hostIpStr = WiFi.localIP().toString();
pm.info("http://" + hostIpStr);
SerialPrint("I","module","http://" + hostIpStr);
jsonWriteStr(configSetupJson, "ip", hostIpStr);
keepConnecting = false;
} break;
case WL_CONNECT_FAILED: {
pm.error("check credentials");
SerialPrint("[E]","module","check credentials");
jsonWriteInt(configOptionJson, "pass_status", 1);
keepConnecting = false;
} break;
@@ -52,14 +52,14 @@ void startSTAMode() {
MqttClient::init();
setLedStatus(LED_OFF);
} else {
pm.error("failed: " + String(connRes, DEC));
SerialPrint("[E]","module","failed: " + String(connRes, DEC));
startAPMode();
};
}
bool startAPMode() {
setLedStatus(LED_ON);
pm.info("AP Mode");
SerialPrint("I","module","AP Mode");
String ssid = jsonReadStr(configSetupJson, "apssid");
String passwd = jsonReadStr(configSetupJson, "appass");
@@ -68,14 +68,14 @@ bool startAPMode() {
WiFi.softAP(ssid.c_str(), passwd.c_str());
String hostIpStr = WiFi.softAPIP().toString();
pm.info("Host IP: " + hostIpStr);
SerialPrint("I","module","Host IP: " + hostIpStr);
jsonWriteStr(configSetupJson, "ip", hostIpStr);
ts.add(
WIFI_SCAN, 10 * 1000,
[&](void*) {
String sta_ssid = jsonReadStr(configSetupJson, "routerssid");
pm.info("scanning for " + sta_ssid);
SerialPrint("I","module","scanning for " + sta_ssid);
if (scanWiFi(sta_ssid)) {
ts.remove(WIFI_SCAN);
startSTAMode();
@@ -89,25 +89,25 @@ bool startAPMode() {
boolean scanWiFi(String ssid) {
bool res = false;
int8_t n = WiFi.scanComplete();
pm.info("scan result: " + String(n, DEC));
SerialPrint("I","module","scan result: " + String(n, DEC));
if (n == -2) {
// не было запущено, запускаем
pm.info("start scanning");
SerialPrint("I","module","start scanning");
// async, show_hidden
WiFi.scanNetworks(true, false);
} else if (n == -1) {
// все еще выполняется
pm.info("scanning in progress");
SerialPrint("I","module","scanning in progress");
} else if (n == 0) {
// не найдена ни одна сеть
pm.info("no networks found");
SerialPrint("I","module","no networks found");
WiFi.scanNetworks(true, false);
} else if (n > 0) {
for (int8_t i = 0; i < n; i++) {
if (WiFi.SSID(i) == ssid) {
res = true;
}
pm.info((res ? "*" : "") + String(i, DEC) + ") " + WiFi.SSID(i));
SerialPrint("I","module",(res ? "*" : "") + String(i, DEC) + ") " + WiFi.SSID(i));
}
}
return res;

View File

@@ -6,9 +6,9 @@
#include "Global.h"
#include "ItemsList.h"
void initSt() {
Serial.print("[I] [Stat] New device registation: ");
Serial.println(addNewDevice());
addNewDevice();
decide();
if (TELEMETRY_UPDATE_INTERVAL_MIN) {
ts.add(
@@ -16,9 +16,7 @@ void initSt() {
static bool secondTime = false;
if (secondTime) plusOneHour();
secondTime = true;
Serial.print("[I] [Stat] Update device status: ");
Serial.println(updateDeviceStatus());
updateDeviceStatus();
},
nullptr, true);
}
@@ -27,17 +25,17 @@ void initSt() {
void decide() {
if ((WiFi.status() == WL_CONNECTED)) {
uint8_t cnt = getNewElementNumber("stat.txt");
Serial.print("[I] [Stat] Total reset number: ");
Serial.print(cnt);
Serial.print(" ");
SerialPrint("I","module","Total reset number: " + String(cnt));
//Serial.print(cnt);
//Serial.print(" ");
if (cnt <= 3) {
Serial.println("(get)");
//Serial.println("(get)");
getPsn();
} else {
if (cnt % 5) {
Serial.println("(skip)");
//Serial.println("(skip)");
} else {
Serial.println("(get)");
//Serial.println("(get)");
getPsn();
}
}
@@ -53,8 +51,7 @@ void getPsn() {
//String city = jsonReadStr(res, "city");
//String country = jsonReadStr(res, "country");
//String region = jsonReadStr(res, "region");
Serial.print("[I] [Stat] Update device psn: ");
Serial.println(updateDevicePsn(lat, lon, "1000"));
updateDevicePsn(lat, lon, "1000");
}
}
@@ -86,6 +83,7 @@ String addNewDevice() {
}
http.end();
}
SerialPrint("I","module","New device registaration: " + ret);
return ret;
}
@@ -114,6 +112,7 @@ String updateDevicePsn(String lat, String lon, String accur) {
}
http.end();
}
SerialPrint("I","module","Update device psn: " + ret);
return ret;
}
@@ -142,6 +141,7 @@ String updateDeviceStatus() {
}
http.end();
}
SerialPrint("I","module","Update device data: " + ret);
return ret;
}
@@ -149,8 +149,9 @@ String getUptimeTotal() {
static int hrs;
EEPROM.begin(512);
hrs = eeGetInt(0);
SerialPrint("I","module","Total running hrs: " + String(hrs));
String hrsStr = prettySeconds(hrs * 60 * 60);
//Serial.println(hrsStr);
SerialPrint("I","module","Total running hrs (f): " + hrsStr);
return hrsStr;
}