From 3a5f14dc183179245a52eda5af7b510ebbafc5fd Mon Sep 17 00:00:00 2001 From: technyon Date: Fri, 23 Dec 2022 23:06:19 +0100 Subject: [PATCH] dynamic path for mqtt logger --- MqttTopics.h | 1 + networkDevices/W5500Device.cpp | 10 +++++++++- networkDevices/W5500Device.h | 1 + networkDevices/WifiDevice.cpp | 6 +++++- networkDevices/WifiDevice.h | 1 + 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/MqttTopics.h b/MqttTopics.h index baac76f..66c315f 100644 --- a/MqttTopics.h +++ b/MqttTopics.h @@ -42,4 +42,5 @@ #define mqtt_topic_reset "/maintenance/reset" #define mqtt_topic_uptime "/maintenance/uptime" #define mqtt_topic_wifi_rssi "/maintenance/wifiRssi" +#define mqtt_topic_log "/maintenance/log" #define mqtt_topic_freeheap "/maintenance/freeHeap" \ No newline at end of file diff --git a/networkDevices/W5500Device.cpp b/networkDevices/W5500Device.cpp index 52fc2c4..4bfd2df 100644 --- a/networkDevices/W5500Device.cpp +++ b/networkDevices/W5500Device.cpp @@ -4,6 +4,7 @@ #include "../Pins.h" #include "../PreferencesKeys.h" #include "../Logger.h" +#include "../MqttTopics.h" W5500Device::W5500Device(const String &hostname, Preferences* preferences) : NetworkDevice(hostname), @@ -40,7 +41,14 @@ void W5500Device::initialize() _ethClient = new EthernetClient(); _mqttClient = new PubSubClient(*_ethClient); _mqttClient->setBufferSize(_mqttMaxBufferSize); - Log = new MqttLogger(*_mqttClient, "nuki/log"); + + _path = new char[200]; + memset(_path, 0, sizeof(_path)); + + String pathStr = _preferences->getString(preference_mqtt_lock_path); + pathStr.concat(mqtt_topic_log); + strcpy(_path, pathStr.c_str()); + Log = new MqttLogger(*_mqttClient, _path); reconnect(); } diff --git a/networkDevices/W5500Device.h b/networkDevices/W5500Device.h index d18368e..2eb9c53 100644 --- a/networkDevices/W5500Device.h +++ b/networkDevices/W5500Device.h @@ -33,6 +33,7 @@ private: int _maintainResult = 0; bool _hasDHCPAddress = false; + char* _path; byte _mac[6]; }; \ No newline at end of file diff --git a/networkDevices/WifiDevice.cpp b/networkDevices/WifiDevice.cpp index 305294b..e27265a 100644 --- a/networkDevices/WifiDevice.cpp +++ b/networkDevices/WifiDevice.cpp @@ -2,6 +2,7 @@ #include "WifiDevice.h" #include "../PreferencesKeys.h" #include "../Logger.h" +#include "../MqttTopics.h" RTC_NOINIT_ATTR char WiFiDevice_reconfdetect[17]; @@ -40,7 +41,10 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* _preferences) _mqttClient = new PubSubClient(*_wifiClient); } - Log = new MqttLogger(*_mqttClient, "nuki/log"); + String pathStr = _preferences->getString(preference_mqtt_lock_path); + pathStr.concat(mqtt_topic_log); + strcpy(_path, pathStr.c_str()); + Log = new MqttLogger(*_mqttClient, _path); } PubSubClient *WifiDevice::mqttClient() diff --git a/networkDevices/WifiDevice.h b/networkDevices/WifiDevice.h index cd517d7..f359761 100644 --- a/networkDevices/WifiDevice.h +++ b/networkDevices/WifiDevice.h @@ -34,6 +34,7 @@ private: // SpiffsCookie _cookie; bool _restartOnDisconnect = false; bool _startAp = false; + char* _path; char _ca[TLS_CA_MAX_SIZE]; char _cert[TLS_CERT_MAX_SIZE];