remove NetworkDevice dependency from MqttLogger library

This commit is contained in:
Luca Oliano
2024-02-04 19:05:26 +01:00
parent de117f5a06
commit c716afb254
8 changed files with 38 additions and 13 deletions

View File

@@ -57,7 +57,7 @@ EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* preferen
String pathStr = preferences->getString(preference_mqtt_lock_path);
pathStr.concat(mqtt_topic_log);
strcpy(_path, pathStr.c_str());
Log = new MqttLogger(this, _path, MqttLoggerMode::MqttAndSerial);
Log = new MqttLogger(*getMqttClient(), _path, MqttLoggerMode::MqttAndSerial);
}
}
@@ -342,3 +342,14 @@ void EthLan8720Device::disableMqtt()
_mqttEnabled = false;
}
MqttClient *EthLan8720Device::getMqttClient() const
{
if (_useEncryption)
{
return _mqttClientSecure;
}
else
{
return _mqttClient;
}
}

View File

@@ -69,6 +69,7 @@ public:
private:
void onDisconnected();
MqttClient *getMqttClient() const;
espMqttClient* _mqttClient = nullptr;
espMqttClientSecure* _mqttClientSecure = nullptr;

View File

@@ -61,7 +61,7 @@ void W5500Device::initialize()
_path = new char[pathStr.length() + 1];
memset(_path, 0, sizeof(_path));
strcpy(_path, pathStr.c_str());
Log = new MqttLogger(this, _path, MqttLoggerMode::MqttAndSerial);
Log = new MqttLogger(_mqttClient, _path, MqttLoggerMode::MqttAndSerial);
}
reconnect();

View File

@@ -51,7 +51,7 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* preferences, const I
String pathStr = preferences->getString(preference_mqtt_lock_path);
pathStr.concat(mqtt_topic_log);
strcpy(_path, pathStr.c_str());
Log = new MqttLogger(this, _path, MqttLoggerMode::MqttAndSerial);
Log = new MqttLogger(*getMqttClient(), _path, MqttLoggerMode::MqttAndSerial);
}
}
@@ -367,3 +367,15 @@ void WifiDevice::disableMqtt()
_mqttEnabled = false;
}
MqttClient *WifiDevice::getMqttClient() const
{
if (_useEncryption)
{
return _mqttClientSecure;
}
else
{
return _mqttClient;
}
}

View File

@@ -61,6 +61,7 @@ private:
static void clearRtcInitVar(WiFiManager*);
void onDisconnected();
MqttClient *getMqttClient() const;
WiFiManager _wm;
espMqttClient* _mqttClient = nullptr;