mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
modules
This commit is contained in:
@@ -35,7 +35,7 @@ void init() {
|
||||
if (isNetworkActive()) {
|
||||
if (mqtt.connected()) {
|
||||
if (!connected) {
|
||||
SerialPrint("I","module","OK");
|
||||
SerialPrint("I","MQTT","OK");
|
||||
setLedStatus(LED_OFF);
|
||||
connected = true;
|
||||
}
|
||||
@@ -45,7 +45,7 @@ void init() {
|
||||
}
|
||||
} else {
|
||||
if (connected) {
|
||||
SerialPrint("[E]","module","connection lost");
|
||||
SerialPrint("[E]","MQTT","connection lost");
|
||||
connected = false;
|
||||
}
|
||||
ts.remove(WIFI_MQTT_CONNECTION_CHECK);
|
||||
@@ -57,7 +57,7 @@ void init() {
|
||||
}
|
||||
|
||||
void disconnect() {
|
||||
SerialPrint("I","module","disconnect");
|
||||
SerialPrint("I","MQTT","disconnect");
|
||||
mqtt.disconnect();
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ void loop() {
|
||||
}
|
||||
|
||||
void subscribe() {
|
||||
SerialPrint("I","module","subscribe");
|
||||
SerialPrint("I","MQTT","subscribe");
|
||||
mqtt.subscribe(mqttPrefix.c_str());
|
||||
mqtt.subscribe((mqttRootDevice + "/+/control").c_str());
|
||||
mqtt.subscribe((mqttRootDevice + "/order").c_str());
|
||||
@@ -84,11 +84,11 @@ void subscribe() {
|
||||
}
|
||||
|
||||
boolean connect() {
|
||||
SerialPrint("I","module","connect");
|
||||
SerialPrint("I","MQTT","connect");
|
||||
|
||||
String addr = jsonReadStr(configSetupJson, "mqttServer");
|
||||
if (!addr) {
|
||||
SerialPrint("[E]","module","no broker address");
|
||||
SerialPrint("[E]","MQTT","no broker address");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -100,20 +100,20 @@ boolean connect() {
|
||||
mqttPrefix = jsonReadStr(configSetupJson, "mqttPrefix");
|
||||
mqttRootDevice = mqttPrefix + "/" + chipId;
|
||||
|
||||
SerialPrint("I","module","broker " + addr + ":" + String(port, DEC));
|
||||
SerialPrint("I","module","topic " + mqttRootDevice);
|
||||
SerialPrint("I","MQTT","broker " + addr + ":" + String(port, DEC));
|
||||
SerialPrint("I","MQTT","topic " + mqttRootDevice);
|
||||
|
||||
setLedStatus(LED_FAST);
|
||||
mqtt.setServer(addr.c_str(), port);
|
||||
bool res = false;
|
||||
if (!mqtt.connected()) {
|
||||
if (mqtt.connect(chipId.c_str(), user.c_str(), pass.c_str())) {
|
||||
SerialPrint("I","module","connected");
|
||||
SerialPrint("I","MQTT","connected");
|
||||
setLedStatus(LED_OFF);
|
||||
subscribe();
|
||||
res = true;
|
||||
} else {
|
||||
SerialPrint("[E]","module","could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s");
|
||||
SerialPrint("[E]","MQTT","could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s");
|
||||
setLedStatus(LED_FAST);
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,7 @@ boolean connect() {
|
||||
void handleSubscribedUpdates(char* topic, uint8_t* payload, size_t length) {
|
||||
String topicStr = String(topic);
|
||||
|
||||
SerialPrint("I","module",topicStr);
|
||||
SerialPrint("I","MQTT",topicStr);
|
||||
|
||||
String payloadStr;
|
||||
|
||||
@@ -132,10 +132,10 @@ void handleSubscribedUpdates(char* topic, uint8_t* payload, size_t length) {
|
||||
payloadStr += (char)payload[i];
|
||||
}
|
||||
|
||||
SerialPrint("I","module",payloadStr);
|
||||
SerialPrint("I","MQTT",payloadStr);
|
||||
|
||||
if (payloadStr.startsWith("HELLO")) {
|
||||
SerialPrint("I","module","Full update");
|
||||
SerialPrint("I","MQTT","Full update");
|
||||
publishWidgets();
|
||||
publishState();
|
||||
#ifdef LOGGING_ENABLED
|
||||
@@ -184,7 +184,7 @@ boolean publish(const String& topic, const String& data) {
|
||||
boolean publishData(const String& topic, const String& data) {
|
||||
String path = mqttRootDevice + "/" + topic;
|
||||
if (!publish(path, data)) {
|
||||
SerialPrint("[E]","module","on publish data");
|
||||
SerialPrint("[E]","MQTT","on publish data");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -193,7 +193,7 @@ boolean publishData(const String& topic, const String& data) {
|
||||
boolean publishChart(const String& topic, const String& data) {
|
||||
String path = mqttRootDevice + "/" + topic + "/status";
|
||||
if (!publish(path, data)) {
|
||||
SerialPrint("[E]","module","on publish chart");
|
||||
SerialPrint("[E]","MQTT","on publish chart");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -244,12 +244,12 @@ void publishWidgets() {
|
||||
void publishWidgets() {
|
||||
auto file = seekFile("layout.txt");
|
||||
if (!file) {
|
||||
SerialPrint("[E]","module","no file layout.txt");
|
||||
SerialPrint("[E]","MQTT","no file layout.txt");
|
||||
return;
|
||||
}
|
||||
while (file.available()) {
|
||||
String payload = file.readStringUntil('\n');
|
||||
SerialPrint("I","module","widgets: " + payload);
|
||||
SerialPrint("I","MQTT","widgets: " + payload);
|
||||
publishData("config", payload);
|
||||
}
|
||||
file.close();
|
||||
|
||||
@@ -23,7 +23,7 @@ void upgradeInit() {
|
||||
if (isNetworkActive()) {
|
||||
getLastVersion();
|
||||
if (lastVersion.length()) {
|
||||
SerialPrint("I","module","available: " + lastVersion);
|
||||
SerialPrint("I","Update","available: " + lastVersion);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ void web_init() {
|
||||
//==============================presets===========================================================================================================
|
||||
//uint8_t preset;
|
||||
//if (parseRequestForPreset(request, preset)) {
|
||||
// SerialPrint("I","module","activate #" + String(preset, DEC));
|
||||
// SerialPrint("I","Web","activate #" + String(preset, DEC));
|
||||
// String configFile = DEVICE_CONFIG_FILE;
|
||||
// String scenarioFile = DEVICE_SCENARIO_FILE;
|
||||
// copyFile(getConfigFile(preset, CT_CONFIG), configFile);
|
||||
@@ -262,7 +262,7 @@ void web_init() {
|
||||
*/
|
||||
server.on("/check", HTTP_GET, [](AsyncWebServerRequest* request) {
|
||||
myNotAsincActions->make(do_GETLASTVERSION);
|
||||
SerialPrint("I","module","firmware version: " + lastVersion);
|
||||
SerialPrint("I","Web","firmware version: " + lastVersion);
|
||||
|
||||
if (!FLASH_4MB) {
|
||||
lastVersion = "less";
|
||||
@@ -302,7 +302,7 @@ void web_init() {
|
||||
}
|
||||
|
||||
void setConfigParam(const char* param, const String& value) {
|
||||
SerialPrint("I","module","set " + String(param) + ": " + value);
|
||||
SerialPrint("I","Web","set " + String(param) + ": " + value);
|
||||
jsonWriteStr(configSetupJson, param, value);
|
||||
saveConfig();
|
||||
}
|
||||
28
src/main.cpp
28
src/main.cpp
@@ -35,43 +35,43 @@ void setup() {
|
||||
myNotAsincActions = new NotAsinc(do_LAST);
|
||||
myScenario = new Scenario();
|
||||
|
||||
SerialPrint("I","module","FS");
|
||||
SerialPrint("I","FS","FS");
|
||||
fileSystemInit();
|
||||
|
||||
SerialPrint("I","module","Config");
|
||||
SerialPrint("I","Conf","Config");
|
||||
loadConfig();
|
||||
|
||||
SerialPrint("I","module","Clock");
|
||||
SerialPrint("I","Time","Clock");
|
||||
clock_init();
|
||||
|
||||
SerialPrint("I","module","Commands");
|
||||
SerialPrint("I","CMD","Commands");
|
||||
cmd_init();
|
||||
|
||||
SerialPrint("I","module","Sensors");
|
||||
SerialPrint("I","Sensors","Sensors");
|
||||
sensorsInit();
|
||||
|
||||
SerialPrint("I","module","Init");
|
||||
SerialPrint("I","Init","Init");
|
||||
all_init();
|
||||
|
||||
SerialPrint("I","module","Network");
|
||||
SerialPrint("I","WIFI","Network");
|
||||
startSTAMode();
|
||||
|
||||
SerialPrint("I","module","Uptime");
|
||||
SerialPrint("I","Uptime","Uptime");
|
||||
uptime_init();
|
||||
|
||||
SerialPrint("I","module","Updater");
|
||||
SerialPrint("I","Update","Updater");
|
||||
upgradeInit();
|
||||
|
||||
SerialPrint("I","module","HttpServer");
|
||||
SerialPrint("I","HTTP","HttpServer");
|
||||
HttpServer::init();
|
||||
|
||||
SerialPrint("I","module","WebAdmin");
|
||||
SerialPrint("I","Web","WebAdmin");
|
||||
web_init();
|
||||
|
||||
SerialPrint("I","module","InitSt");
|
||||
SerialPrint("I","Stat","InitSt");
|
||||
initSt();
|
||||
|
||||
SerialPrint("I","module","asyncUdpInit");
|
||||
SerialPrint("I","UDP","asyncUdpInit");
|
||||
asyncUdpInit();
|
||||
|
||||
#ifdef UDP_ENABLED
|
||||
@@ -79,7 +79,7 @@ void setup() {
|
||||
udpInit();
|
||||
#endif
|
||||
#ifdef SSDP_EN
|
||||
SerialPrint("I","module","Ssdp Init");
|
||||
SerialPrint("I","SSDP","Ssdp Init");
|
||||
SsdpInit();
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user