mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 22:52:19 +03:00
modules
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
|
||||
#include "Global.h"
|
||||
|
||||
|
||||
void SerialPrint(String errorLevel, String module, String msg) {
|
||||
Serial.println(prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg);
|
||||
//if (module == "Stat") {
|
||||
Serial.println(prettyMillis(millis()) + " [" + errorLevel + "] [" + module + "] " + msg);
|
||||
//}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
void startSTAMode() {
|
||||
setLedStatus(LED_SLOW);
|
||||
SerialPrint("I","module","STA Mode");
|
||||
SerialPrint("I","WIFI","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) {
|
||||
SerialPrint("[E]","module","failed on start");
|
||||
SerialPrint("[E]","WIFI","failed on start");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,17 +29,17 @@ void startSTAMode() {
|
||||
#endif
|
||||
switch (connRes) {
|
||||
case WL_NO_SSID_AVAIL: {
|
||||
SerialPrint("[E]","module","no network");
|
||||
SerialPrint("[E]","WIFI","no network");
|
||||
keepConnecting = false;
|
||||
} break;
|
||||
case WL_CONNECTED: {
|
||||
String hostIpStr = WiFi.localIP().toString();
|
||||
SerialPrint("I","module","http://" + hostIpStr);
|
||||
SerialPrint("I","WIFI","http://" + hostIpStr);
|
||||
jsonWriteStr(configSetupJson, "ip", hostIpStr);
|
||||
keepConnecting = false;
|
||||
} break;
|
||||
case WL_CONNECT_FAILED: {
|
||||
SerialPrint("[E]","module","check credentials");
|
||||
SerialPrint("[E]","WIFI","check credentials");
|
||||
jsonWriteInt(configOptionJson, "pass_status", 1);
|
||||
keepConnecting = false;
|
||||
} break;
|
||||
@@ -52,14 +52,14 @@ void startSTAMode() {
|
||||
MqttClient::init();
|
||||
setLedStatus(LED_OFF);
|
||||
} else {
|
||||
SerialPrint("[E]","module","failed: " + String(connRes, DEC));
|
||||
SerialPrint("[E]","WIFI","failed: " + String(connRes, DEC));
|
||||
startAPMode();
|
||||
};
|
||||
}
|
||||
|
||||
bool startAPMode() {
|
||||
setLedStatus(LED_ON);
|
||||
SerialPrint("I","module","AP Mode");
|
||||
SerialPrint("I","WIFI","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();
|
||||
SerialPrint("I","module","Host IP: " + hostIpStr);
|
||||
SerialPrint("I","WIFI","Host IP: " + hostIpStr);
|
||||
jsonWriteStr(configSetupJson, "ip", hostIpStr);
|
||||
|
||||
ts.add(
|
||||
WIFI_SCAN, 10 * 1000,
|
||||
[&](void*) {
|
||||
String sta_ssid = jsonReadStr(configSetupJson, "routerssid");
|
||||
SerialPrint("I","module","scanning for " + sta_ssid);
|
||||
SerialPrint("I","WIFI","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();
|
||||
SerialPrint("I","module","scan result: " + String(n, DEC));
|
||||
SerialPrint("I","WIFI","scan result: " + String(n, DEC));
|
||||
if (n == -2) {
|
||||
// не было запущено, запускаем
|
||||
SerialPrint("I","module","start scanning");
|
||||
SerialPrint("I","WIFI","start scanning");
|
||||
// async, show_hidden
|
||||
WiFi.scanNetworks(true, false);
|
||||
} else if (n == -1) {
|
||||
// все еще выполняется
|
||||
SerialPrint("I","module","scanning in progress");
|
||||
SerialPrint("I","WIFI","scanning in progress");
|
||||
} else if (n == 0) {
|
||||
// не найдена ни одна сеть
|
||||
SerialPrint("I","module","no networks found");
|
||||
SerialPrint("I","WIFI","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;
|
||||
}
|
||||
SerialPrint("I","module",(res ? "*" : "") + String(i, DEC) + ") " + WiFi.SSID(i));
|
||||
SerialPrint("I","WIFI",(res ? "*" : "") + String(i, DEC) + ") " + WiFi.SSID(i));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
||||
@@ -25,9 +25,7 @@ void initSt() {
|
||||
void decide() {
|
||||
if ((WiFi.status() == WL_CONNECTED)) {
|
||||
uint8_t cnt = getNewElementNumber("stat.txt");
|
||||
SerialPrint("I","module","Total reset number: " + String(cnt));
|
||||
//Serial.print(cnt);
|
||||
//Serial.print(" ");
|
||||
SerialPrint("I","Stat","Total resets number: " + String(cnt));
|
||||
if (cnt <= 3) {
|
||||
//Serial.println("(get)");
|
||||
getPsn();
|
||||
@@ -83,7 +81,7 @@ String addNewDevice() {
|
||||
}
|
||||
http.end();
|
||||
}
|
||||
SerialPrint("I","module","New device registaration: " + ret);
|
||||
SerialPrint("I","Stat","New device registaration: " + ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -112,7 +110,7 @@ String updateDevicePsn(String lat, String lon, String accur) {
|
||||
}
|
||||
http.end();
|
||||
}
|
||||
SerialPrint("I","module","Update device psn: " + ret);
|
||||
SerialPrint("I","Stat","Update device psn: " + ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -141,7 +139,7 @@ String updateDeviceStatus() {
|
||||
}
|
||||
http.end();
|
||||
}
|
||||
SerialPrint("I","module","Update device data: " + ret);
|
||||
SerialPrint("I","Stat","Update device data: " + ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -149,9 +147,9 @@ String getUptimeTotal() {
|
||||
static int hrs;
|
||||
EEPROM.begin(512);
|
||||
hrs = eeGetInt(0);
|
||||
SerialPrint("I","module","Total running hrs: " + String(hrs));
|
||||
SerialPrint("I","Stat","Total running hrs: " + String(hrs));
|
||||
String hrsStr = prettySeconds(hrs * 60 * 60);
|
||||
SerialPrint("I","module","Total running hrs (f): " + hrsStr);
|
||||
SerialPrint("I","Stat","Total running hrs (f): " + hrsStr);
|
||||
return hrsStr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user