MQTT internal task
This commit is contained in:
@@ -7,9 +7,19 @@
|
|||||||
#include "SPIFFS.h"
|
#include "SPIFFS.h"
|
||||||
#include "../MqttTopics.h"
|
#include "../MqttTopics.h"
|
||||||
#include "PreferencesKeys.h"
|
#include "PreferencesKeys.h"
|
||||||
|
#ifdef CONFIG_SOC_SPIRAM_SUPPORTED
|
||||||
|
#include "esp_psram.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
void NetworkDevice::init()
|
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(_preferences->getBool(preference_mqtt_ssl_enabled, false)) {
|
||||||
if (!SPIFFS.begin(true)) {
|
if (!SPIFFS.begin(true)) {
|
||||||
Log->println("SPIFFS Mount Failed");
|
Log->println("SPIFFS Mount Failed");
|
||||||
@@ -33,7 +43,14 @@ void NetworkDevice::init()
|
|||||||
{
|
{
|
||||||
_useEncryption = true;
|
_useEncryption = true;
|
||||||
Log->println("MQTT over TLS.");
|
Log->println("MQTT over TLS.");
|
||||||
|
if(_mqttInternal)
|
||||||
|
{
|
||||||
_mqttClientSecure = new espMqttClientSecure(espMqttClientTypes::UseInternalTask::YES);
|
_mqttClientSecure = new espMqttClientSecure(espMqttClientTypes::UseInternalTask::YES);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_mqttClientSecure = new espMqttClientSecure(espMqttClientTypes::UseInternalTask::NO);
|
||||||
|
}
|
||||||
_mqttClientSecure->setCACert(caDest);
|
_mqttClientSecure->setCACert(caDest);
|
||||||
|
|
||||||
File file2 = SPIFFS.open("/mqtt_ssl.crt");
|
File file2 = SPIFFS.open("/mqtt_ssl.crt");
|
||||||
@@ -70,8 +87,15 @@ void NetworkDevice::init()
|
|||||||
if (!_useEncryption)
|
if (!_useEncryption)
|
||||||
{
|
{
|
||||||
Log->println("MQTT without TLS.");
|
Log->println("MQTT without TLS.");
|
||||||
|
if(_mqttInternal)
|
||||||
|
{
|
||||||
_mqttClient = new espMqttClient(espMqttClientTypes::UseInternalTask::YES);
|
_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))
|
if(_preferences->getBool(preference_mqtt_log_enabled, false) || _preferences->getBool(preference_webserial_enabled, false))
|
||||||
{
|
{
|
||||||
@@ -101,9 +125,9 @@ void NetworkDevice::init()
|
|||||||
}
|
}
|
||||||
void NetworkDevice::update()
|
void NetworkDevice::update()
|
||||||
{
|
{
|
||||||
if (_mqttEnabled)
|
if (_mqttEnabled && !_mqttInternal)
|
||||||
{
|
{
|
||||||
//getMqttClient()->loop();
|
getMqttClient()->loop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ protected:
|
|||||||
|
|
||||||
bool _useEncryption = false;
|
bool _useEncryption = false;
|
||||||
bool _mqttEnabled = true;
|
bool _mqttEnabled = true;
|
||||||
|
bool _mqttInternal = false;
|
||||||
char* _path;
|
char* _path;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user