MQTT internal task

This commit is contained in:
iranl
2025-04-01 22:27:50 +02:00
parent 0592c277ea
commit bf1b27a792
2 changed files with 31 additions and 6 deletions

View File

@@ -7,9 +7,19 @@
#include "SPIFFS.h"
#include "../MqttTopics.h"
#include "PreferencesKeys.h"
#ifdef CONFIG_SOC_SPIRAM_SUPPORTED
#include "esp_psram.h"
#endif
void NetworkDevice::init()
{
#ifdef CONFIG_SOC_SPIRAM_SUPPORTED
if(esp_psram_get_size() > 0)
{
_mqttInternal = true;
}
#endif
if(_preferences->getBool(preference_mqtt_ssl_enabled, false)) {
if (!SPIFFS.begin(true)) {
Log->println("SPIFFS Mount Failed");
@@ -33,7 +43,14 @@ void NetworkDevice::init()
{
_useEncryption = true;
Log->println("MQTT over TLS.");
if(_mqttInternal)
{
_mqttClientSecure = new espMqttClientSecure(espMqttClientTypes::UseInternalTask::YES);
}
else
{
_mqttClientSecure = new espMqttClientSecure(espMqttClientTypes::UseInternalTask::NO);
}
_mqttClientSecure->setCACert(caDest);
File file2 = SPIFFS.open("/mqtt_ssl.crt");
@@ -70,8 +87,15 @@ void NetworkDevice::init()
if (!_useEncryption)
{
Log->println("MQTT without TLS.");
if(_mqttInternal)
{
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::YES);
}
else
{
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::NO);
}
}
if(_preferences->getBool(preference_mqtt_log_enabled, false) || _preferences->getBool(preference_webserial_enabled, false))
{
@@ -101,9 +125,9 @@ void NetworkDevice::init()
}
void NetworkDevice::update()
{
if (_mqttEnabled)
if (_mqttEnabled && !_mqttInternal)
{
//getMqttClient()->loop();
getMqttClient()->loop();
}
}

View File

@@ -64,6 +64,7 @@ protected:
bool _useEncryption = false;
bool _mqttEnabled = true;
bool _mqttInternal = false;
char* _path;
#endif