diff --git a/data/is-cfg.json b/data/is-cfg.json index e9c5f7e..37e449b 100644 --- a/data/is-cfg.json +++ b/data/is-cfg.json @@ -50,7 +50,7 @@ "spreading_factor": 12, "signal_bandwidth": 125000, "coding_rate4": 5, - "txok": true + "tx_enable": false }, "display": { "always_on": true, @@ -75,5 +75,10 @@ "password": "", "topic": "LoraAPRS/Data" }, + "syslog": { + "active": true, + "server": "syslog.lora-aprs.info", + "port": 514 + }, "ntp_server": "pool.ntp.org" } diff --git a/lib/APRS-IS/APRS-IS.cpp b/lib/APRS-IS/APRS-IS.cpp index 6988ac9..7863bbf 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 00d27ca..0aa0691 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 @@ private: 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/lib/BoardFinder/BoardFinder.cpp b/lib/BoardFinder/BoardFinder.cpp index 0990d86..8a39ae6 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, uint8_t gpsrx, uint8_t gpstx, 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), GpsRx(gpsrx), GpsTx(gpstx), 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.c_str()); 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.c_str()); 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 fa68451..c833fab 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, @@ -49,16 +51,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/lib/ConfigurationManagement/configuration.cpp b/lib/ConfigurationManagement/configuration.cpp index 5f50550..6734608 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 6ebcf75..4d988cb 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/lib/System/System.cpp b/lib/System/System.cpp index e074745..18b89d4 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/lib/System/System.h b/lib/System/System.h index 376741b..6c7e9d4 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 @@ public: Display & getDisplay(); bool isWifiEthConnected() const; void connectedViaWifiEth(bool status); + logging::Logger & getLogger(); private: BoardConfig const * _boardConfig; @@ -29,6 +31,7 @@ private: TaskManager _taskManager; Display _display; bool _isWifiEthConnected; + logging::Logger _logger; }; #endif diff --git a/lib/System/TaskManager.cpp b/lib/System/TaskManager.cpp index d524ad0..b643c1e 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().c_str()); 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().c_str()); 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); } diff --git a/platformio.ini b/platformio.ini index ce8560b..e9d1555 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 diff --git a/scripts/check_version.py b/scripts/check_version.py index 95e29c0..df9914f 100755 --- a/scripts/check_version.py +++ b/scripts/check_version.py @@ -11,7 +11,7 @@ version = None 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]) diff --git a/src/LoRa_APRS_iGate.cpp b/src/LoRa_APRS_iGate.cpp index 1996af2..92bd27a 100644 --- a/src/LoRa_APRS_iGate.cpp +++ b/src/LoRa_APRS_iGate.cpp @@ -20,7 +20,8 @@ #include "TaskWifi.h" #include "project_configuration.h" -#define VERSION "22.11.0" +#define VERSION "22.11.2" +#define MODULE_NAME "Main" String create_lat_aprs(double lat); String create_long_aprs(double lng); @@ -47,10 +48,11 @@ BeaconTask beaconTask(toModem, toAprsIs); void setup() { Serial.begin(115200); - Logger::instance().setSerial(&Serial); + LoRaSystem.getLogger().setSerial(&Serial); + setWiFiLogger(&LoRaSystem.getLogger()); 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); @@ -62,36 +64,34 @@ 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); if (!boardConfig) { - boardConfig = finder.searchBoardConfig(); + boardConfig = finder.searchBoardConfig(LoRaSystem.getLogger()); 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!"); + confmg.writeConfiguration(LoRaSystem.getLogger(), userConfig); + 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.c_str()); 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(); @@ -133,13 +133,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) ; @@ -151,9 +151,16 @@ void setup() { } delay(5000); - logPrintlnI("setup done..."); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "setup done..."); } +volatile bool syslogSet = false; + void loop() { LoRaSystem.getTaskManager().loop(LoRaSystem); + if (LoRaSystem.isWifiEthConnected() && LoRaSystem.getUserConfig()->syslog.active && !syslogSet) { + LoRaSystem.getLogger().setSyslogServer(LoRaSystem.getUserConfig()->syslog.server, LoRaSystem.getUserConfig()->syslog.port, LoRaSystem.getUserConfig()->callsign); + LoRaSystem.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_INFO, MODULE_NAME, "System connected after a restart to the network, syslog server set"); + syslogSet = true; + } } diff --git a/src/TaskAprsIs.cpp b/src/TaskAprsIs.cpp index b96b06e..680a2c4 100644 --- a/src/TaskAprsIs.cpp +++ b/src/TaskAprsIs.cpp @@ -40,15 +40,18 @@ 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)); - if (!_aprs_is.connect(system.getUserConfig()->aprs_is.server, system.getUserConfig()->aprs_is.port)) { - logPrintlnE("Connection failed."); +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.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?"); + 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; } - 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 de75fec..30679db 100644 --- a/src/TaskAprsIs.h +++ b/src/TaskAprsIs.h @@ -19,7 +19,7 @@ private: TaskQueue> &_toAprsIs; - bool connect(const System &system); + bool connect(System &system); }; #endif diff --git a/src/TaskEth.cpp b/src/TaskEth.cpp index 720856e..03f211f 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().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: - 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().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()) { - 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 4a63d3f..50f1d63 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 { diff --git a/src/TaskFTP.cpp b/src/TaskFTP.cpp index d9615cf..86e0bef 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.c_str()); _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) { diff --git a/src/TaskMQTT.cpp b/src/TaskMQTT.cpp index a4d0aa4..fe6ee3f 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.c_str(), r.c_str()); _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.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())) { - 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.c_str()); 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 88fa35e..d388075 100644 --- a/src/TaskMQTT.h +++ b/src/TaskMQTT.h @@ -20,7 +20,7 @@ private: WiFiClient _client; PubSubClient _MQTT; - bool connect(const System &system); + bool connect(System &system); }; #endif diff --git a/src/TaskModem.cpp b/src/TaskModem.cpp index 50b9035..ca0784d 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,31 +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().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(); - logPrintD("[" + timeString() + "] "); - if (system.getUserConfig()->lora.txok) { - logPrintD("Transmitting packet '"); - logPrintD(msg->toString()); + if (system.getUserConfig()->lora.tx_enable) { + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] Transmitting packet '%s'", timeString().c_str(), msg->toString().c_str()); _lora_aprs.sendMessage(msg); - logPrintlnD(String(" TXDone")); + system.getLogger().log(logging::LoggerLevel::LOGGER_LEVEL_DEBUG, getName(), "[%s] TX done", timeString().c_str()); } else { - logPrintD("NOT Transmitting packet '"); - logPrintD(msg->toString()); - logPrintlnD(String(" TXNG")); + 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 14b3808..569eecc 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().c_str()); } _stateInfo = _ntpClient.getFormattedTime(); _state = Okay; diff --git a/src/TaskOTA.cpp b/src/TaskOTA.cpp index d3bd60c..89cbf7f 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.c_str()); }) - .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.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 26d23ab..dc9da8a 100644 --- a/src/TaskRouter.cpp +++ b/src/TaskRouter.cpp @@ -17,7 +17,6 @@ bool RouterTask::setup(System &system) { } bool RouterTask::loop(System &system) { - // do routing if (!_fromModem.empty()) { std::shared_ptr modemMsg = _fromModem.getElement(); @@ -36,18 +35,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().c_str()); _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) { @@ -59,8 +59,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().c_str()); _toModem.addElement(digiMsg); } diff --git a/src/TaskWifi.cpp b/src/TaskWifi.cpp index aa02876..d7e1868 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.c_str()); _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().c_str()); _oldWifiStatus = wifi_status; return false; } diff --git a/src/project_configuration.cpp b/src/project_configuration.cpp index 829fdc0..231fe03 100644 --- a/src/project_configuration.cpp +++ b/src/project_configuration.cpp @@ -59,7 +59,7 @@ void ProjectConfigurationManagement::readProjectConfiguration(DynamicJsonDocumen conf.lora.spreadingFactor = data["lora"]["spreading_factor"] | 12; conf.lora.signalBandwidth = data["lora"]["signal_bandwidth"] | 125000; conf.lora.codingRate4 = data["lora"]["coding_rate4"] | 5; - conf.lora.txok = data["lora"]["txok"] | false; + conf.lora.tx_enable = data["lora"]["tx_enable"] | true; conf.display.alwaysOn = data["display"]["always_on"] | true; conf.display.timeout = data["display"]["timeout"] | 10; conf.display.overwritePin = data["display"]["overwrite_pin"] | 0; @@ -87,6 +87,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(); @@ -133,7 +138,7 @@ void ProjectConfigurationManagement::writeProjectConfiguration(Configuration &co data["lora"]["spreading_factor"] = conf.lora.spreadingFactor; data["lora"]["signal_bandwidth"] = conf.lora.signalBandwidth; data["lora"]["coding_rate4"] = conf.lora.codingRate4; - data["lora"]["txok"] = conf.lora.txok; + data["lora"]["tx_enable"] = conf.lora.tx_enable; data["display"]["always_on"] = conf.display.alwaysOn; data["display"]["timeout"] = conf.display.timeout; data["display"]["overwrite_pin"] = conf.display.overwritePin; @@ -151,6 +156,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 d7c5f28..f38974e 100644 --- a/src/project_configuration.h +++ b/src/project_configuration.h @@ -80,7 +80,7 @@ public: class LoRa { public: - LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5), txok(false) { + LoRa() : frequencyRx(433775000), frequencyTx(433775000), power(20), spreadingFactor(12), signalBandwidth(125000), codingRate4(5), tx_enable(true) { } long frequencyRx; @@ -90,7 +90,7 @@ public: int spreadingFactor; long signalBandwidth; int codingRate4; - bool txok; + bool tx_enable; }; class Display { @@ -121,6 +121,9 @@ public: class MQTT { public: + MQTT() : active(false), server(""), port(1883), name(""), password(""), topic("LoraAPRS/Data") { + } + bool active; String server; uint16_t port; @@ -129,7 +132,18 @@ public: 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; @@ -141,13 +155,14 @@ public: Display display; Ftp ftp; MQTT mqtt; - String board; + Syslog syslog; String ntpServer; + String board; }; class ProjectConfigurationManagement : public ConfigurationManagement { public: - explicit ProjectConfigurationManagement() : ConfigurationManagement("/is-cfg.json") { + explicit ProjectConfigurationManagement(logging::Logger &logger) : ConfigurationManagement(logger, "/is-cfg.json") { } virtual ~ProjectConfigurationManagement() { }