From 96fc8ea0b75f29505133c26a64cec270095fa850 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 18:43:48 +0100 Subject: [PATCH 01/21] update esp logger --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index ce8560b9..e9d15559 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,7 +11,7 @@ lib_deps = bblanchon/ArduinoJson @ 6.17.0 lewisxhe/AXP202X_Library @ 1.1.2 peterus/APRS-Decoder-Lib @ 0.0.6 - peterus/esp-logger @ 0.0.1 + peterus/esp-logger @ 1.0.0 peterus/ESP-FTP-Server-Lib @ 0.9.5 knolleary/PubSubClient@^2.8 check_tool = cppcheck From 9cde910d5d3188ca521f7d74245c7d3d6239299b Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 18:44:03 +0100 Subject: [PATCH 02/21] add logger to system --- lib/System/System.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/System/System.h b/lib/System/System.h index 376741bf..6c7e9d40 100644 --- a/lib/System/System.h +++ b/lib/System/System.h @@ -1,6 +1,7 @@ #ifndef SYSTEM_H_ #define SYSTEM_H_ +#include #include #include "TaskManager.h" @@ -22,6 +23,7 @@ class System { Display & getDisplay(); bool isWifiEthConnected() const; void connectedViaWifiEth(bool status); + logging::Logger & getLogger(); private: BoardConfig const * _boardConfig; @@ -29,6 +31,7 @@ class System { TaskManager _taskManager; Display _display; bool _isWifiEthConnected; + logging::Logger _logger; }; #endif From 1da93bb60e3af8282a73be73fa6fc87e1f846b8d Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 18:44:10 +0100 Subject: [PATCH 03/21] task manager update --- lib/System/TaskManager.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/System/TaskManager.cpp b/lib/System/TaskManager.cpp index d524ad07..d149e2fe 100644 --- a/lib/System/TaskManager.cpp +++ b/lib/System/TaskManager.cpp @@ -2,6 +2,8 @@ #include #include +#define MODULE_NAME "TaskManager" + TaskManager::TaskManager() { } @@ -20,15 +22,13 @@ std::list TaskManager::getTasks() { } bool TaskManager::setup(System &system) { - logPrintlnV("will setup all tasks..."); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "will setup all tasks..."); for (Task *elem : _alwaysRunTasks) { - logPrintD("call setup from "); - logPrintlnD(elem->getName()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName()); elem->setup(system); } for (Task *elem : _tasks) { - logPrintD("call setup from "); - logPrintlnD(elem->getName()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName()); elem->setup(system); } _nextTask = _tasks.begin(); @@ -36,10 +36,7 @@ bool TaskManager::setup(System &system) { } bool TaskManager::loop(System &system) { - // logPrintlnD("will loop all tasks..."); for (Task *elem : _alwaysRunTasks) { - // logPrintD("call loop from "); - // logPrintlnD(elem->getName()); elem->loop(system); } From 798d5b20410b81a7caa8b8f6735e18487664d63a Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 21:57:09 +0100 Subject: [PATCH 04/21] log update in AprsIsTask --- src/TaskAprsIs.cpp | 11 ++++------- src/TaskAprsIs.h | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/TaskAprsIs.cpp b/src/TaskAprsIs.cpp index b96b06ed..8aa80c4c 100644 --- a/src/TaskAprsIs.cpp +++ b/src/TaskAprsIs.cpp @@ -40,15 +40,12 @@ bool AprsIsTask::loop(System &system) { return true; } -bool AprsIsTask::connect(const System &system) { - logPrintI("connecting to APRS-IS server: "); - logPrintI(system.getUserConfig()->aprs_is.server); - logPrintI(" on port: "); - logPrintlnI(String(system.getUserConfig()->aprs_is.port)); +bool AprsIsTask::connect(System &system) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "connecting to APRS-IS server: %s on port: %d", system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); if (!_aprs_is.connect(system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port)) { - logPrintlnE("Connection failed."); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Connection failed."); return false; } - logPrintlnI("Connected to APRS-IS server!"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connected to APRS-IS server!"); return true; } diff --git a/src/TaskAprsIs.h b/src/TaskAprsIs.h index de75fec9..30679db5 100644 --- a/src/TaskAprsIs.h +++ b/src/TaskAprsIs.h @@ -19,7 +19,7 @@ class AprsIsTask : public Task { TaskQueue> &_toAprsIs; - bool connect(const System &system); + bool connect(System &system); }; #endif From 49c61d1845d4621183f51767df4cc0693bafefcb Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:03:28 +0100 Subject: [PATCH 05/21] fixing ftp task --- src/TaskFTP.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/TaskFTP.cpp b/src/TaskFTP.cpp index d9615cf7..e4a6037b 100644 --- a/src/TaskFTP.cpp +++ b/src/TaskFTP.cpp @@ -14,8 +14,7 @@ FTPTask::~FTPTask() { bool FTPTask::setup(System &system) { for (Configuration::Ftp::User user : system.getUserConfig()->ftp.users) { - logPrintD("Adding user to FTP Server: "); - logPrintlnD(user.name); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Adding user to FTP Server: %s", user.name); _ftpServer.addUser(user.name, user.password); } _ftpServer.addFilesystem("SPIFFS", &SPIFFS); @@ -31,8 +30,7 @@ bool FTPTask::loop(System &system) { _ftpServer.handle(); static bool configWasOpen = false; if (configWasOpen && _ftpServer.countConnections() == 0) { - logPrintlnW("Maybe the config has been changed via FTP, lets restart now to get the new config..."); - logPrintlnW(""); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_WARN, getName(), "Maybe the config has been changed via FTP, lets restart now to get the new config..."); ESP.restart(); } if (_ftpServer.countConnections() > 0) { From 3fbed7b963b2fb9aaccec475e9fd064f6b10b909 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:08:54 +0100 Subject: [PATCH 06/21] modem fixed --- src/TaskModem.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index e6c5ca63..645626b2 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -17,7 +17,7 @@ bool ModemTask::setup(System &system) { SPI.begin(system.getBoardConfig()->LoraSck, system.getBoardConfig()->LoraMiso, system.getBoardConfig()->LoraMosi, system.getBoardConfig()->LoraCS); _lora_aprs.setPins(system.getBoardConfig()->LoraCS, system.getBoardConfig()->LoraReset, system.getBoardConfig()->LoraIRQ); if (!_lora_aprs.begin(system.getUserConfig()->lora.frequencyRx)) { - logPrintlnE("Starting LoRa failed!"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Starting LoRa failed!"); _stateInfo = "LoRa-Modem failed"; _state = Error; while (true) @@ -39,32 +39,19 @@ bool ModemTask::setup(System &system) { bool ModemTask::loop(System &system) { if (_lora_aprs.checkMessage()) { std::shared_ptr msg = _lora_aprs.getMessage(); - // msg->getAPRSBody()->setData(msg->getAPRSBody()->getData() + " 123"); - logPrintD("[" + timeString() + "] "); - logPrintD("Received packet '"); - logPrintD(msg->toString()); - logPrintD("' with RSSI "); - logPrintD(String(_lora_aprs.packetRssi())); - logPrintD(" and SNR "); - logPrintlnD(String(_lora_aprs.packetSnr())); - + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %d and SNR %f", timeString(), msg->toString(), _lora_aprs.packetRssi(), _lora_aprs.packetSnr()); _fromModem.addElement(msg); system.getDisplay().addFrame(std::shared_ptr(new TextFrame("LoRa", msg->toString()))); } if (!_toModem.empty()) { std::shared_ptr msg = _toModem.getElement(); - logPrintD("[" + timeString() + "] "); if (system.getUserConfig()->lora.tx_enable) { - logPrintD("Transmitting packet '"); - logPrintD(msg->toString()); - logPrintlnD("'"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString(), msg->toString()); _lora_aprs.sendMessage(msg); - logPrintlnD("TX done"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString()); } else { - logPrintD("NOT transmitting packet as TX is not enabled '"); - logPrintD(msg->toString()); - logPrintlnD("'"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] NOT transmitting packet as TX is not enabled '%s'", timeString(), msg->toString()); } } From 8d494c0832305cd535bc3987d19c9e52fb8b500e Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:18:07 +0100 Subject: [PATCH 07/21] fixing mqtt task --- src/TaskMQTT.cpp | 20 +++++--------------- src/TaskMQTT.h | 2 +- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/TaskMQTT.cpp b/src/TaskMQTT.cpp index a4d0aa4a..aa0a7a0c 100644 --- a/src/TaskMQTT.cpp +++ b/src/TaskMQTT.cpp @@ -46,29 +46,19 @@ bool MQTTTask::loop(System &system) { topic = topic + "/"; } topic = topic + system.getUserConfig()->callsign; - - logPrintD("Send MQTT with topic: \""); - logPrintD(topic); - logPrintD("\", data: "); - logPrintlnD(r); - + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Send MQTT with topic: '%s', data: %s", topic, r); _MQTT.publish(topic.c_str(), r.c_str()); } _MQTT.loop(); return true; } -bool MQTTTask::connect(const System &system) { - logPrintI("Connecting to MQTT broker: "); - logPrintI(system.getUserConfig()->mqtt.server); - logPrintI(" on port "); - logPrintlnI(String(system.getUserConfig()->mqtt.port)); - +bool MQTTTask::connect(System &system) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker: %s on port %d", system.getUserConfig()->mqtt.server, system.getUserConfig()->mqtt.port); if (_MQTT.connect(system.getUserConfig()->callsign.c_str(), system.getUserConfig()->mqtt.name.c_str(), system.getUserConfig()->mqtt.password.c_str())) { - logPrintI("Connected to MQTT broker as: "); - logPrintlnI(system.getUserConfig()->callsign); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connected to MQTT broker as: %s", system.getUserConfig()->callsign); return true; } - logPrintlnI("Connecting to MQTT broker faild. Try again later."); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker failed. Try again later."); return false; } diff --git a/src/TaskMQTT.h b/src/TaskMQTT.h index 88fa35eb..d3880759 100644 --- a/src/TaskMQTT.h +++ b/src/TaskMQTT.h @@ -20,7 +20,7 @@ class MQTTTask : public Task { WiFiClient _client; PubSubClient _MQTT; - bool connect(const System &system); + bool connect(System &system); }; #endif From ee25e0194f8dae015eda90693ee5961f8f2c867f Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:19:59 +0100 Subject: [PATCH 08/21] fixing ntp task --- src/TaskNTP.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/TaskNTP.cpp b/src/TaskNTP.cpp index 14b3808a..c012ae83 100644 --- a/src/TaskNTP.cpp +++ b/src/TaskNTP.cpp @@ -27,8 +27,7 @@ bool NTPTask::loop(System &system) { } if (_ntpClient.update()) { setTime(_ntpClient.getEpochTime()); - logPrintI("Current time: "); - logPrintlnI(_ntpClient.getFormattedTime()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Current time: %s", _ntpClient.getFormattedTime()); } _stateInfo = _ntpClient.getFormattedTime(); _state = Okay; From 9c2fb18d1b35dcb3b3686379b75624cc5bbfd579 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:29:38 +0100 Subject: [PATCH 09/21] fixing ota --- src/TaskOTA.cpp | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/src/TaskOTA.cpp b/src/TaskOTA.cpp index d3bd60c7..28dcb853 100644 --- a/src/TaskOTA.cpp +++ b/src/TaskOTA.cpp @@ -13,35 +13,33 @@ OTATask::~OTATask() { bool OTATask::setup(System &system) { _ota.onStart([&]() { String type; - if (_ota.getCommand() == U_FLASH) + if (_ota.getCommand() == U_FLASH) { type = "sketch"; - else // U_SPIFFS + } else { // U_SPIFFS type = "filesystem"; - logPrintlnI("Start updating " + type); + } + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Start updating %s", type); }) - .onEnd([]() { - logPrintlnI(""); - logPrintlnI("OTA End"); + .onEnd([&]() { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "OTA End"); }) - .onProgress([](unsigned int progress, unsigned int total) { - logPrintI("Progress: "); - logPrintI(String(progress / (total / 100))); - logPrintlnI("%"); + .onProgress([&](unsigned int progress, unsigned int total) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Progress: %f", (progress / (total / 100))); }) - .onError([](ota_error_t error) { - logPrintE("Error["); - logPrintE(String(error)); - logPrintE("]: "); - if (error == OTA_AUTH_ERROR) - logPrintlnE("Auth Failed"); - else if (error == OTA_BEGIN_ERROR) - logPrintlnE("Begin Failed"); - else if (error == OTA_CONNECT_ERROR) - logPrintlnE("Connect Failed"); - else if (error == OTA_RECEIVE_ERROR) - logPrintlnE("Receive Failed"); - else if (error == OTA_END_ERROR) - logPrintlnE("End Failed"); + .onError([&](ota_error_t error) { + String error_str; + if (error == OTA_AUTH_ERROR) { + error_str = "Auth Failed"; + } else if (error == OTA_BEGIN_ERROR) { + error_str = "Begin Failed"; + } else if (error == OTA_CONNECT_ERROR) { + error_str = "Connect Failed"; + } else if (error == OTA_RECEIVE_ERROR) { + error_str = "Receive Failed"; + } else if (error == OTA_END_ERROR) { + error_str = "End Failed"; + } + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Error[%d]: %s", error, error_str); }); if (system.getUserConfig()->network.hostname.overwrite) { _ota.setHostname(system.getUserConfig()->network.hostname.name.c_str()); From 00603fe2c38e5364c06999b822fee79b1a4849e3 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 22:36:33 +0100 Subject: [PATCH 10/21] fixing router task --- src/TaskRouter.cpp | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/TaskRouter.cpp b/src/TaskRouter.cpp index 2ab3cd58..25cf38dd 100644 --- a/src/TaskRouter.cpp +++ b/src/TaskRouter.cpp @@ -16,7 +16,6 @@ RouterTask::~RouterTask() { } bool RouterTask::setup(System &system) { - // setup beacon _beacon_timer.setTimeout(system.getUserConfig()->beacon.timeout * 60 * 1000); _beaconMsg = std::shared_ptr(new APRSMessage()); @@ -30,7 +29,6 @@ bool RouterTask::setup(System &system) { } bool RouterTask::loop(System &system) { - // do routing if (!_fromModem.empty()) { std::shared_ptr modemMsg = _fromModem.getElement(); @@ -49,18 +47,19 @@ bool RouterTask::loop(System &system) { aprsIsMsg->setPath(path + "qAO," + system.getUserConfig()->callsign); - logPrintD("APRS-IS: "); - logPrintlnD(aprsIsMsg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: %s", aprsIsMsg->toString()); _toAprsIs.addElement(aprsIsMsg); } else { - logPrintlnD("APRS-IS: no forward => RFonly"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: no forward => RFonly"); } } else { - if (!system.getUserConfig()->aprs_is.active) - logPrintlnD("APRS-IS: disabled"); + if (!system.getUserConfig()->aprs_is.active) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: disabled"); + } - if (modemMsg->getSource() == system.getUserConfig()->callsign) - logPrintlnD("APRS-IS: no forward => own packet received"); + if (modemMsg->getSource() == system.getUserConfig()->callsign) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: no forward => own packet received"); + } } if (system.getUserConfig()->digi.active && modemMsg->getSource() != system.getUserConfig()->callsign) { @@ -72,8 +71,7 @@ bool RouterTask::loop(System &system) { // fixme digiMsg->setPath(system.getUserConfig()->callsign + "*"); - logPrintD("DIGI: "); - logPrintlnD(digiMsg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "DIGI: %s", digiMsg->toString()); _toModem.addElement(digiMsg); } @@ -82,8 +80,7 @@ bool RouterTask::loop(System &system) { // check for beacon if (_beacon_timer.check()) { - logPrintD("[" + timeString() + "] "); - logPrintlnD(_beaconMsg->encode()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s] %s", timeString(), _beaconMsg->encode()); if (system.getUserConfig()->aprs_is.active) _toAprsIs.addElement(_beaconMsg); @@ -93,7 +90,6 @@ bool RouterTask::loop(System &system) { } system.getDisplay().addFrame(std::shared_ptr(new TextFrame("BEACON", _beaconMsg->toString()))); - _beacon_timer.start(); } From 4a39c5e2f2e65a670718fcf479a1b01a23cbc3ff Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sat, 19 Mar 2022 23:51:18 +0100 Subject: [PATCH 11/21] fixing APRS-IS lib --- lib/APRS-IS/APRS-IS.cpp | 17 +++++++---------- lib/APRS-IS/APRS-IS.h | 15 +++++++++++---- src/TaskAprsIs.cpp | 8 +++++++- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/APRS-IS/APRS-IS.cpp b/lib/APRS-IS/APRS-IS.cpp index 6988ac93..7863bbf1 100644 --- a/lib/APRS-IS/APRS-IS.cpp +++ b/lib/APRS-IS/APRS-IS.cpp @@ -8,34 +8,32 @@ void APRS_IS::setup(const String &user, const String &passcode, const String &to _version = version; } -bool APRS_IS::connect(const String &server, const int port) { +APRS_IS::ConnectionStatus APRS_IS::connect(const String &server, const int port) { const String login = "user " + _user + " pass " + _passcode + " vers " + _tool_name + " " + _version + "\n\r"; return _connect(server, port, login); } -bool APRS_IS::connect(const String &server, const int port, const String &filter) { +APRS_IS::ConnectionStatus APRS_IS::connect(const String &server, const int port, const String &filter) { const String login = "user " + _user + " pass " + _passcode + " vers " + _tool_name + " " + _version + " filter " + filter + "\n\r"; return _connect(server, port, login); } -bool APRS_IS::_connect(const String &server, const int port, const String &login_line) { +APRS_IS::ConnectionStatus APRS_IS::_connect(const String &server, const int port, const String &login_line) { if (!_client.connect(server.c_str(), port)) { - logPrintlnE("Something went wrong on connecting! Is the server reachable?"); - return false; + return ERROR_CONNECTION; } sendMessage(login_line); while (true) { String line = _client.readStringUntil('\n'); if (line.indexOf("logresp") != -1) { if (line.indexOf("unverified") == -1) { - return true; + return SUCCESS; } else { - logPrintlnE("User can not be verified with passcode!"); - return false; + return ERROR_PASSCODE; } } } - return true; + return SUCCESS; } bool APRS_IS::connected() { @@ -76,7 +74,6 @@ std::shared_ptr APRS_IS::getAPRSMessage() { line = _client.readStringUntil('\n'); } if (line.startsWith("#")) { - logPrintlnD(line); return 0; } if (line.length() == 0) { diff --git a/lib/APRS-IS/APRS-IS.h b/lib/APRS-IS/APRS-IS.h index 00d27ca4..0aa06917 100644 --- a/lib/APRS-IS/APRS-IS.h +++ b/lib/APRS-IS/APRS-IS.h @@ -9,9 +9,16 @@ class APRS_IS { public: void setup(const String &user, const String &passcode, const String &tool_name, const String &version); - bool connect(const String &server, const int port); - bool connect(const String &server, const int port, const String &filter); - bool connected(); + enum ConnectionStatus + { + SUCCESS, + ERROR_CONNECTION, + ERROR_PASSCODE, + }; + + ConnectionStatus connect(const String &server, const int port); + ConnectionStatus connect(const String &server, const int port, const String &filter); + bool connected(); bool sendMessage(const String &message); bool sendMessage(const std::shared_ptr message); @@ -28,7 +35,7 @@ class APRS_IS { String _version; WiFiClient _client; - bool _connect(const String &server, const int port, const String &login_line); + ConnectionStatus _connect(const String &server, const int port, const String &login_line); }; #endif diff --git a/src/TaskAprsIs.cpp b/src/TaskAprsIs.cpp index 8aa80c4c..86ef766f 100644 --- a/src/TaskAprsIs.cpp +++ b/src/TaskAprsIs.cpp @@ -42,7 +42,13 @@ bool AprsIsTask::loop(System &system) { bool AprsIsTask::connect(System &system) { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "connecting to APRS-IS server: %s on port: %d", system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); - if (!_aprs_is.connect(system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port)) { + APRS_IS::ConnectionStatus status = _aprs_is.connect(system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); + if (status == APRS_IS::ERROR_CONNECTION) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Something went wrong on connecting! Is the server reachable?"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Connection failed."); + return false; + } else if (status == APRS_IS::ERROR_PASSCODE) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "User can not be verified with passcode!"); system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Connection failed."); return false; } From c1fc1c5cbff552a8fbf0c3b26b691e271cdd4cc4 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 00:03:43 +0100 Subject: [PATCH 12/21] fixing main --- src/LoRa_APRS_iGate.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 205e00d7..15c71fc3 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -19,7 +19,8 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.11.1" +#define VERSION "22.11.1" +#define MODULE_NAME "Main" String create_lat_aprs(double lat); String create_long_aprs(double lng); @@ -45,10 +46,10 @@ RouterTask routerTask(fromModem, toModem, toAprsIs, toMQTT); void setup() { Serial.begin(115200); - Logger::instance().setSerial(&Serial); + LoRaSystem.getLogger().setSerial(&Serial); delay(500); - logPrintlnI("LoRa APRS iGate by OE5BPA (Peter Buchegger)"); - logPrintlnI("Version: " VERSION); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "LoRa APRS iGate by OE5BPA (Peter Buchegger)"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Version: %s", VERSION); std::list boardConfigs; boardConfigs.push_back(&TTGO_LORA32_V1); @@ -68,28 +69,26 @@ void setup() { if (!boardConfig) { boardConfig = finder.searchBoardConfig(); if (!boardConfig) { - logPrintlnE("Board config not set and search failed!"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Board config not set and search failed!"); while (true) ; } else { userConfig.board = boardConfig->Name; confmg.writeConfiguration(userConfig); - logPrintlnI("will restart board now!"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "will restart board now!"); ESP.restart(); } } - logPrintI("Board "); - logPrintI(boardConfig->Name); - logPrintlnI(" loaded."); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Board %s loaded.", boardConfig->Name); if (boardConfig->Type == eTTGO_T_Beam_V1_0) { Wire.begin(boardConfig->OledSda, boardConfig->OledScl); PowerManagement powerManagement; if (!powerManagement.begin(Wire)) { - logPrintlnI("AXP192 init done!"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "AXP192 init done!"); } else { - logPrintlnE("AXP192 init failed!"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "AXP192 init failed!"); } powerManagement.activateLoRa(); powerManagement.activateOLED(); @@ -126,13 +125,13 @@ void setup() { LoRaSystem.getDisplay().showSpashScreen("LoRa APRS iGate", VERSION); if (userConfig.callsign == "NOCALL-10") { - logPrintlnE("You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "You have to change your settings in 'data/is-cfg.json' and upload it via 'Upload File System image'!"); LoRaSystem.getDisplay().showStatusScreen("ERROR", "You have to change your settings in 'data/is-cfg.json' and upload it via \"Upload File System image\"!"); while (true) ; } if ((!userConfig.aprs_is.active) && !(userConfig.digi.active)) { - logPrintlnE("No mode selected (iGate or Digi)! You have to activate one of iGate or Digi."); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "No mode selected (iGate or Digi)! You have to activate one of iGate or Digi."); LoRaSystem.getDisplay().showStatusScreen("ERROR", "No mode selected (iGate or Digi)! You have to activate one of iGate or Digi."); while (true) ; @@ -144,7 +143,7 @@ void setup() { } delay(5000); - logPrintlnI("setup done..."); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "setup done..."); } void loop() { From 121f90b59cc1500bb50b6f87712cb90948053bab Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 00:22:19 +0100 Subject: [PATCH 13/21] board finder fixed --- lib/BoardFinder/BoardFinder.cpp | 38 ++++++++++++++++----------------- lib/BoardFinder/BoardFinder.h | 8 ++++--- src/LoRa_APRS_iGate.cpp | 2 +- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/lib/BoardFinder/BoardFinder.cpp b/lib/BoardFinder/BoardFinder.cpp index 0e076e08..00cfc57e 100644 --- a/lib/BoardFinder/BoardFinder.cpp +++ b/lib/BoardFinder/BoardFinder.cpp @@ -2,6 +2,8 @@ #include #include +#define MODULE_NAME "BoardFinder" + BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t oledscl, uint8_t oledaddr, uint8_t oledreset, uint8_t lorasck, uint8_t loramiso, uint8_t loramosi, uint8_t loracs, uint8_t lorareset, uint8_t lorairq, bool needcheckpowerchip, bool powercheckstatus) : Name(name), Type(type), OledSda(oledsda), OledScl(oledscl), OledAddr(oledaddr), OledReset(oledreset), LoraSck(lorasck), LoraMiso(loramiso), LoraMosi(loramosi), LoraCS(loracs), LoraReset(lorareset), LoraIRQ(lorairq), needCheckPowerChip(needcheckpowerchip), powerCheckStatus(powercheckstatus) { } @@ -9,12 +11,12 @@ BoardConfig::BoardConfig(String name, BoardType type, uint8_t oledsda, uint8_t o BoardFinder::BoardFinder(const std::list &boardConfigs) : _boardConfigs(boardConfigs) { } -BoardConfig const *BoardFinder::searchBoardConfig() { - logPrintlnI("looking for a board config."); - logPrintlnI("searching for OLED..."); +BoardConfig const *BoardFinder::searchBoardConfig(logging::Logger &logger) { + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "looking for a board config."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "searching for OLED..."); for (BoardConfig const *boardconf : _boardConfigs) { - if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) { + if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf, logger) == boardconf->powerCheckStatus) { PowerManagement powerManagement; Wire.begin(boardconf->OledSda, boardconf->OledScl); powerManagement.begin(Wire); @@ -22,30 +24,28 @@ BoardConfig const *BoardFinder::searchBoardConfig() { } else if (boardconf->needCheckPowerChip) { continue; } - if (checkOledConfig(boardconf)) { - logPrintI("found a board config: "); - logPrintlnI(boardconf->Name); + if (checkOledConfig(boardconf, logger)) { + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name); return boardconf; } } - logPrintlnI("could not find OLED, will search for the modem now..."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "could not find OLED, will search for the modem now..."); for (BoardConfig const *boardconf : _boardConfigs) { - if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf) == boardconf->powerCheckStatus) { + if (boardconf->needCheckPowerChip && checkPowerConfig(boardconf, logger) == boardconf->powerCheckStatus) { PowerManagement powerManagement; Wire.begin(boardconf->OledSda, boardconf->OledScl); powerManagement.begin(Wire); powerManagement.activateLoRa(); } if (checkModemConfig(boardconf)) { - logPrintI("found a board config: "); - logPrintlnI(boardconf->Name); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name); return boardconf; } } - logPrintlnE("could not find a board config!"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "could not find a board config!"); return 0; } @@ -60,7 +60,7 @@ BoardConfig const *BoardFinder::getBoardConfig(String name) { return *elem; } -bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig) { +bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig, logging::Logger &logger) { if (boardConfig->OledReset > 0) { pinMode(boardConfig->OledReset, OUTPUT); digitalWrite(boardConfig->OledReset, HIGH); @@ -70,7 +70,7 @@ bool BoardFinder::checkOledConfig(BoardConfig const *boardConfig) { digitalWrite(boardConfig->OledReset, HIGH); } if (!Wire.begin(boardConfig->OledSda, boardConfig->OledScl)) { - logPrintlnW("issue with wire"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, MODULE_NAME, "issue with wire"); return false; } Wire.beginTransmission(boardConfig->OledAddr); @@ -107,9 +107,9 @@ bool BoardFinder::checkModemConfig(BoardConfig const *boardConfig) { return false; } -bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig) { +bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig, logging::Logger &logger) { if (!Wire.begin(boardConfig->OledSda, boardConfig->OledScl)) { - logPrintlnW("issue with wire"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, MODULE_NAME, "issue with wire"); return false; } Wire.beginTransmission(0x34); @@ -120,12 +120,12 @@ bool BoardFinder::checkPowerConfig(BoardConfig const *boardConfig) { int response = Wire.read(); Wire.endTransmission(); - logPrintlnD(String(response)); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "wire response: %d", response); if (response == 0x03) { - logPrintlnD("power chip found!"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "power chip found!"); return true; } - logPrintlnD("power chip NOT found"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "power chip NOT found"); return false; } diff --git a/lib/BoardFinder/BoardFinder.h b/lib/BoardFinder/BoardFinder.h index 142de6d2..ef65881d 100644 --- a/lib/BoardFinder/BoardFinder.h +++ b/lib/BoardFinder/BoardFinder.h @@ -8,6 +8,8 @@ #include #include +#include + enum BoardType { eHELTEC_WIFI_LORA_32_V1, @@ -47,16 +49,16 @@ class BoardFinder { public: explicit BoardFinder(const std::list &boardConfigs); - BoardConfig const *searchBoardConfig(); + BoardConfig const *searchBoardConfig(logging::Logger &logger); BoardConfig const *getBoardConfig(String name); private: const std::list &_boardConfigs; - bool checkOledConfig(BoardConfig const *boardConfig); + bool checkOledConfig(BoardConfig const *boardConfig, logging::Logger &logger); bool checkModemConfig(BoardConfig const *boardConfig); - bool checkPowerConfig(BoardConfig const *boardConfig); + bool checkPowerConfig(BoardConfig const *boardConfig, logging::Logger &logger); }; extern BoardConfig TTGO_LORA32_V1; diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 15c71fc3..2f5dfd12 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -67,7 +67,7 @@ void setup() { BoardFinder finder(boardConfigs); BoardConfig const *boardConfig = finder.getBoardConfig(userConfig.board); if (!boardConfig) { - boardConfig = finder.searchBoardConfig(); + boardConfig = finder.searchBoardConfig(LoRaSystem.getLogger()); if (!boardConfig) { LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Board config not set and search failed!"); while (true) From fd1034a3a000e0ac8417622d96c4c6ca37f8ec19 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 00:37:29 +0100 Subject: [PATCH 14/21] fixing configuration management --- lib/ConfigurationManagement/configuration.cpp | 20 ++++++++++--------- lib/ConfigurationManagement/configuration.h | 8 +++++--- src/LoRa_APRS_iGate.cpp | 6 +++--- src/project_configuration.h | 2 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/ConfigurationManagement/configuration.cpp b/lib/ConfigurationManagement/configuration.cpp index 5f505509..6734608f 100644 --- a/lib/ConfigurationManagement/configuration.cpp +++ b/lib/ConfigurationManagement/configuration.cpp @@ -2,12 +2,14 @@ #include #include -ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(FilePath) { +#define MODULE_NAME "ConfigurationManagement" + +ConfigurationManagement::ConfigurationManagement(logging::Logger &logger, String FilePath) : mFilePath(FilePath) { if (!SPIFFS.begin(true)) { - logPrintlnI("Mounting SPIFFS was not possible. Trying to format SPIFFS..."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Mounting SPIFFS was not possible. Trying to format SPIFFS..."); SPIFFS.format(); if (!SPIFFS.begin()) { - logPrintlnE("Formating SPIFFS was not okay!"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Formating SPIFFS was not okay!"); } } } @@ -15,16 +17,16 @@ ConfigurationManagement::ConfigurationManagement(String FilePath) : mFilePath(Fi ConfigurationManagement::~ConfigurationManagement() { } -void ConfigurationManagement::readConfiguration(Configuration &conf) { +void ConfigurationManagement::readConfiguration(logging::Logger &logger, Configuration &conf) { File file = SPIFFS.open(mFilePath); if (!file) { - logPrintlnE("Failed to open file for reading, using default configuration."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Failed to open file for reading, using default configuration."); return; } DynamicJsonDocument data(2048); DeserializationError error = deserializeJson(data, file); if (error) { - logPrintlnW("Failed to read file, using default configuration."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_WARN, MODULE_NAME, "Failed to read file, using default configuration."); } // serializeJson(data, Serial); // Serial.println(); @@ -33,13 +35,13 @@ void ConfigurationManagement::readConfiguration(Configuration &conf) { readProjectConfiguration(data, conf); // update config in memory to get the new fields: - writeConfiguration(conf); + writeConfiguration(logger, conf); } -void ConfigurationManagement::writeConfiguration(Configuration &conf) { +void ConfigurationManagement::writeConfiguration(logging::Logger &logger, Configuration &conf) { File file = SPIFFS.open(mFilePath, "w"); if (!file) { - logPrintlnE("Failed to open file for writing..."); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, MODULE_NAME, "Failed to open file for writing..."); return; } DynamicJsonDocument data(2048); diff --git a/lib/ConfigurationManagement/configuration.h b/lib/ConfigurationManagement/configuration.h index 6ebcf75b..4d988cb4 100644 --- a/lib/ConfigurationManagement/configuration.h +++ b/lib/ConfigurationManagement/configuration.h @@ -9,15 +9,17 @@ #include #endif +#include + class Configuration; class ConfigurationManagement { public: - explicit ConfigurationManagement(String FilePath); + explicit ConfigurationManagement(logging::Logger &logger, String FilePath); virtual ~ConfigurationManagement(); - void readConfiguration(Configuration &conf); - void writeConfiguration(Configuration &conf); + void readConfiguration(logging::Logger &logger, Configuration &conf); + void writeConfiguration(logging::Logger &logger, Configuration &conf); private: virtual void readProjectConfiguration(DynamicJsonDocument &data, Configuration &conf) = 0; diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 2f5dfd12..41711382 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -61,8 +61,8 @@ void setup() { boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V1); boardConfigs.push_back(&HELTEC_WIFI_LORA_32_V2); - ProjectConfigurationManagement confmg; - confmg.readConfiguration(userConfig); + ProjectConfigurationManagement confmg(LoRaSystem.getLogger()); + confmg.readConfiguration(LoRaSystem.getLogger(), userConfig); BoardFinder finder(boardConfigs); BoardConfig const *boardConfig = finder.getBoardConfig(userConfig.board); @@ -74,7 +74,7 @@ void setup() { ; } else { userConfig.board = boardConfig->Name; - confmg.writeConfiguration(userConfig); + confmg.writeConfiguration(LoRaSystem.getLogger(), userConfig); LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "will restart board now!"); ESP.restart(); } diff --git a/src/project_configuration.h b/src/project_configuration.h index df83acbf..4fe78bd9 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -146,7 +146,7 @@ class Configuration { class ProjectConfigurationManagement : public ConfigurationManagement { public: - explicit ProjectConfigurationManagement() : ConfigurationManagement("/is-cfg.json") { + explicit ProjectConfigurationManagement(logging::Logger &logger) : ConfigurationManagement(logger, "/is-cfg.json") { } virtual ~ProjectConfigurationManagement() { } From 11b392b3098fa2cf5ef1ce544559a1e399e9ece8 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 00:45:30 +0100 Subject: [PATCH 15/21] wifi task fixed --- src/TaskWifi.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/TaskWifi.cpp b/src/TaskWifi.cpp index aa028764..fb01baf9 100644 --- a/src/TaskWifi.cpp +++ b/src/TaskWifi.cpp @@ -31,8 +31,7 @@ bool WifiTask::setup(System &system) { } for (Configuration::Wifi::AP ap : system.getUserConfig()->wifi.APs) { - logPrintD("Looking for AP: "); - logPrintlnD(ap.SSID); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Looking for AP: %s", ap.SSID); _wiFiMulti.addAP(ap.SSID.c_str(), ap.password.c_str()); } return true; @@ -42,14 +41,13 @@ bool WifiTask::loop(System &system) { const uint8_t wifi_status = _wiFiMulti.run(); if (wifi_status != WL_CONNECTED) { system.connectedViaWifiEth(false); - logPrintlnE("WiFi not connected!"); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "WiFi not connected!"); _oldWifiStatus = wifi_status; _stateInfo = "WiFi not connected"; _state = Error; return false; } else if (wifi_status != _oldWifiStatus) { - logPrintD("IP address: "); - logPrintlnD(WiFi.localIP().toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "IP address: %s", WiFi.localIP().toString()); _oldWifiStatus = wifi_status; return false; } From 4aa8a3197d2354c3a471ea846698d1e9d0c5be1a Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 01:03:26 +0100 Subject: [PATCH 16/21] fixing WifiEvent function --- src/TaskEth.cpp | 65 +++++++++++++++++++++++-------------------------- src/TaskEth.h | 1 + 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index 720856e3..d5a15eec 100644 --- a/src/TaskEth.cpp +++ b/src/TaskEth.cpp @@ -6,67 +6,62 @@ #include "TaskEth.h" #include "project_configuration.h" -volatile bool eth_connected = false; +#define WIFI_EVENT "WiFiEvent" + +volatile bool eth_connected = false; +logging::Logger *_logger; + +void setWiFiLogger(logging::Logger *logger) { + _logger = logger; +} void WiFiEvent(WiFiEvent_t event) { switch (event) { case SYSTEM_EVENT_STA_START: - logPrintlnI("WiFi Started"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Started"); break; case SYSTEM_EVENT_STA_CONNECTED: - logPrintlnI("WiFi Connected"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Connected"); break; case SYSTEM_EVENT_STA_GOT_IP: - logPrintI("WiFi MAC: "); - logPrintI(WiFi.macAddress()); - logPrintI(", IPv4: "); - logPrintI(WiFi.localIP().toString()); - logPrintI(", Gateway: "); - logPrintI(WiFi.gatewayIP().toString()); - logPrintI(", DNS1: "); - logPrintI(WiFi.dnsIP().toString()); - logPrintI(", DNS2: "); - logPrintlnI(WiFi.dnsIP(1).toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi MAC: %s", WiFi.macAddress()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", WiFi.localIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", WiFi.gatewayIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", WiFi.dnsIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", WiFi.dnsIP(1).toString()); break; case SYSTEM_EVENT_STA_DISCONNECTED: - logPrintlnW("WiFi Disconnected"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Disconnected"); break; case SYSTEM_EVENT_STA_STOP: - logPrintlnW("WiFi Stopped"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Stopped"); break; case SYSTEM_EVENT_ETH_START: - logPrintlnI("ETH Started"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Started"); break; case SYSTEM_EVENT_ETH_CONNECTED: - logPrintlnI("ETH Connected"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH Connected"); break; case SYSTEM_EVENT_ETH_GOT_IP: - logPrintI("Hostname: "); - logPrintI(ETH.getHostname()); - logPrintI(", ETH MAC: "); - logPrintI(ETH.macAddress()); - logPrintI(", IPv4: "); - logPrintI(ETH.localIP().toString()); - logPrintI(", Gateway: "); - logPrintI(ETH.gatewayIP().toString()); - logPrintI(", DNS1: "); - logPrintI(ETH.dnsIP().toString()); - logPrintI(", DNS2: "); - logPrintI(ETH.dnsIP(1).toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Hostname: %s", ETH.getHostname()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH MAC: %s", ETH.macAddress()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", ETH.localIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", ETH.gatewayIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", ETH.dnsIP().toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", ETH.dnsIP(1).toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Hostname: %s", ETH.getHostname()); if (ETH.fullDuplex()) { - logPrintI(", FULL_DUPLEX"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "FULL_DUPLEX"); } - logPrintI(", "); - logPrintI(String(ETH.linkSpeed())); - logPrintlnI("Mbps"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "%dMbps", ETH.linkSpeed()); eth_connected = true; break; case SYSTEM_EVENT_ETH_DISCONNECTED: - logPrintlnW("ETH Disconnected"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_WARN, WIFI_EVENT, "ETH Disconnected"); eth_connected = false; break; case SYSTEM_EVENT_ETH_STOP: - logPrintlnW("ETH Stopped"); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_WARN, WIFI_EVENT, "ETH Stopped"); eth_connected = false; break; default: diff --git a/src/TaskEth.h b/src/TaskEth.h index 4a63d3fd..50f1d630 100644 --- a/src/TaskEth.h +++ b/src/TaskEth.h @@ -3,6 +3,7 @@ #include +void setWiFiLogger(logging::Logger *logger); void WiFiEvent(WiFiEvent_t event); class EthTask : public Task { From 006b29d17791c411477d943630fe4b3702d1f19e Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 01:03:42 +0100 Subject: [PATCH 17/21] fixing missing function --- lib/System/System.cpp | 4 ++++ src/LoRa_APRS_iGate.cpp | 1 + 2 files changed, 5 insertions(+) diff --git a/lib/System/System.cpp b/lib/System/System.cpp index e0747452..18b89d45 100644 --- a/lib/System/System.cpp +++ b/lib/System/System.cpp @@ -38,3 +38,7 @@ bool System::isWifiEthConnected() const { void System::connectedViaWifiEth(bool status) { _isWifiEthConnected = status; } + +logging::Logger &System::getLogger() { + return _logger; +} diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 41711382..d795da2a 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -47,6 +47,7 @@ RouterTask routerTask(fromModem, toModem, toAprsIs, toMQTT); void setup() { Serial.begin(115200); LoRaSystem.getLogger().setSerial(&Serial); + setWiFiLogger(&LoRaSystem.getLogger()); delay(500); LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "LoRa APRS iGate by OE5BPA (Peter Buchegger)"); LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Version: %s", VERSION); From 6839db20ca061362936e815fb896fbfb66dca17f Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 01:16:47 +0100 Subject: [PATCH 18/21] fix version check script --- scripts/check_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_version.py b/scripts/check_version.py index 95e29c0f..df9914f4 100755 --- a/scripts/check_version.py +++ b/scripts/check_version.py @@ -11,7 +11,7 @@ with open("src/LoRa_APRS_iGate.cpp") as f: for line in f: if line.startswith("#define VERSION"): - version = line.strip().split(" ")[2].replace('"', "") + version = line.strip().split(" ")[-1].replace('"', "") version_split = version.split(".") version_year = int(version_split[0]) From 4bd1c46335d8b75e09435d62535ae44dc60b76e8 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 10:56:06 +0100 Subject: [PATCH 19/21] fixing String in fstring --- lib/BoardFinder/BoardFinder.cpp | 4 ++-- lib/System/TaskManager.cpp | 4 ++-- src/LoRa_APRS_iGate.cpp | 2 +- src/TaskAprsIs.cpp | 2 +- src/TaskEth.cpp | 20 ++++++++++---------- src/TaskFTP.cpp | 2 +- src/TaskMQTT.cpp | 6 +++--- src/TaskModem.cpp | 10 +++++----- src/TaskNTP.cpp | 2 +- src/TaskOTA.cpp | 4 ++-- src/TaskRouter.cpp | 6 +++--- src/TaskWifi.cpp | 4 ++-- 12 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/BoardFinder/BoardFinder.cpp b/lib/BoardFinder/BoardFinder.cpp index 00cfc57e..2276da50 100644 --- a/lib/BoardFinder/BoardFinder.cpp +++ b/lib/BoardFinder/BoardFinder.cpp @@ -25,7 +25,7 @@ BoardConfig const *BoardFinder::searchBoardConfig(logging::Logger &logger) { continue; } if (checkOledConfig(boardconf, logger)) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name.c_str()); return boardconf; } } @@ -40,7 +40,7 @@ BoardConfig const *BoardFinder::searchBoardConfig(logging::Logger &logger) { powerManagement.activateLoRa(); } if (checkModemConfig(boardconf)) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "found a board config: %s", boardconf->Name.c_str()); return boardconf; } } diff --git a/lib/System/TaskManager.cpp b/lib/System/TaskManager.cpp index d149e2fe..b643c1ec 100644 --- a/lib/System/TaskManager.cpp +++ b/lib/System/TaskManager.cpp @@ -24,11 +24,11 @@ std::list TaskManager::getTasks() { bool TaskManager::setup(System &system) { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "will setup all tasks..."); for (Task *elem : _alwaysRunTasks) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName().c_str()); elem->setup(system); } for (Task *elem : _tasks) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, MODULE_NAME, "call setup for %s", elem->getName().c_str()); elem->setup(system); } _nextTask = _tasks.begin(); diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index d795da2a..74a313de 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -81,7 +81,7 @@ void setup() { } } - LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Board %s loaded.", boardConfig->Name); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "Board %s loaded.", boardConfig->Name.c_str()); if (boardConfig->Type == eTTGO_T_Beam_V1_0) { Wire.begin(boardConfig->OledSda, boardConfig->OledScl); diff --git a/src/TaskAprsIs.cpp b/src/TaskAprsIs.cpp index 86ef766f..680a2c44 100644 --- a/src/TaskAprsIs.cpp +++ b/src/TaskAprsIs.cpp @@ -41,7 +41,7 @@ bool AprsIsTask::loop(System &system) { } bool AprsIsTask::connect(System &system) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "connecting to APRS-IS server: %s on port: %d", system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "connecting to APRS-IS server: %s on port: %d", system.getUserConfig()->aprs_is.server.c_str(), system.getUserConfig()->aprs_is.port); APRS_IS::ConnectionStatus status = _aprs_is.connect(system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port); if (status == APRS_IS::ERROR_CONNECTION) { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Something went wrong on connecting! Is the server reachable?"); diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index d5a15eec..03f211fd 100644 --- a/src/TaskEth.cpp +++ b/src/TaskEth.cpp @@ -24,11 +24,11 @@ void WiFiEvent(WiFiEvent_t event) { _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Connected"); break; case SYSTEM_EVENT_STA_GOT_IP: - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi MAC: %s", WiFi.macAddress()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", WiFi.localIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", WiFi.gatewayIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", WiFi.dnsIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", WiFi.dnsIP(1).toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi MAC: %s", WiFi.macAddress().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", WiFi.localIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", WiFi.gatewayIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", WiFi.dnsIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", WiFi.dnsIP(1).toString().c_str()); break; case SYSTEM_EVENT_STA_DISCONNECTED: _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "WiFi Disconnected"); @@ -44,11 +44,11 @@ void WiFiEvent(WiFiEvent_t event) { break; case SYSTEM_EVENT_ETH_GOT_IP: _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Hostname: %s", ETH.getHostname()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH MAC: %s", ETH.macAddress()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", ETH.localIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", ETH.gatewayIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", ETH.dnsIP().toString()); - _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", ETH.dnsIP(1).toString()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "ETH MAC: %s", ETH.macAddress().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "IPv4: %s", ETH.localIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Gateway: %s", ETH.gatewayIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS1: %s", ETH.dnsIP().toString().c_str()); + _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "DNS2: %s", ETH.dnsIP(1).toString().c_str()); _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "Hostname: %s", ETH.getHostname()); if (ETH.fullDuplex()) { _logger->log(logging::LoggerLevel::LOGGER_LEVEL_INFO, WIFI_EVENT, "FULL_DUPLEX"); diff --git a/src/TaskFTP.cpp b/src/TaskFTP.cpp index e4a6037b..86e0bef6 100644 --- a/src/TaskFTP.cpp +++ b/src/TaskFTP.cpp @@ -14,7 +14,7 @@ FTPTask::~FTPTask() { bool FTPTask::setup(System &system) { for (Configuration::Ftp::User user : system.getUserConfig()->ftp.users) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Adding user to FTP Server: %s", user.name); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Adding user to FTP Server: %s", user.name.c_str()); _ftpServer.addUser(user.name, user.password); } _ftpServer.addFilesystem("SPIFFS", &SPIFFS); diff --git a/src/TaskMQTT.cpp b/src/TaskMQTT.cpp index aa0a7a0c..fe6ee3fb 100644 --- a/src/TaskMQTT.cpp +++ b/src/TaskMQTT.cpp @@ -46,7 +46,7 @@ bool MQTTTask::loop(System &system) { topic = topic + "/"; } topic = topic + system.getUserConfig()->callsign; - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Send MQTT with topic: '%s', data: %s", topic, r); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Send MQTT with topic: '%s', data: %s", topic.c_str(), r.c_str()); _MQTT.publish(topic.c_str(), r.c_str()); } _MQTT.loop(); @@ -54,9 +54,9 @@ bool MQTTTask::loop(System &system) { } bool MQTTTask::connect(System &system) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker: %s on port %d", system.getUserConfig()->mqtt.server, system.getUserConfig()->mqtt.port); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker: %s on port %d", system.getUserConfig()->mqtt.server.c_str(), system.getUserConfig()->mqtt.port); if (_MQTT.connect(system.getUserConfig()->callsign.c_str(), system.getUserConfig()->mqtt.name.c_str(), system.getUserConfig()->mqtt.password.c_str())) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connected to MQTT broker as: %s", system.getUserConfig()->callsign); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connected to MQTT broker as: %s", system.getUserConfig()->callsign.c_str()); return true; } system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Connecting to MQTT broker failed. Try again later."); diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index 645626b2..ca0784dd 100644 --- a/src/TaskModem.cpp +++ b/src/TaskModem.cpp @@ -39,19 +39,19 @@ bool ModemTask::setup(System &system) { bool ModemTask::loop(System &system) { if (_lora_aprs.checkMessage()) { std::shared_ptr msg = _lora_aprs.getMessage(); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %d and SNR %f", timeString(), msg->toString(), _lora_aprs.packetRssi(), _lora_aprs.packetSnr()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Received packet '%s' with RSSI %d and SNR %f", timeString().c_str(), msg->toString().c_str(), _lora_aprs.packetRssi(), _lora_aprs.packetSnr()); _fromModem.addElement(msg); - system.getDisplay().addFrame(std::shared_ptr(new TextFrame("LoRa", msg->toString()))); + system.getDisplay().addFrame(std::shared_ptr(new TextFrame("LoRa", msg->toString().c_str()))); } if (!_toModem.empty()) { std::shared_ptr msg = _toModem.getElement(); if (system.getUserConfig()->lora.tx_enable) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString(), msg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str()); _lora_aprs.sendMessage(msg); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString().c_str()); } else { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] NOT transmitting packet as TX is not enabled '%s'", timeString(), msg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] NOT transmitting packet as TX is not enabled '%s'", timeString().c_str(), msg->toString().c_str()); } } diff --git a/src/TaskNTP.cpp b/src/TaskNTP.cpp index c012ae83..569eeccb 100644 --- a/src/TaskNTP.cpp +++ b/src/TaskNTP.cpp @@ -27,7 +27,7 @@ bool NTPTask::loop(System &system) { } if (_ntpClient.update()) { setTime(_ntpClient.getEpochTime()); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Current time: %s", _ntpClient.getFormattedTime()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Current time: %s", _ntpClient.getFormattedTime().c_str()); } _stateInfo = _ntpClient.getFormattedTime(); _state = Okay; diff --git a/src/TaskOTA.cpp b/src/TaskOTA.cpp index 28dcb853..89cbf7fe 100644 --- a/src/TaskOTA.cpp +++ b/src/TaskOTA.cpp @@ -18,7 +18,7 @@ bool OTATask::setup(System &system) { } else { // U_SPIFFS type = "filesystem"; } - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Start updating %s", type); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "Start updating %s", type.c_str()); }) .onEnd([&]() { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "OTA End"); @@ -39,7 +39,7 @@ bool OTATask::setup(System &system) { } else if (error == OTA_END_ERROR) { error_str = "End Failed"; } - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Error[%d]: %s", error, error_str); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, getName(), "Error[%d]: %s", error, error_str.c_str()); }); if (system.getUserConfig()->network.hostname.overwrite) { _ota.setHostname(system.getUserConfig()->network.hostname.name.c_str()); diff --git a/src/TaskRouter.cpp b/src/TaskRouter.cpp index 25cf38dd..96b13dca 100644 --- a/src/TaskRouter.cpp +++ b/src/TaskRouter.cpp @@ -47,7 +47,7 @@ bool RouterTask::loop(System &system) { aprsIsMsg->setPath(path + "qAO," + system.getUserConfig()->callsign); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: %s", aprsIsMsg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: %s", aprsIsMsg->toString().c_str()); _toAprsIs.addElement(aprsIsMsg); } else { system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "APRS-IS: no forward => RFonly"); @@ -71,7 +71,7 @@ bool RouterTask::loop(System &system) { // fixme digiMsg->setPath(system.getUserConfig()->callsign + "*"); - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "DIGI: %s", digiMsg->toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "DIGI: %s", digiMsg->toString().c_str()); _toModem.addElement(digiMsg); } @@ -80,7 +80,7 @@ bool RouterTask::loop(System &system) { // check for beacon if (_beacon_timer.check()) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s] %s", timeString(), _beaconMsg->encode()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, getName(), "[%s] %s", timeString().c_str(), _beaconMsg->encode().c_str()); if (system.getUserConfig()->aprs_is.active) _toAprsIs.addElement(_beaconMsg); diff --git a/src/TaskWifi.cpp b/src/TaskWifi.cpp index fb01baf9..d7e18683 100644 --- a/src/TaskWifi.cpp +++ b/src/TaskWifi.cpp @@ -31,7 +31,7 @@ bool WifiTask::setup(System &system) { } for (Configuration::Wifi::AP ap : system.getUserConfig()->wifi.APs) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Looking for AP: %s", ap.SSID); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "Looking for AP: %s", ap.SSID.c_str()); _wiFiMulti.addAP(ap.SSID.c_str(), ap.password.c_str()); } return true; @@ -47,7 +47,7 @@ bool WifiTask::loop(System &system) { _state = Error; return false; } else if (wifi_status != _oldWifiStatus) { - system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "IP address: %s", WiFi.localIP().toString()); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "IP address: %s", WiFi.localIP().toString().c_str()); _oldWifiStatus = wifi_status; return false; } From d6bc7e9788c556f4e2bceb1594c61d96d7a81f76 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 12:16:37 +0100 Subject: [PATCH 20/21] add syslog config --- data/is-cfg.json | 7 ++++++- src/LoRa_APRS_iGate.cpp | 5 +++++ src/project_configuration.cpp | 8 ++++++++ src/project_configuration.h | 19 +++++++++++++++++-- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/data/is-cfg.json b/data/is-cfg.json index f2781664..942f7505 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -49,7 +49,7 @@ "spreading_factor": 12, "signal_bandwidth": 125000, "coding_rate4": 5, - "tx_enable": true + "tx_enable": false }, "display": { "always_on": true, @@ -74,5 +74,10 @@ "password": "", "topic": "LoraAPRS/Data" }, + "syslog": { + "active": true, + "server": "syslog.lora-aprs.info", + "port": 514 + }, "ntp_server": "pool.ntp.org" } diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 74a313de..8f7b8c9c 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -149,6 +149,11 @@ void setup() { void loop() { LoRaSystem.getTaskManager().loop(LoRaSystem); + if (LoRaSystem.isWifiEthConnected()) { + if (LoRaSystem.getUserConfig()->syslog.active) { + LoRaSystem.getLogger().setSyslogServer(LoRaSystem.getUserConfig()->syslog.server, LoRaSystem.getUserConfig()->syslog.port, LoRaSystem.getUserConfig()->callsign); + } + } } String create_lat_aprs(double lat) { diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index a462c5b6..6deebf51 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -86,6 +86,11 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.mqtt.password = data["mqtt"]["password"].as(); conf.mqtt.topic = data["mqtt"]["topic"].as(); } + if (data.containsKey("syslog")) { + conf.syslog.active = data["syslog"]["active"] | true; + conf.syslog.server = data["syslog"]["server"].as(); + conf.syslog.port = data["syslog"]["port"] | 514; + } if (data.containsKey("ntp_server")) conf.ntpServer = data["ntp_server"].as(); @@ -149,6 +154,9 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["mqtt"]["name"] = conf.mqtt.name; data["mqtt"]["password"] = conf.mqtt.password; data["mqtt"]["topic"] = conf.mqtt.topic; + data["syslog"]["active"] = conf.syslog.active; + data["syslog"]["server"] = conf.syslog.server; + data["syslog"]["port"] = conf.syslog.port; data["ntp_server"] = conf.ntpServer; data["board"] = conf.board; diff --git a/src/project_configuration.h b/src/project_configuration.h index 4fe78bd9..234a83a4 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -120,6 +120,9 @@ class Configuration { class MQTT { public: + MQTT() : active(false), server(""), port(1883), name(""), password(""), topic("LoraAPRS/Data") { + } + bool active; String server; uint16_t port; @@ -128,7 +131,18 @@ class Configuration { String topic; }; - Configuration() : callsign("NOCALL-10"), board(""), ntpServer("pool.ntp.org"){}; + class Syslog { + public: + Syslog() : active(true), server("syslog.lora-aprs.info"), port(514) { + } + + bool active; + String server; + int port; + }; + + Configuration() : callsign("NOCALL-10"), ntpServer("pool.ntp.org"), board("") { + } String callsign; Network network; @@ -140,8 +154,9 @@ class Configuration { Display display; Ftp ftp; MQTT mqtt; - String board; + Syslog syslog; String ntpServer; + String board; }; class ProjectConfigurationManagement : public ConfigurationManagement { From 7d240680b930709cc7fd26853def370ed4f71da9 Mon Sep 17 00:00:00 2001 From: Peter Buchegger Date: Sun, 20 Mar 2022 12:18:21 +0100 Subject: [PATCH 21/21] version push --- src/LoRa_APRS_iGate.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 8f7b8c9c..163146de 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -19,7 +19,7 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.11.1" +#define VERSION "22.11.2" #define MODULE_NAME "Main" String create_lat_aprs(double lat);