From e5dfceafcba003f7c4347c0b6dff3c67ca3bfbe9 Mon Sep 17 00:00:00 2001 From: Boris Brock Date: Sat, 5 Oct 2024 06:16:32 +0200 Subject: [PATCH] Logging additions --- platformio.ini | 4 +- src/Components/MQTT/MQTTManager.cpp | 11 +++-- src/Components/Modbus/ModbusTCP.cpp | 51 ++++++++++---------- src/Components/Wallbox/DummyWallbox.cpp | 23 ++++----- src/Components/Wallbox/HeidelbergWallbox.cpp | 43 +++++++++-------- src/Components/WiFi/WifiConnection.cpp | 21 ++++---- src/Configuration/Logging.h | 6 --- src/Main.cpp | 10 ++-- 8 files changed, 82 insertions(+), 87 deletions(-) delete mode 100644 src/Configuration/Logging.h diff --git a/platformio.ini b/platformio.ini index b55552e..b1bb3e9 100644 --- a/platformio.ini +++ b/platformio.ini @@ -28,8 +28,10 @@ lib_deps = [env:heidelberg] build_flags = -O2 + -D DEBUGLOG_DEFAULT_LOG_LEVEL_ERROR [env:dummy] build_flags = -O2 - -D DUMMY_WALLBOX \ No newline at end of file + -D DUMMY_WALLBOX + -D DEBUGLOG_DEFAULT_LOG_LEVEL_DEBUG \ No newline at end of file diff --git a/src/Components/MQTT/MQTTManager.cpp b/src/Components/MQTT/MQTTManager.cpp index ff25252..4ac3984 100644 --- a/src/Components/MQTT/MQTTManager.cpp +++ b/src/Components/MQTT/MQTTManager.cpp @@ -1,4 +1,5 @@ #include +#include #include #include extern "C" @@ -41,7 +42,7 @@ namespace MQTTManager { if (!gMqttClient.connected()) { - Serial.println("Connecting to MQTT..."); + LOG_INFO("Connecting to MQTT broker..."); gMqttClient.connect(); } } @@ -112,7 +113,7 @@ namespace MQTTManager void OnMqttConnect(bool sessionPresent) { - Serial.println("Connected to MQTT"); + LOG_INFO("Connected to MQTT"); // Subscribe to control topics gMqttClient.subscribe(ChargingCurrentControl.c_str(), 2); @@ -125,7 +126,7 @@ namespace MQTTManager void OnMqttDisconnect(AsyncMqttClientDisconnectReason reason) { - Serial.println("Disconnected from MQTT"); + LOG_WARN("Disconnected from MQTT"); } void OnMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) @@ -133,7 +134,7 @@ namespace MQTTManager if (ChargingCurrentControl == topic) { float current = String(payload, len).toFloat(); - Serial.printf("Received MQTT control command: charging current limit = %f\n", current); + LOG_TRACE("Received MQTT control command: charging current limit = %f\n", current); gWallbox->SetChargingCurrentLimit(current); } } @@ -145,7 +146,7 @@ namespace MQTTManager void Init(IWallbox *wallbox) { - Serial.println("Initializing MQTT"); + LOG_INFO("Initializing MQTT"); gWallbox = wallbox; diff --git a/src/Components/Modbus/ModbusTCP.cpp b/src/Components/Modbus/ModbusTCP.cpp index f13ffef..1330d93 100644 --- a/src/Components/Modbus/ModbusTCP.cpp +++ b/src/Components/Modbus/ModbusTCP.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "ModbusServerWiFi.h" #include "../../Configuration/Constants.h" @@ -13,13 +14,13 @@ namespace ModbusTCP ModbusMessage ReadInputRegister(ModbusMessage msg) { // For debugging - Serial.println("\nMB TCP request received: READ_INPUT_REGISTER:"); - Serial.printf(" > Size: %d\n", msg.size()); - Serial.printf(" > FC: %d\n", msg.getFunctionCode()); - Serial.println(" > Data:"); + LOG_TRACE("Modbus TCP request received: READ_INPUT_REGISTER:"); + LOG_TRACE(" > Size: %d", msg.size()); + LOG_TRACE(" > FC: %d", msg.getFunctionCode()); + LOG_TRACE(" > Data:"); for (uint8_t i = 0; i < msg.size(); ++i) { - Serial.printf(" > %d\n", msg[i]); + LOG_TRACE(" > %d", msg[i]); } return ModbusMessage{}; } @@ -31,7 +32,7 @@ namespace ModbusTCP uint16_t numWords = 0; request.get(2, startAddress); request.get(4, numWords); - Serial.printf("\nModbusTCP request received: READ_HOLD_REGISTER %d words at reg. %d\n", numWords, startAddress); + LOG_TRACE("ModbusTCP request received: READ_HOLD_REGISTER %d words at reg. %d", numWords, startAddress); // Respond properly ModbusMessage response; @@ -40,7 +41,7 @@ namespace ModbusTCP { case (Constants::DaheimladenRegisters::Status): { - Serial.println(" -> Responding with wallbox status"); + LOG_TRACE(" -> Responding with wallbox status"); responseLengthBytes = 2; const uint16_t rawState = static_cast(gWallbox->GetState()); response.add(request.getServerID(), fc, responseLengthBytes); @@ -49,7 +50,7 @@ namespace ModbusTCP } case (Constants::DaheimladenRegisters::LimitChargingCurrent): { - Serial.println(" -> Responding with charging current limit"); + LOG_TRACE(" -> Responding with charging current limit"); responseLengthBytes = 2; uint16_t rawCurrent = static_cast(gWallbox->GetChargingCurrentLimit() * Constants::DaheimladenWallbox::CurrentFactor); response.add(request.getServerID(), fc, responseLengthBytes); @@ -58,7 +59,7 @@ namespace ModbusTCP } case (Constants::DaheimladenRegisters::ConnectionTimeoutTime): { - Serial.println(" -> Responding with connection timeout time"); + LOG_TRACE(" -> Responding with connection timeout time"); responseLengthBytes = 2; const uint16_t dummyValue = 60; response.add(request.getServerID(), fc, responseLengthBytes); @@ -67,7 +68,7 @@ namespace ModbusTCP } case (Constants::DaheimladenRegisters::EnergyMeter): { - Serial.println(" -> Responding with energy meter value"); + LOG_TRACE(" -> Responding with energy meter value"); responseLengthBytes = 4; const uint32_t rawEnergy01kWh = static_cast(gWallbox->GetEnergyMeterValue() * Constants::DaheimladenWallbox::EnergyFactor); response.add(request.getServerID(), fc, responseLengthBytes); @@ -76,7 +77,7 @@ namespace ModbusTCP } case (Constants::DaheimladenRegisters::MaxChargingCurrentAfterConnectionLoss): { - Serial.println(" -> Responding with connection loss current"); + LOG_TRACE(" -> Responding with connection loss current"); responseLengthBytes = 2; uint16_t rawCurrent = static_cast(gWallbox->GetFailsafeCurrent() * Constants::DaheimladenWallbox::CurrentFactor); response.add(request.getServerID(), fc, responseLengthBytes); @@ -85,7 +86,7 @@ namespace ModbusTCP } case (Constants::DaheimladenRegisters::TotalChargingPower): { - Serial.println(" -> Responding with total charging power"); + LOG_TRACE(" -> Responding with total charging power"); responseLengthBytes = 4; const uint32_t powerW = static_cast(gWallbox->GetChargingPower()); response.add(request.getServerID(), fc, responseLengthBytes); @@ -94,7 +95,7 @@ namespace ModbusTCP } case (Constants::DaheimladenRegisters::ChargeCurrents): { - Serial.println(" -> Responding with charging currents"); + LOG_TRACE(" -> Responding with charging currents"); responseLengthBytes = 12; float c1, c2, c3; @@ -111,7 +112,7 @@ namespace ModbusTCP } case (Constants::DaheimladenRegisters::ChargeVoltages): { - Serial.println(" -> Responding with charging voltages"); + LOG_TRACE(" -> Responding with charging voltages"); responseLengthBytes = 12; float v1, v2, v3; @@ -129,7 +130,7 @@ namespace ModbusTCP case (Constants::DaheimladenRegisters::RfidStationId): case (Constants::DaheimladenRegisters::RfidCardId): { - Serial.println(" -> Responding with ID"); + LOG_TRACE(" -> Responding with ID"); responseLengthBytes = 32; const uint32_t dummyValue = 0; response.add(request.getServerID(), fc, responseLengthBytes); @@ -139,7 +140,7 @@ namespace ModbusTCP } default: { - Serial.println(" -> Responding with error ILLEGAL_DATA_ADDRESS"); + LOG_ERROR(" -> Responding with error ILLEGAL_DATA_ADDRESS"); response.setError(request.getServerID(), fc, Modbus::Error::ILLEGAL_DATA_ADDRESS); break; } @@ -151,13 +152,13 @@ namespace ModbusTCP ModbusMessage WriteHoldRegister(ModbusMessage msg) { // For debugging only - Serial.println("\nMB TCP request received: WRITE_HOLD_REGISTER"); - Serial.printf(" > Size: %d\n", msg.size()); - Serial.printf(" > FC: %d\n", msg.getFunctionCode()); - Serial.println(" > Data:"); + LOG_TRACE("Modbus TCP request received: WRITE_HOLD_REGISTER"); + LOG_TRACE(" > Size: %d", msg.size()); + LOG_TRACE(" > FC: %d", msg.getFunctionCode()); + LOG_TRACE(" > Data:"); for (uint8_t i = 0; i < msg.size(); ++i) { - Serial.printf(" > %d\n", msg[i]); + LOG_TRACE(" > %d", msg[i]); } return msg; // Echo back request } @@ -169,7 +170,7 @@ namespace ModbusTCP uint16_t numWords = 0; request.get(2, startAddress); request.get(4, numWords); - Serial.printf("\nModbusTCP request received: WRITE_MULT_REGISTERS %d words to reg. %d\n", numWords, startAddress); + LOG_TRACE("ModbusTCP request received: WRITE_MULT_REGISTERS %d words to reg. %d", numWords, startAddress); // Respond properly switch (startAddress) @@ -178,13 +179,13 @@ namespace ModbusTCP { uint16_t currentLimit = 0; request.get(7, currentLimit); - Serial.printf(" -> Writing charging current limit: %d\n", currentLimit); + LOG_TRACE(" -> Writing charging current limit: %d", currentLimit); gWallbox->SetChargingCurrentLimit(static_cast(currentLimit * 0.1f)); break; } default: { - Serial.println(" -> Responding with error ILLEGAL_DATA_ADDRESS"); + LOG_ERROR(" -> Responding with error ILLEGAL_DATA_ADDRESS"); ModbusMessage response; response.setError(request.getServerID(), fc, Modbus::Error::ILLEGAL_DATA_ADDRESS); return response; @@ -200,7 +201,7 @@ namespace ModbusTCP void Init(IWallbox *wallbox) { - Serial.println("Initializing Modbus TCP server"); + LOG_INFO("Initializing Modbus TCP server"); gWallbox = wallbox; diff --git a/src/Components/Wallbox/DummyWallbox.cpp b/src/Components/Wallbox/DummyWallbox.cpp index 10c7a12..bb3d7b0 100644 --- a/src/Components/Wallbox/DummyWallbox.cpp +++ b/src/Components/Wallbox/DummyWallbox.cpp @@ -1,4 +1,5 @@ #include +#include #include "../../Configuration/Constants.h" #include "DummyWallbox.h" @@ -10,19 +11,19 @@ DummyWallbox *DummyWallbox::Instance() void DummyWallbox::Init() { - Serial.println("Dummy wallbox: initializing"); + LOG_DEBUG("Dummy wallbox: initializing"); } VehicleState DummyWallbox::GetState() { if (mChargingCurrentLimitA > 0.0f) { - Serial.println("Dummy wallbox: returning state CHARGING"); + LOG_DEBUG("Dummy wallbox: returning state CHARGING"); return VehicleState::Charging; } else { - Serial.println("Dummy wallbox: returning state CONNECTED"); + LOG_DEBUG("Dummy wallbox: returning state CONNECTED"); return VehicleState::Connected; } } @@ -30,37 +31,37 @@ VehicleState DummyWallbox::GetState() bool DummyWallbox::SetChargingCurrentLimit(float currentLimitA) { mChargingCurrentLimitA = currentLimitA; - Serial.printf("Dummy wallbox: setting charging current limit to %f A\n", mChargingCurrentLimitA); + LOG_DEBUG("Dummy wallbox: setting charging current limit to %f A", mChargingCurrentLimitA); return true; } float DummyWallbox::GetChargingCurrentLimit() { - Serial.printf("Dummy wallbox: returning charging current limit %f A\n", mChargingCurrentLimitA); + LOG_DEBUG("Dummy wallbox: returning charging current limit %f A", mChargingCurrentLimitA); return mChargingCurrentLimitA; } float DummyWallbox::GetEnergyMeterValue() { - if(mChargingCurrentLimitA > 0.0f) + if (mChargingCurrentLimitA > 0.0f) { mEnergyMeterKWh += 0.1f; } - Serial.printf("Dummy wallbox: returning energy meter value %f kWh\n", mEnergyMeterKWh); + LOG_DEBUG("Dummy wallbox: returning energy meter value %f kWh", mEnergyMeterKWh); return mEnergyMeterKWh; } float DummyWallbox::GetFailsafeCurrent() { - Serial.printf("Dummy wallbox: returning failsafe current %f A\n", mFailsafeCurrentA); + LOG_DEBUG("Dummy wallbox: returning failsafe current %f A", mFailsafeCurrentA); return mFailsafeCurrentA; } float DummyWallbox::GetChargingPower() { float chargingPowerW = mChargingCurrentLimitA * Constants::DummyWallbox::ChargingVoltageV * Constants::DummyWallbox::NumPhases; - Serial.printf("Dummy wallbox: returning charging power %f W\n", chargingPowerW); + LOG_DEBUG("Dummy wallbox: returning charging power %f W", chargingPowerW); return chargingPowerW; } @@ -69,7 +70,7 @@ bool DummyWallbox::GetChargingCurrents(float &c1A, float &c2A, float &c3A) c1A = mChargingCurrentLimitA; c2A = mChargingCurrentLimitA; c3A = mChargingCurrentLimitA; - Serial.printf("Dummy wallbox: returning charging currents %f, %f and %f A\n", c1A, c2A, c3A); + LOG_DEBUG("Dummy wallbox: returning charging currents %f, %f and %f A", c1A, c2A, c3A); return true; } @@ -78,7 +79,7 @@ bool DummyWallbox::GetChargingVoltages(float &v1V, float &v2V, float &v3V) v1V = Constants::DummyWallbox::ChargingVoltageV; v2V = Constants::DummyWallbox::ChargingVoltageV; v3V = Constants::DummyWallbox::ChargingVoltageV; - Serial.printf("Dummy wallbox: returning charging voltages %f, %f and %f A\n", v1V, v2V, v3V); + LOG_DEBUG("Dummy wallbox: returning charging voltages %f, %f and %f A", v1V, v2V, v3V); return true; } diff --git a/src/Components/Wallbox/HeidelbergWallbox.cpp b/src/Components/Wallbox/HeidelbergWallbox.cpp index 62549fa..6811271 100644 --- a/src/Components/Wallbox/HeidelbergWallbox.cpp +++ b/src/Components/Wallbox/HeidelbergWallbox.cpp @@ -1,4 +1,5 @@ #include +#include #include "../Modbus/ModbusRTU.h" #include "../../Configuration/Constants.h" #include "HeidelbergWallbox.h" @@ -12,19 +13,19 @@ HeidelbergWallbox *HeidelbergWallbox::Instance() void HeidelbergWallbox::Init() { uint16_t rawCurrent = static_cast(Constants::HeidelbergWallbox::FailSafeCurrentA / Constants::HeidelbergWallbox::CurrentFactor); - Serial.printf("Heidelberg wallbox: Initializing fail safe current with %d (raw)\n", rawCurrent); + LOG_TRACE("Heidelberg wallbox: Initializing fail safe current with %d (raw)", rawCurrent); if (!ModbusRTU::Instance()->WriteHoldRegister16(Constants::HeidelbergRegisters::FailsafeCurrent, rawCurrent)) { // Error writing modbus register - Serial.println("ERROR: Could not set fail safe current"); + LOG_ERROR("ERROR: Could not set fail safe current"); } uint16_t standbyDisabled = 4; - Serial.printf("Heidelberg wallbox: Initializing standby mode with %d (raw)\n", standbyDisabled); + LOG_TRACE("Heidelberg wallbox: Initializing standby mode with %d (raw)", standbyDisabled); if (!ModbusRTU::Instance()->WriteHoldRegister16(Constants::HeidelbergRegisters::DisableStandby, standbyDisabled)) { // Error writing modbus register - Serial.println("ERROR: Could not disable standby"); + LOG_ERROR("ERROR: Could not disable standby"); } } @@ -33,7 +34,7 @@ VehicleState HeidelbergWallbox::GetState() uint16_t registerValue[0]; if (ModbusRTU::Instance()->ReadRegisters(Constants::HeidelbergRegisters::ChargingState, 1, 0x4, registerValue)) { - Serial.printf("Heidelberg wallbox: Read state: %d\n", registerValue[0]); + LOG_DEBUG("Heidelberg wallbox: Read state: %d", registerValue[0]); if (registerValue[0] <= 3) { mState = VehicleState::Disconnected; @@ -50,7 +51,7 @@ VehicleState HeidelbergWallbox::GetState() else { // Error reading modbus register - Serial.println("Heidelberg wallbox: ERROR: Could not read plugged state"); + LOG_ERROR("Heidelberg wallbox: ERROR: Could not read plugged state"); } return mState; @@ -59,13 +60,13 @@ VehicleState HeidelbergWallbox::GetState() bool HeidelbergWallbox::SetChargingCurrentLimit(float currentLimitA) { mChargingCurrentLimitA = currentLimitA; - Serial.printf("Heidelberg wallbox: setting charging current limit to %f A\n", mChargingCurrentLimitA); + LOG_DEBUG("Heidelberg wallbox: setting charging current limit to %f A", mChargingCurrentLimitA); uint16_t rawCurrent = static_cast(mChargingCurrentLimitA / Constants::HeidelbergWallbox::CurrentFactor); if (!ModbusRTU::Instance()->WriteHoldRegister16(Constants::HeidelbergRegisters::MaximalCurrent, rawCurrent)) { // Error writing modbus register - Serial.println("Heidelberg wallbox: ERROR: Could not set maximum charging current"); + LOG_ERROR("Heidelberg wallbox: ERROR: Could not set maximum charging current"); } return true; @@ -77,13 +78,13 @@ float HeidelbergWallbox::GetChargingCurrentLimit() if (ModbusRTU::Instance()->ReadRegisters(Constants::HeidelbergRegisters::MaximalCurrent, 1, 0x3, registerValue)) { mChargingCurrentLimitA = static_cast(registerValue[0] * Constants::HeidelbergWallbox::CurrentFactor); - Serial.printf("Heidelberg wallbox: Read max. charging current: %d\n", mChargingCurrentLimitA); + LOG_DEBUG("Heidelberg wallbox: Read max. charging current: %d", mChargingCurrentLimitA); return mChargingCurrentLimitA; } else { // Error reading modbus register - Serial.println("Heidelberg wallbox: ERROR: Could not read max. charging current"); + LOG_ERROR("Heidelberg wallbox: ERROR: Could not read max. charging current"); return mChargingCurrentLimitA; // Return last valid value } } @@ -101,11 +102,11 @@ float HeidelbergWallbox::GetEnergyMeterValue() uint32_t totalEnergyWh = static_cast(rawEnergy[0]) << 16 | static_cast(rawEnergy[1]); mLastEnergyMeterValueWh = static_cast(totalEnergyWh); - Serial.printf("Heidelberg wallbox: Read energy meter value: %f Wh\n", mLastEnergyMeterValueWh); + LOG_DEBUG("Heidelberg wallbox: Read energy meter value: %f Wh", mLastEnergyMeterValueWh); } else { - Serial.println("Heidelberg wallbox: ERROR: Could not read energy meter value"); + LOG_ERROR("Heidelberg wallbox: ERROR: Could not read energy meter value"); } return mLastEnergyMeterValueWh; @@ -117,12 +118,12 @@ float HeidelbergWallbox::GetFailsafeCurrent() if (ModbusRTU::Instance()->ReadRegisters(Constants::HeidelbergRegisters::FailsafeCurrent, 1, 0x3, registerValue)) { mFailsafeCurrentA = static_cast(registerValue[0] * Constants::HeidelbergWallbox::CurrentFactor); - Serial.printf("Read Heidelberg failsafe current: %f\n", mFailsafeCurrentA); + LOG_DEBUG("Read Heidelberg failsafe current: %f", mFailsafeCurrentA); } else { // Error reading modbus register - Serial.println("Heidelberg wallbox: ERROR: Could not read failsafe current"); + LOG_ERROR("Heidelberg wallbox: ERROR: Could not read failsafe current"); } return mFailsafeCurrentA; @@ -134,12 +135,12 @@ float HeidelbergWallbox::GetChargingPower() if (ModbusRTU::Instance()->ReadRegisters(Constants::HeidelbergRegisters::Power, 1, 0x4, registerValue)) { mLastPowerMeterValueW = static_cast(registerValue[0]); - Serial.printf("Reading power meter value: %f W\n", mLastPowerMeterValueW); + LOG_DEBUG("Reading power meter value: %f W", mLastPowerMeterValueW); } else { // Error reading modbus register - Serial.println("Heidelberg wallbox: ERROR: Could not read last power meter value"); + LOG_ERROR("Heidelberg wallbox: ERROR: Could not read last power meter value"); } return mLastPowerMeterValueW; @@ -158,12 +159,12 @@ bool HeidelbergWallbox::GetChargingCurrents(float &c1A, float &c2A, float &c3A) c1A = static_cast(rawCurrents[0] * Constants::HeidelbergWallbox::CurrentFactor); c2A = static_cast(rawCurrents[1] * Constants::HeidelbergWallbox::CurrentFactor); c3A = static_cast(rawCurrents[2] * Constants::HeidelbergWallbox::CurrentFactor); - Serial.printf("Reading currents: %f %f %f A\n", c1A, c2A, c3A); + LOG_DEBUG("Reading currents: %f %f %f A", c1A, c2A, c3A); return true; } else { - Serial.println("Heidelberg wallbox: ERROR: Could not read currents"); + LOG_ERROR("Heidelberg wallbox: ERROR: Could not read currents"); return false; } } @@ -181,12 +182,12 @@ bool HeidelbergWallbox::GetChargingVoltages(float &v1V, float &v2V, float &v3V) v1V = static_cast(rawVoltages[0] * Constants::HeidelbergWallbox::VoltageFactor); v2V = static_cast(rawVoltages[1] * Constants::HeidelbergWallbox::VoltageFactor); v3V = static_cast(rawVoltages[2] * Constants::HeidelbergWallbox::VoltageFactor); - Serial.printf("Reading voltages: %f %f %f V\n", v1V, v2V, v3V); + LOG_DEBUG("Reading voltages: %f %f %f V", v1V, v2V, v3V); return true; } else { - Serial.println("Heidelberg wallbox: ERROR: Could not read voltages"); + LOG_ERROR("Heidelberg wallbox: ERROR: Could not read voltages"); return false; } } @@ -201,7 +202,7 @@ float HeidelbergWallbox::GetTemperature() else { // Error reading modbus register - Serial.println("Heidelberg wallbox: ERROR: Could not read PCB temperature"); + LOG_ERROR("Heidelberg wallbox: ERROR: Could not read PCB temperature"); return 0.0f; } } \ No newline at end of file diff --git a/src/Components/WiFi/WifiConnection.cpp b/src/Components/WiFi/WifiConnection.cpp index 302a5aa..f1700a6 100644 --- a/src/Components/WiFi/WifiConnection.cpp +++ b/src/Components/WiFi/WifiConnection.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "../../Configuration/Constants.h" #include "WifiConnection.h" @@ -8,30 +9,29 @@ namespace WifiConnection { void WiFiStationConnected(WiFiEvent_t event, WiFiEventInfo_t info) { - Serial.println("Connected to AP successfully!"); + LOG_INFO("Connected to AP successfully!"); } void WiFiGotIP(WiFiEvent_t event, WiFiEventInfo_t info) { - Serial.println("WiFi connected"); - Serial.println("IP address: "); - Serial.println(WiFi.localIP()); + LOG_INFO("WiFi connected"); + LOG_INFO("IP address: "); + LOG_INFO(WiFi.localIP()); } void WiFiStationDisconnected(WiFiEvent_t event, WiFiEventInfo_t info) { - Serial.println("Disconnected from WiFi access point"); - Serial.print("WiFi lost connection. Reason: "); - Serial.println(info.wifi_sta_disconnected.reason); + LOG_WARN("Disconnected from WiFi access point"); + LOG_WARN("WiFi lost connection. Reason: %d", info.wifi_sta_disconnected.reason); + LOG_WARN("Trying to reconnect"); - Serial.println("Trying to reconnect"); WiFi.begin(Credentials::WiFi::SSID, Credentials::WiFi::Password); } void Init() { // Delete old config - Serial.println("Preparing Wifi"); + LOG_TRACE("Preparing Wifi"); WiFi.disconnect(true); delay(100); @@ -45,8 +45,7 @@ namespace WifiConnection WiFi.onEvent(WiFiStationDisconnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_DISCONNECTED); // Start Wifi connection - Serial.print("Connecting WiFi, SSID: "); - Serial.println(Credentials::WiFi::SSID); + LOG_INFO("Connecting to WiFi SSID '%s'", Credentials::WiFi::SSID); WiFi.begin(Credentials::WiFi::SSID, Credentials::WiFi::Password); } }; \ No newline at end of file diff --git a/src/Configuration/Logging.h b/src/Configuration/Logging.h deleted file mode 100644 index 6c77963..0000000 --- a/src/Configuration/Logging.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -namespace Logging -{ - constexpr DebugLogLevel LogLevel = DebugLogLevel::LVL_TRACE; -}; diff --git a/src/Main.cpp b/src/Main.cpp index e2d7bae..3a25505 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,6 +1,5 @@ #include #include -#include "Configuration/Logging.h" #include "Configuration/Constants.h" #include "Configuration/Version.h" #include "Components/WiFi/WifiConnection.h" @@ -17,13 +16,10 @@ void setup() // Configure serial communication Serial.begin(115200); - // Set log level - LOG_SET_LEVEL(Logging::LogLevel); - // Print version info - LOG_INFO("Booting HeidelBridge"); - LOG_INFO(" Version: %d.%d.%d\n", Version::Major, Version::Minor, Version::Patch); - LOG_INFO(" Build date: %s\n\n", __DATE__); + PRINT("Booting HeidelBridge"); + PRINT(" Version: %d.%d.%d\n", Version::Major, Version::Minor, Version::Patch); + PRINT(" Build date: %s\n\n", __DATE__); // Make sure WiFi connection is up and running WifiConnection::Init();