diff --git a/include/Class/LineParsing.h b/include/Class/LineParsing.h index 95544fd4..cae6765e 100644 --- a/include/Class/LineParsing.h +++ b/include/Class/LineParsing.h @@ -43,7 +43,7 @@ class LineParsing { void update() { //String order = sCmd.order(); - //pm.info("create '" + order + "'"); + //SerialPrint("I","module","create '" + order + "'"); for (int i = 1; i < 12; i++) { if (i == 1) _key = sCmd.next(); if (i == 2) _file = sCmd.next(); @@ -166,7 +166,7 @@ class LineParsing { buf = readFile(getWidgetFileClass(filename), 2048); bool res = !(buf == "Failed" || buf == "Large"); if (!res) { - //pm.error("on load" + filename); + //SerialPrint("[E]","module","on load" + filename); } return res; } diff --git a/include/Class/ScenarioClass.h b/include/Class/ScenarioClass.h index 66e15ca3..3a241112 100644 --- a/include/Class/ScenarioClass.h +++ b/include/Class/ScenarioClass.h @@ -81,7 +81,7 @@ class Scenario { flag = _eventValue.toInt() <= _conditionValue.toInt(); } - if (flag) Serial.println("[I] Scenario event: " + _condition); + if (flag) Serial.println("I Scenario event: " + _condition); return flag; } diff --git a/include/Clock.h b/include/Clock.h index 53685c1f..eaddafde 100644 --- a/include/Clock.h +++ b/include/Clock.h @@ -10,7 +10,7 @@ #endif class Clock { - const char* MODULE = "Clock"; + private: Time_t _time_local; @@ -71,7 +71,7 @@ class Clock { void startSync() { if (!_configured) { - //pm.info("sync to: " + _ntp + " timezone: " + String(_timezone)); + //SerialPrint("I","module","sync to: " + _ntp + " timezone: " + String(_timezone)); setupSntp(); _configured = true; // лучше не ждать, проверим в следующий раз @@ -79,9 +79,9 @@ class Clock { } _hasSynced = hasTimeSynced(); if (_hasSynced) { - //pm.info("synced " + getDateDotFormated() + " " + getTime()); + //SerialPrint("I","module","synced " + getDateDotFormated() + " " + getTime()); } else { - //pm.error("failed to obtain"); + //SerialPrint("[E]","module","failed to obtain"); } } diff --git a/include/Global.h b/include/Global.h index 735ad63d..c963ea36 100644 --- a/include/Global.h +++ b/include/Global.h @@ -19,6 +19,7 @@ #include "Utils\SysUtils.h" #include "Utils\PrintMessage.h" #include "Utils\WiFiUtils.h" +#include "Utils\SerialPrint.h" #include #include @@ -34,6 +35,7 @@ #include + #ifdef WEBSOCKET_ENABLED extern AsyncWebSocket ws; //extern AsyncEventSource events; diff --git a/include/Utils/SerialPrint.h b/include/Utils/SerialPrint.h new file mode 100644 index 00000000..f0d2d79c --- /dev/null +++ b/include/Utils/SerialPrint.h @@ -0,0 +1,3 @@ +#pragma once +#include +void SerialPrint(String errorLevel, String module, String msg); \ No newline at end of file diff --git a/include/items/SensorAnalogClass.h b/include/items/SensorAnalogClass.h index 36cf7b3d..e462a97e 100644 --- a/include/items/SensorAnalogClass.h +++ b/include/items/SensorAnalogClass.h @@ -25,7 +25,7 @@ class SensorAnalogClass : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); MqttClient::publishStatus(key, String(valueFl)); - Serial.println("[I] sensor '" + key + "' data: " + String(valueFl)); + Serial.println("I sensor '" + key + "' data: " + String(valueFl)); return value; } }; diff --git a/include/items/SensorBme280Class.h b/include/items/SensorBme280Class.h index 14d1a769..2660300d 100644 --- a/include/items/SensorBme280Class.h +++ b/include/items/SensorBme280Class.h @@ -37,7 +37,7 @@ // eventGen(key, ""); // jsonWriteStr(configLiveJson, key, String(valueFl)); // MqttClient::publishStatus(key, String(valueFl)); -// Serial.println("[I] sensor '" + key + "' data: " + String(valueFl)); +// Serial.println("I sensor '" + key + "' data: " + String(valueFl)); // } // } // } diff --git a/include/items/SensorDallasClass.h b/include/items/SensorDallasClass.h index fa31cf0a..9b5c16b4 100644 --- a/include/items/SensorDallasClass.h +++ b/include/items/SensorDallasClass.h @@ -37,7 +37,7 @@ class SensorDallasClass : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); MqttClient::publishStatus(key, String(valueFl)); - Serial.println("[I] sensor '" + key + "' data: " + String(valueFl)); + Serial.println("I sensor '" + key + "' data: " + String(valueFl)); } } } diff --git a/include/items/SensorDhtClass.h b/include/items/SensorDhtClass.h index 31b9b174..0938f23e 100644 --- a/include/items/SensorDhtClass.h +++ b/include/items/SensorDhtClass.h @@ -43,7 +43,7 @@ class SensorDhtClass : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); MqttClient::publishStatus(key, String(valueFl)); - Serial.println("[I] sensor '" + key + "' data: " + String(valueFl)); + Serial.println("I sensor '" + key + "' data: " + String(valueFl)); } else { Serial.println("[E] sensor '" + key); } @@ -67,7 +67,7 @@ class SensorDhtClass : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); MqttClient::publishStatus(key, String(valueFl)); - Serial.println("[I] sensor '" + key + "' data: " + String(valueFl)); + Serial.println("I sensor '" + key + "' data: " + String(valueFl)); } else { Serial.println("[E] sensor '" + key); } diff --git a/include/items/SensorUltrasonicClass.h b/include/items/SensorUltrasonicClass.h index 001cc89b..4a7ed1a2 100644 --- a/include/items/SensorUltrasonicClass.h +++ b/include/items/SensorUltrasonicClass.h @@ -35,7 +35,7 @@ class SensorUltrasonic : public SensorConvertingClass { eventGen(key, ""); jsonWriteStr(configLiveJson, key, String(valueFl)); MqttClient::publishStatus(key, String(valueFl)); - Serial.println("[I] sensor '" + key + "' data: " + String(valueFl)); + Serial.println("I sensor '" + key + "' data: " + String(valueFl)); } }; extern SensorUltrasonic mySensorUltrasonic; \ No newline at end of file diff --git a/src/BufferExecute.cpp b/src/BufferExecute.cpp index cb312eb7..e4255cb7 100644 --- a/src/BufferExecute.cpp +++ b/src/BufferExecute.cpp @@ -3,7 +3,7 @@ #include "Module/Terminal.h" #include "Errors.h" -static const char *MODULE = "Cmd"; + void loopCmdAdd(const String &cmdStr) { orderBuf += cmdStr; @@ -45,7 +45,7 @@ void spaceCmdExecute(String &cmdStr) { void loopCmdExecute() { if (orderBuf.length()) { String tmp = selectToMarker(orderBuf, ","); //выделяем первую команду rel 5 1, - pm.info("do: " + tmp); + SerialPrint("I","module","do: " + tmp); sCmd.readStr(tmp); //выполняем orderBuf = deleteBeforeDelimiter(orderBuf, ","); //осекаем } diff --git a/src/Bus/I2CScanner.cpp b/src/Bus/I2CScanner.cpp index 669b2903..900c51b7 100644 --- a/src/Bus/I2CScanner.cpp +++ b/src/Bus/I2CScanner.cpp @@ -3,7 +3,7 @@ #include -static const char* MODULE = "I2C"; + I2CScanner::I2CScanner(String& out) : BusScanner(TAG_I2C, out, 2){}; @@ -12,12 +12,12 @@ void I2CScanner::init() { } boolean I2CScanner::syncScan() { - pm.info("scanning..."); + SerialPrint("I","module","scanning..."); size_t cnt = 0; for (uint8_t i = 8; i < 120; i++) { Wire.beginTransmission(i); if (Wire.endTransmission() == 0) { - pm.info("found: " + i); + SerialPrint("I","module","found: " + i); addResult(i, i < 119); cnt++; } diff --git a/src/Logging.cpp b/src/Logging.cpp index ab44bba6..bb76371a 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -5,7 +5,6 @@ void sendLogData(String file, String topic); -static const char* MODULE = "Log"; #ifdef LOGGING_ENABLED //===============================================Логирование============================================================ @@ -30,7 +29,7 @@ void logging() { LOG1, period_min.toInt() * 1000 * 60, [&](void*) { String tmp_buf_1 = selectFromMarkerToMarker(logging_value_names_list, ",", 0); deleteOldDate("log." + tmp_buf_1 + ".txt", jsonReadInt(configOptionJson, tmp_buf_1 + "_c"), jsonReadStr(configLiveJson, tmp_buf_1)); - pm.info("logging for " + tmp_buf_1 + " done"); + SerialPrint("I","module","logging for " + tmp_buf_1 + " done"); }, nullptr, false); } @@ -39,7 +38,7 @@ void logging() { LOG2, period_min.toInt() * 1000 * 60, [&](void*) { String tmp_buf_2 = selectFromMarkerToMarker(logging_value_names_list, ",", 1); deleteOldDate("log." + tmp_buf_2 + ".txt", jsonReadInt(configOptionJson, tmp_buf_2 + "_c"), jsonReadStr(configLiveJson, tmp_buf_2)); - pm.info("logging for " + tmp_buf_2 + " done"); + SerialPrint("I","module","logging for " + tmp_buf_2 + " done"); }, nullptr, false); } @@ -48,7 +47,7 @@ void logging() { LOG3, period_min.toInt() * 1000 * 60, [&](void*) { String tmp_buf_3 = selectFromMarkerToMarker(logging_value_names_list, ",", 2); deleteOldDate("log." + tmp_buf_3 + ".txt", jsonReadInt(configOptionJson, tmp_buf_3 + "_c"), jsonReadStr(configLiveJson, tmp_buf_3)); - pm.info("logging for " + tmp_buf_3 + " done"); + SerialPrint("I","module","logging for " + tmp_buf_3 + " done"); }, nullptr, false); } @@ -57,7 +56,7 @@ void logging() { LOG4, period_min.toInt() * 1000 * 60, [&](void*) { String tmp_buf_4 = selectFromMarkerToMarker(logging_value_names_list, ",", 3); deleteOldDate("log." + tmp_buf_4 + ".txt", jsonReadInt(configOptionJson, tmp_buf_4 + "_c"), jsonReadStr(configLiveJson, tmp_buf_4)); - pm.info("logging for " + tmp_buf_4 + " done"); + SerialPrint("I","module","logging for " + tmp_buf_4 + " done"); }, nullptr, false); } @@ -66,7 +65,7 @@ void logging() { LOG5, period_min.toInt() * 1000 * 60, [&](void*) { String tmp_buf_5 = selectFromMarkerToMarker(logging_value_names_list, ",", 4); deleteOldDate("log." + tmp_buf_5 + ".txt", jsonReadInt(configOptionJson, tmp_buf_5 + "_c"), jsonReadStr(configLiveJson, tmp_buf_5)); - pm.info("logging for " + tmp_buf_5 + " done"); + SerialPrint("I","module","logging for " + tmp_buf_5 + " done"); }, nullptr, false); } @@ -79,7 +78,7 @@ void deleteOldDate(const String filename, size_t max_lines_cnt, String payload) String log_date = readFile(filename, 5120); size_t lines_cnt = itemsCount(log_date, "\r\n"); - pm.info("log " + filename + " (" + String(lines_cnt, DEC) + ")"); + SerialPrint("I","module","log " + filename + " (" + String(lines_cnt, DEC) + ")"); if ((lines_cnt > max_lines_cnt + 1) || !lines_cnt) { removeFile(filename); @@ -136,7 +135,7 @@ void sendLogData(String file, String topic) { value = ""; log_date = ""; json_array = "{\"status\":[" + json_array + "]}"; - pm.info(json_array); + SerialPrint("I","module",json_array); MqttClient::publishChart(topic, json_array); } diff --git a/src/MqttClient.cpp b/src/MqttClient.cpp index e9258605..dce91c8f 100644 --- a/src/MqttClient.cpp +++ b/src/MqttClient.cpp @@ -6,7 +6,7 @@ #include "Global.h" #include "Init.h" -static const char* MODULE = "Mqtt"; + namespace MqttClient { @@ -35,7 +35,7 @@ void init() { if (isNetworkActive()) { if (mqtt.connected()) { if (!connected) { - pm.info("OK"); + SerialPrint("I","module","OK"); setLedStatus(LED_OFF); connected = true; } @@ -45,7 +45,7 @@ void init() { } } else { if (connected) { - pm.error("connection lost"); + SerialPrint("[E]","module","connection lost"); connected = false; } ts.remove(WIFI_MQTT_CONNECTION_CHECK); @@ -57,7 +57,7 @@ void init() { } void disconnect() { - pm.info("disconnect"); + SerialPrint("I","module","disconnect"); mqtt.disconnect(); } @@ -74,7 +74,7 @@ void loop() { } void subscribe() { - pm.info("subscribe"); + SerialPrint("I","module","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() { - pm.info("connect"); + SerialPrint("I","module","connect"); String addr = jsonReadStr(configSetupJson, "mqttServer"); if (!addr) { - pm.error("no broker address"); + SerialPrint("[E]","module","no broker address"); return false; } @@ -100,20 +100,20 @@ boolean connect() { mqttPrefix = jsonReadStr(configSetupJson, "mqttPrefix"); mqttRootDevice = mqttPrefix + "/" + chipId; - pm.info("broker " + addr + ":" + String(port, DEC)); - pm.info("topic " + mqttRootDevice); + SerialPrint("I","module","broker " + addr + ":" + String(port, DEC)); + SerialPrint("I","module","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())) { - pm.info("connected"); + SerialPrint("I","module","connected"); setLedStatus(LED_OFF); subscribe(); res = true; } else { - pm.error("could't connect, retry in " + String(MQTT_RECONNECT_INTERVAL / 1000) + "s"); + SerialPrint("[E]","module","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); - pm.info(topicStr); + SerialPrint("I","module",topicStr); String payloadStr; @@ -132,10 +132,10 @@ void handleSubscribedUpdates(char* topic, uint8_t* payload, size_t length) { payloadStr += (char)payload[i]; } - pm.info(payloadStr); + SerialPrint("I","module",payloadStr); if (payloadStr.startsWith("HELLO")) { - pm.info("Full update"); + SerialPrint("I","module","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)) { - pm.error("on publish data"); + SerialPrint("[E]","module","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)) { - pm.error("on publish chart"); + SerialPrint("[E]","module","on publish chart"); return false; } return true; @@ -235,7 +235,7 @@ void publishWidgets() { Serial.println("[V] " + line); psn_1 = psn_2 + 1; } while (psn_2 + 2 < all_widgets.length()); - getMemoryLoad("[I] after send all widgets"); + getMemoryLoad("I after send all widgets"); } } #endif @@ -244,12 +244,12 @@ void publishWidgets() { void publishWidgets() { auto file = seekFile("layout.txt"); if (!file) { - pm.error("no file layout.txt"); + SerialPrint("[E]","module","no file layout.txt"); return; } while (file.available()) { String payload = file.readStringUntil('\n'); - pm.info("widgets: " + payload); + SerialPrint("I","module","widgets: " + payload); publishData("config", payload); } file.close(); diff --git a/src/PushingBox.cpp b/src/PushingBox.cpp index 67e2be14..5c2f91e4 100644 --- a/src/PushingBox.cpp +++ b/src/PushingBox.cpp @@ -23,15 +23,15 @@ void pushControl() { const char* logServer = "api.pushingbox.com"; String deviceId = jsonReadStr(configSetupJson, "pushingbox_id"); - Serial.println("- starting client"); + //Serial.println("- starting client"); WiFiClient client_push; - Serial.println("- connecting to pushing server: " + String(logServer)); + //Serial.println("- connecting to pushing server: " + String(logServer)); if (!client_push.connect(logServer, 80)) { - Serial.println("- not connected"); + //Serial.println("- not connected"); } else { - Serial.println("- succesfully connected"); + //Serial.println("- succesfully connected"); String postStr = "devid="; postStr += String(deviceId); @@ -44,7 +44,7 @@ void pushControl() { postStr += "\r\n\r\n"; - Serial.println("- sending data..."); + //Serial.println("- sending data..."); client_push.print(F("POST /pushingbox HTTP/1.1\n")); client_push.print(F("Host: api.pushingbox.com\n")); @@ -56,5 +56,5 @@ void pushControl() { client_push.print(postStr); } client_push.stop(); - Serial.println("- stopping the client"); + //Serial.println("- stopping the client"); } diff --git a/src/RemoteOrdersUdp.cpp b/src/RemoteOrdersUdp.cpp index add4a8c3..aa41e322 100644 --- a/src/RemoteOrdersUdp.cpp +++ b/src/RemoteOrdersUdp.cpp @@ -35,9 +35,9 @@ void asyncUdpInit() { Serial.print(data); if (udpPacketValidation(data)) { udpPacketParse(data); - Serial.println("', Packet valid"); + //Serial.println("', Packet valid"); } else { - Serial.println("', Packet invalid"); + //Serial.println("', Packet invalid"); } //reply to the client diff --git a/src/Scenario.cpp b/src/Scenario.cpp index 00aaa0fc..2399d178 100644 --- a/src/Scenario.cpp +++ b/src/Scenario.cpp @@ -2,7 +2,7 @@ #include "Global.h" #include "Class/ScenarioClass.h" -static const char* MODULE = "Scen"; + boolean isScenarioEnabled() { return jsonReadBool(configSetupJson, "scen") && eventBuf != ""; @@ -58,7 +58,7 @@ void loopScenario() { if (flag) { scenBlok = deleteBeforeDelimiter(scenBlok, "\n"); // удаляем строку самого сценария оставляя только команды - pm.info("do: " + scenBlok); + SerialPrint("I","module","do: " + scenBlok); spaceCmdExecute(scenBlok); // выполняем все команды } } diff --git a/src/Sensors.cpp b/src/Sensors.cpp index 7285c055..1ba131ad 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -57,7 +57,7 @@ // //eventGen(dhtT_value_name, ""); // //jsonWriteStr(configLiveJson, dhtT_value_name, String(value)); // //MqttClient::publishStatus(dhtT_value_name, String(value)); -// //Serial.println("[I] sensor '" + dhtT_value_name + "' data: " + String(value)); +// //Serial.println("I sensor '" + dhtT_value_name + "' data: " + String(value)); // } // } //} @@ -95,7 +95,7 @@ // //eventGen(dhtH_value_name, ""); // //jsonWriteStr(configLiveJson, dhtH_value_name, String(value)); // //MqttClient::publishStatus(dhtH_value_name, String(value)); -// //Serial.println("[I] sensor '" + dhtH_value_name + "' data: " + String(value)); +// //Serial.println("I sensor '" + dhtH_value_name + "' data: " + String(value)); // } // } //} @@ -120,7 +120,7 @@ // eventGen("dhtPerception", ""); // MqttClient::publishStatus("dhtPerception", final_line); // if (mqtt.connected()) { -// Serial.println("[I] sensor 'dhtPerception' data: " + final_line); +// Serial.println("I sensor 'dhtPerception' data: " + final_line); // } // } //} @@ -144,7 +144,7 @@ // jsonWriteStr(configLiveJson, "dhtComfort", final_line); // eventGen("dhtComfort", ""); // MqttClient::publishStatus("dhtComfort", final_line); -// Serial.println("[I] sensor 'dhtComfort' send date " + final_line); +// Serial.println("I sensor 'dhtComfort' send date " + final_line); // } //} // @@ -236,7 +236,7 @@ // jsonWriteInt(configLiveJson, "dhtDewpoint", value); // eventGen("dhtDewpoint", ""); // MqttClient::publishStatus("dhtDewpoint", String(value)); -// Serial.println("[I] sensor 'dhtDewpoint' data: " + String(value)); +// Serial.println("I sensor 'dhtDewpoint' data: " + String(value)); // } //} //#endif @@ -272,7 +272,7 @@ // //jsonWriteStr(configLiveJson, bmp280T_value_name, String(value)); // //eventGen(bmp280T_value_name, ""); // //MqttClient::publishStatus(bmp280T_value_name, String(value)); -// //Serial.println("[I] sensor '" + bmp280T_value_name + "' data: " + String(value)); +// //Serial.println("I sensor '" + bmp280T_value_name + "' data: " + String(value)); //} // ////bmp280P press1 0x76 Давление#bmp280 Датчики any-data 2 @@ -304,7 +304,7 @@ // //jsonWriteStr(configLiveJson, bmp280P_value_name, String(value)); // //eventGen(bmp280P_value_name, ""); // //MqttClient::publishStatus(bmp280P_value_name, String(value)); -// //Serial.println("[I] sensor '" + bmp280P_value_name + "' data: " + String(value)); +// //Serial.println("I sensor '" + bmp280P_value_name + "' data: " + String(value)); //} // ////========================================================================================================================================= @@ -329,7 +329,7 @@ // //jsonWriteStr(configLiveJson, bme280T_value_name, String(value)); // //eventGen(bme280T_value_name, ""); // //MqttClient::publishStatus(bme280T_value_name, String(value)); -// //Serial.println("[I] sensor '" + bme280T_value_name + "' data: " + String(value)); +// //Serial.println("I sensor '" + bme280T_value_name + "' data: " + String(value)); //} // ////bme280P pres1 0x76 Давление#bmp280 Датчики any-data 1 @@ -353,7 +353,7 @@ // //jsonWriteStr(configLiveJson, bme280P_value_name, String(value)); // //eventGen(bme280P_value_name, ""); // //MqttClient::publishStatus(bme280P_value_name, String(value)); -// //Serial.println("[I] sensor '" + bme280P_value_name + "' data: " + String(value)); +// //Serial.println("I sensor '" + bme280P_value_name + "' data: " + String(value)); //} // ////bme280H hum1 0x76 Влажность#bmp280 Датчики any-data 1 @@ -376,7 +376,7 @@ // //jsonWriteStr(configLiveJson, bme280H_value_name, String(value)); // //eventGen(bme280H_value_name, ""); // //MqttClient::publishStatus(bme280H_value_name, String(value)); -// //Serial.println("[I] sensor '" + bme280H_value_name + "' data: " + String(value)); +// //Serial.println("I sensor '" + bme280H_value_name + "' data: " + String(value)); //} // ////bme280A altit1 0x76 Высота#bmp280 Датчики any-data 1 @@ -401,5 +401,5 @@ // // //MqttClient::publishStatus(bme280A_value_name, String(value)); // -// //Serial.println("[I] sensor '" + bme280A_value_name + "' data: " + String(value)); +// //Serial.println("I sensor '" + bme280A_value_name + "' data: " + String(value)); //} diff --git a/src/Timers.cpp b/src/Timers.cpp index aa6bd002..dda1007b 100644 --- a/src/Timers.cpp +++ b/src/Timers.cpp @@ -11,8 +11,8 @@ void Timer_countdown_init() { int i = 0; do { String timer = selectFromMarkerToMarker(old_line, ",", i); - Serial.print("timer no " + String(i) + ": "); - Serial.println(timer); + //Serial.print("timer no " + String(i) + ": "); + //Serial.println(timer); if (timer == "not found" || timer == "") return; int number = selectToMarker(timer, ":").toInt(); int time = readTimer(number); diff --git a/src/Upgrade.cpp b/src/Upgrade.cpp index 6885c4e9..faedbada 100644 --- a/src/Upgrade.cpp +++ b/src/Upgrade.cpp @@ -4,7 +4,7 @@ #include "ESP8266.h" #include "Global.h" -static const char* MODULE = "Update"; + static const char* check_update_url PROGMEM = "http://91.204.228.124:1100/update/%s/version.txt"; void upgradeInit() { @@ -23,7 +23,7 @@ void upgradeInit() { if (isNetworkActive()) { getLastVersion(); if (lastVersion.length()) { - pm.info("available: " + lastVersion); + SerialPrint("I","module","available: " + lastVersion); } }; } @@ -52,7 +52,7 @@ void upgrade_firmware() { configBackup = readFile(String(DEVICE_CONFIG_FILE), 4096); setupBackup = configSetupJson; - pm.info("update data"); + SerialPrint("I","module","update data"); WiFiClient wifiClient; #ifdef ESP8266 ESPhttpUpdate.rebootOnUpdate(false); @@ -68,22 +68,22 @@ void upgrade_firmware() { saveConfig(); - pm.info("done!"); + SerialPrint("I","module","done!"); } else { - pm.error("on data"); + SerialPrint("[E]","module","on data"); return; } - Serial.println("update firmware"); + //Serial.println("update firmware"); #ifdef ESP8266 ret = ESPhttpUpdate.update(wifiClient, F("http://91.204.228.124:1100/update/esp8266/esp32-esp8266_iot-manager_modules_firmware.ino.bin")); #else ret = httpUpdate.update(client_for_upgrade, "http://91.204.228.124:1100/update/esp32/esp32-esp8266_iot-manager_modules_firmware.ino.bin"); #endif if (ret == HTTP_UPDATE_OK) { - pm.info("done! restart..."); + SerialPrint("I","module","done! restart..."); ESP.restart(); } else { - pm.error("on firmware"); + SerialPrint("[E]","module","on firmware"); } } diff --git a/src/Utils/FileUtils.cpp b/src/Utils/FileUtils.cpp index 0ec732c3..baa82d6d 100644 --- a/src/Utils/FileUtils.cpp +++ b/src/Utils/FileUtils.cpp @@ -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); diff --git a/src/Utils/SerialPrint.cpp b/src/Utils/SerialPrint.cpp new file mode 100644 index 00000000..f431ccbc --- /dev/null +++ b/src/Utils/SerialPrint.cpp @@ -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); +} \ No newline at end of file diff --git a/src/Utils/SysUtils.cpp b/src/Utils/SysUtils.cpp index e5db4ea8..c2713a63 100644 --- a/src/Utils/SysUtils.cpp +++ b/src/Utils/SysUtils.cpp @@ -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 diff --git a/src/Utils/WiFiUtils.cpp b/src/Utils/WiFiUtils.cpp index 950ec1f2..18f3468c 100644 --- a/src/Utils/WiFiUtils.cpp +++ b/src/Utils/WiFiUtils.cpp @@ -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; diff --git a/src/Utils/statUtils.cpp b/src/Utils/statUtils.cpp index 069beda8..b125f4d4 100644 --- a/src/Utils/statUtils.cpp +++ b/src/Utils/statUtils.cpp @@ -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; } diff --git a/src/Web.cpp b/src/Web.cpp index b312d64f..dfbd7aa2 100644 --- a/src/Web.cpp +++ b/src/Web.cpp @@ -4,7 +4,7 @@ #include "Init.h" #include "Class/NotAsinc.h" -static const char* MODULE = "Web"; + bool parseRequestForPreset(AsyncWebServerRequest* request, uint8_t& preset) { if (request->hasArg("preset")) { @@ -32,7 +32,7 @@ void web_init() { //==============================presets=========================================================================================================== //uint8_t preset; //if (parseRequestForPreset(request, preset)) { - // pm.info("activate #" + String(preset, DEC)); + // SerialPrint("I","module","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); - pm.info("firmware version: " + lastVersion); + SerialPrint("I","module","firmware version: " + lastVersion); if (!FLASH_4MB) { lastVersion = "less"; @@ -302,7 +302,7 @@ void web_init() { } void setConfigParam(const char* param, const String& value) { - pm.info("set " + String(param) + ": " + value); + SerialPrint("I","module","set " + String(param) + ": " + value); jsonWriteStr(configSetupJson, param, value); saveConfig(); } \ No newline at end of file diff --git a/src/WebServer.cpp b/src/WebServer.cpp index e6b10f90..9a8e7df0 100644 --- a/src/WebServer.cpp +++ b/src/WebServer.cpp @@ -6,7 +6,7 @@ namespace HttpServer { -static const char *MODULE = "Http"; + /* Forward declaration */ void initOta(); void initMDNS(); @@ -29,17 +29,17 @@ void init() { server.serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(login.c_str(), pass.c_str()); server.onNotFound([](AsyncWebServerRequest *request) { - pm.error("not found:\n" + getRequestInfo(request)); + SerialPrint("[E]","module","not found:\n" + getRequestInfo(request)); request->send(404); }); server.onFileUpload([](AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) { // TODO if (!index) { - pm.info("start upload " + filename); + SerialPrint("I","module","start upload " + filename); } if (final) { - pm.info("finish upload: " + prettyBytes(index + len)); + SerialPrint("I","module","finish upload: " + prettyBytes(index + len)); } }); @@ -60,7 +60,7 @@ void init() { server.on("/cmd", HTTP_GET, [](AsyncWebServerRequest *request) { String cmdStr = request->getParam("command")->value(); - pm.info("do: " + cmdStr); + SerialPrint("I","module","do: " + cmdStr); loopCmdAdd(cmdStr); request->send(200, "text/html", "OK"); }); diff --git a/src/Widgets.cpp b/src/Widgets.cpp index 1f8b07ca..32e1285d 100644 --- a/src/Widgets.cpp +++ b/src/Widgets.cpp @@ -1,6 +1,5 @@ #include "Global.h" -static const char* MODULE = "Widget"; const String getWidgetFile(const String& name); @@ -8,7 +7,7 @@ bool loadWidget(const String& filename, String& buf) { buf = readFile(getWidgetFile(filename), 2048); bool res = !(buf == "Failed" || buf == "Large"); if (!res) { - pm.error("on load" + filename); + SerialPrint("[E]","module","on load" + filename); } return res; } diff --git a/src/main.cpp b/src/main.cpp index 8da5765a..18da033d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,7 +17,6 @@ void not_async_actions(); -static const char* MODULE = "Main"; Timings metric; boolean initialized = false; @@ -36,57 +35,57 @@ void setup() { myNotAsincActions = new NotAsinc(do_LAST); myScenario = new Scenario(); - pm.info("FS"); + SerialPrint("I","module","FS"); fileSystemInit(); - pm.info("Config"); + SerialPrint("I","module","Config"); loadConfig(); - pm.info("Clock"); + SerialPrint("I","module","Clock"); clock_init(); - pm.info("Commands"); + SerialPrint("I","module","Commands"); cmd_init(); - pm.info("Sensors"); + SerialPrint("I","module","Sensors"); sensorsInit(); - pm.info("Init"); + SerialPrint("I","module","Init"); all_init(); - pm.info("Network"); + SerialPrint("I","module","Network"); startSTAMode(); - pm.info("Uptime"); + SerialPrint("I","module","Uptime"); uptime_init(); - pm.info("Updater"); + SerialPrint("I","module","Updater"); upgradeInit(); - pm.info("HttpServer"); + SerialPrint("I","module","HttpServer"); HttpServer::init(); - pm.info("WebAdmin"); + SerialPrint("I","module","WebAdmin"); web_init(); - pm.info("InitSt"); + SerialPrint("I","module","InitSt"); initSt(); - pm.info("asyncUdpInit"); + SerialPrint("I","module","asyncUdpInit"); asyncUdpInit(); #ifdef UDP_ENABLED - pm.info("Broadcast UDP"); + SerialPrint("I","module","Broadcast UDP"); udpInit(); #endif #ifdef SSDP_EN - pm.info("Ssdp Init"); + SerialPrint("I","module","Ssdp Init"); SsdpInit(); #endif ts.add( TEST, 1000 * 60, [&](void*) { - pm.info(printMemoryStatus()); + SerialPrint("I","module",printMemoryStatus()); }, nullptr, true); diff --git a/src/udp_.cpp b/src/udp_.cpp index a94d49b0..d605eb6d 100644 --- a/src/udp_.cpp +++ b/src/udp_.cpp @@ -3,7 +3,6 @@ #include "udp_.h" #include "Global.h" -static const char* MODULE = "Udp"; #ifdef ESP8266 IPAddress udp_multicastIP(255, 255, 255, 255); @@ -49,7 +48,7 @@ void udpInit() { ts.add( UDP, udp_period, [&](void*) { if (jsonReadBool(configSetupJson, "udponoff") && isNetworkActive() && !udp_busy) { - pm.info("send info"); + SerialPrint("I","module","send info"); String payload = "iotm;"; payload += chipId; payload += ";"; @@ -85,7 +84,7 @@ void loopUdp() { char udp_packet[255]; remote_ip = udp.remoteIP().toString(); - pm.info(prettyBytes(packetSize) + " from " + remote_ip + ":" + udp.remotePort()); + SerialPrint("I","module",prettyBytes(packetSize) + " from " + remote_ip + ":" + udp.remotePort()); int len = udp.read(udp_packet, 255); if (len) { @@ -120,7 +119,7 @@ void handleUdp_esp32() { void do_udp_data_parse() { if (received.indexOf("mqttServer") >= 0) { - pm.info("received setting"); + SerialPrint("I","module","received setting"); jsonWriteStr(configSetupJson, "mqttServer", jsonReadStr(received, "mqttServer")); jsonWriteInt(configSetupJson, "mqttPort", jsonReadInt(received, "mqttPort")); jsonWriteStr(configSetupJson, "mqttPrefix", jsonReadStr(received, "mqttPrefix")); @@ -160,7 +159,7 @@ void send_mqtt_to_udp() { #ifdef ESP32 udp.broadcast(mqtt_data.c_str()); #endif - pm.info("sent info"); + SerialPrint("I","module","sent info"); udp_busy = false; }