move mqtt loop into network task
This commit is contained in:
@@ -25,7 +25,7 @@ EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* _prefere
|
||||
{
|
||||
Log->println(F("MQTT over TLS."));
|
||||
Log->println(_ca);
|
||||
_mqttClientSecure = new espMqttClientSecure();
|
||||
_mqttClientSecure = new espMqttClientSecureAsync();
|
||||
_mqttClientSecure->setCACert(_ca);
|
||||
if(crtLength > 1 && keyLength > 1) // length is 1 when empty
|
||||
{
|
||||
@@ -38,7 +38,7 @@ EthLan8720Device::EthLan8720Device(const String& hostname, Preferences* _prefere
|
||||
} else
|
||||
{
|
||||
Log->println(F("MQTT without TLS."));
|
||||
_mqttClient = new espMqttClient();
|
||||
_mqttClient = new espMqttClientAsync();
|
||||
}
|
||||
|
||||
if(_preferences->getBool(preference_mqtt_log_enabled))
|
||||
@@ -110,7 +110,14 @@ ReconnectStatus EthLan8720Device::reconnect()
|
||||
|
||||
void EthLan8720Device::update()
|
||||
{
|
||||
|
||||
if(_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->loop();
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->loop();
|
||||
}
|
||||
}
|
||||
|
||||
void EthLan8720Device::onDisconnected()
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <Preferences.h>
|
||||
#include "NetworkDevice.h"
|
||||
#include "espMqttClient.h"
|
||||
#include "espMqttClientAsync.h"
|
||||
|
||||
class EthLan8720Device : public NetworkDevice
|
||||
{
|
||||
@@ -54,8 +54,8 @@ public:
|
||||
private:
|
||||
void onDisconnected();
|
||||
|
||||
espMqttClient* _mqttClient = nullptr;
|
||||
espMqttClientSecure* _mqttClientSecure = nullptr;
|
||||
espMqttClientAsync* _mqttClient = nullptr;
|
||||
espMqttClientSecureAsync* _mqttClientSecure = nullptr;
|
||||
|
||||
bool _restartOnDisconnect = false;
|
||||
bool _startAp = false;
|
||||
|
||||
@@ -197,6 +197,7 @@ void W5500Device::initializeMacAddress(byte *mac)
|
||||
void W5500Device::update()
|
||||
{
|
||||
_maintainResult = Ethernet.maintain();
|
||||
_mqttClient.loop();
|
||||
}
|
||||
|
||||
int8_t W5500Device::signalStrength()
|
||||
|
||||
@@ -25,7 +25,7 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* _preferences)
|
||||
{
|
||||
Log->println(F("MQTT over TLS."));
|
||||
Log->println(_ca);
|
||||
_mqttClientSecure = new espMqttClientSecure();
|
||||
_mqttClientSecure = new espMqttClientSecureAsync();
|
||||
_mqttClientSecure->setCACert(_ca);
|
||||
if(crtLength > 1 && keyLength > 1) // length is 1 when empty
|
||||
{
|
||||
@@ -38,7 +38,7 @@ WifiDevice::WifiDevice(const String& hostname, Preferences* _preferences)
|
||||
} else
|
||||
{
|
||||
Log->println(F("MQTT without TLS."));
|
||||
_mqttClient = new espMqttClient();
|
||||
_mqttClient = new espMqttClientAsync();
|
||||
}
|
||||
|
||||
if(_preferences->getBool(preference_mqtt_log_enabled))
|
||||
@@ -142,7 +142,14 @@ ReconnectStatus WifiDevice::reconnect()
|
||||
|
||||
void WifiDevice::update()
|
||||
{
|
||||
|
||||
if(_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->loop();
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->loop();
|
||||
}
|
||||
}
|
||||
|
||||
void WifiDevice::onDisconnected()
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <Preferences.h>
|
||||
#include "NetworkDevice.h"
|
||||
#include "WiFiManager.h"
|
||||
#include "espMqttClient.h"
|
||||
#include "espMqttClientAsync.h"
|
||||
|
||||
class WifiDevice : public NetworkDevice
|
||||
{
|
||||
@@ -58,8 +58,8 @@ private:
|
||||
void onDisconnected();
|
||||
|
||||
WiFiManager _wm;
|
||||
espMqttClient* _mqttClient = nullptr;
|
||||
espMqttClientSecure* _mqttClientSecure = nullptr;
|
||||
espMqttClientAsync* _mqttClient = nullptr;
|
||||
espMqttClientSecureAsync* _mqttClientSecure = nullptr;
|
||||
|
||||
bool _restartOnDisconnect = false;
|
||||
bool _startAp = false;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "espMqttClientW5500.h"
|
||||
|
||||
espMqttClientW5500::espMqttClientW5500(uint8_t priority, uint8_t core)
|
||||
: MqttClientSetup(true, priority, core),
|
||||
: MqttClientSetup(false, priority, core),
|
||||
_client()
|
||||
{
|
||||
_transport = &_client;
|
||||
|
||||
Reference in New Issue
Block a user