Refractor
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
#ifndef NUKI_HUB_UPDATER
|
||||
#include "../MqttTopics.h"
|
||||
#include "espMqttClient.h"
|
||||
#include "PreferencesKeys.h"
|
||||
|
||||
void NetworkDevice::init()
|
||||
{
|
||||
@@ -58,17 +58,38 @@ void NetworkDevice::update()
|
||||
|
||||
void NetworkDevice::mqttSetClientId(const char *clientId)
|
||||
{
|
||||
getMqttClient()->setClientId(clientId);
|
||||
if (_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->setClientId(clientId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->setClientId(clientId);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkDevice::mqttSetCleanSession(bool cleanSession)
|
||||
{
|
||||
getMqttClient()->setCleanSession(cleanSession);
|
||||
if (_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->setCleanSession(cleanSession);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->setCleanSession(cleanSession);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkDevice::mqttSetKeepAlive(uint16_t keepAlive)
|
||||
{
|
||||
getMqttClient()->setKeepAlive(keepAlive);
|
||||
if (_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->setKeepAlive(keepAlive);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->setKeepAlive(keepAlive);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t NetworkDevice::mqttPublish(const char *topic, uint8_t qos, bool retain, const char *payload)
|
||||
@@ -88,7 +109,14 @@ bool NetworkDevice::mqttConnected() const
|
||||
|
||||
void NetworkDevice::mqttSetServer(const char *host, uint16_t port)
|
||||
{
|
||||
getMqttClient()->setServer(host, port);
|
||||
if (_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->setServer(host, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->setServer(host, port);
|
||||
}
|
||||
}
|
||||
|
||||
bool NetworkDevice::mqttConnect()
|
||||
@@ -101,29 +129,64 @@ bool NetworkDevice::mqttDisconnect(bool force)
|
||||
return getMqttClient()->disconnect(force);
|
||||
}
|
||||
|
||||
void NetworkDevice::setWill(const char *topic, uint8_t qos, bool retain, const char *payload)
|
||||
void NetworkDevice::mqttSetWill(const char *topic, uint8_t qos, bool retain, const char *payload)
|
||||
{
|
||||
getMqttClient()->setWill(topic, qos, retain, payload);
|
||||
if (_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->setWill(topic, qos, retain, payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->setWill(topic, qos, retain, payload);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkDevice::mqttSetCredentials(const char *username, const char *password)
|
||||
{
|
||||
getMqttClient()->setCredentials(username, password);
|
||||
if (_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->setCredentials(username, password);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->setCredentials(username, password);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkDevice::mqttOnMessage(espMqttClientTypes::OnMessageCallback callback)
|
||||
{
|
||||
getMqttClient()->onMessage(callback);
|
||||
if (_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->onMessage(callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->onMessage(callback);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkDevice::mqttOnConnect(espMqttClientTypes::OnConnectCallback callback)
|
||||
{
|
||||
getMqttClient()->onConnect(callback);
|
||||
if(_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->onConnect(callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->onConnect(callback);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkDevice::mqttOnDisconnect(espMqttClientTypes::OnDisconnectCallback callback)
|
||||
{
|
||||
getMqttClient()->onDisconnect(callback);
|
||||
if (_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->onDisconnect(callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->onDisconnect(callback);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t NetworkDevice::mqttSubscribe(const char *topic, uint8_t qos)
|
||||
@@ -131,7 +194,7 @@ uint16_t NetworkDevice::mqttSubscribe(const char *topic, uint8_t qos)
|
||||
return getMqttClient()->subscribe(topic, qos);
|
||||
}
|
||||
|
||||
void NetworkDevice::disableMqtt()
|
||||
void NetworkDevice::mqttDisable()
|
||||
{
|
||||
getMqttClient()->disconnect();
|
||||
_mqttEnabled = false;
|
||||
|
||||
Reference in New Issue
Block a user