refactor network devices hierarchy
This commit is contained in:
@@ -125,18 +125,6 @@ void WifiDevice::reconfigure()
|
||||
restartEsp(RestartReason::ReconfigureWifi);
|
||||
}
|
||||
|
||||
void WifiDevice::printError()
|
||||
{
|
||||
// if(_wifiClientSecure != nullptr)
|
||||
// {
|
||||
// char lastError[100];
|
||||
// _wifiClientSecure->lastError(lastError,100);
|
||||
// Log->println(lastError);
|
||||
// }
|
||||
Log->print(F("Free Heap: "));
|
||||
Log->println(ESP.getFreeHeap());
|
||||
}
|
||||
|
||||
bool WifiDevice::supportsEncryption()
|
||||
{
|
||||
return true;
|
||||
@@ -153,20 +141,6 @@ ReconnectStatus WifiDevice::reconnect()
|
||||
return isConnected() ? ReconnectStatus::Success : ReconnectStatus::Failure;
|
||||
}
|
||||
|
||||
void WifiDevice::update()
|
||||
{
|
||||
if(_mqttEnabled)
|
||||
{
|
||||
if (_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->loop();
|
||||
} else
|
||||
{
|
||||
_mqttClient->loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WifiDevice::onDisconnected()
|
||||
{
|
||||
if(millis() > 60000)
|
||||
@@ -184,198 +158,3 @@ void WifiDevice::clearRtcInitVar(WiFiManager *)
|
||||
{
|
||||
memset(WiFiDevice_reconfdetect, 0, sizeof WiFiDevice_reconfdetect);
|
||||
}
|
||||
|
||||
void WifiDevice::mqttSetClientId(const char *clientId)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->setClientId(clientId);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->setClientId(clientId);
|
||||
}
|
||||
}
|
||||
|
||||
void WifiDevice::mqttSetCleanSession(bool cleanSession)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->setCleanSession(cleanSession);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->setCleanSession(cleanSession);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t WifiDevice::mqttPublish(const char *topic, uint8_t qos, bool retain, const char *payload)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
return _mqttClientSecure->publish(topic, qos, retain, payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _mqttClient->publish(topic, qos, retain, payload);
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t WifiDevice::mqttPublish(const char *topic, uint8_t qos, bool retain, const uint8_t *payload, size_t length)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
return _mqttClientSecure->publish(topic, qos, retain, payload, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _mqttClient->publish(topic, qos, retain, payload, length);
|
||||
}
|
||||
}
|
||||
|
||||
bool WifiDevice::mqttConnected() const
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
return _mqttClientSecure->connected();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _mqttClient->connected();
|
||||
}
|
||||
}
|
||||
|
||||
void WifiDevice::mqttSetServer(const char *host, uint16_t port)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->setServer(host, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->setServer(host, port);
|
||||
}
|
||||
}
|
||||
|
||||
bool WifiDevice::mqttConnect()
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
return _mqttClientSecure->connect();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _mqttClient->connect();
|
||||
}
|
||||
}
|
||||
|
||||
bool WifiDevice::mqttDisconnect(bool force)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
return _mqttClientSecure->disconnect(force);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _mqttClient->disconnect(force);
|
||||
}
|
||||
}
|
||||
|
||||
void WifiDevice::setWill(const char *topic, uint8_t qos, bool retain, const char *payload)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->setWill(topic, qos, retain, payload);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->setWill(topic, qos, retain, payload);
|
||||
}
|
||||
}
|
||||
|
||||
void WifiDevice::mqttSetCredentials(const char *username, const char *password)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->setCredentials(username, password);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->setCredentials(username, password);
|
||||
}
|
||||
}
|
||||
|
||||
void WifiDevice::mqttOnMessage(espMqttClientTypes::OnMessageCallback callback)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->onMessage(callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->onMessage(callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WifiDevice::mqttOnConnect(espMqttClientTypes::OnConnectCallback callback)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->onConnect(callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->onConnect(callback);
|
||||
}
|
||||
}
|
||||
|
||||
void WifiDevice::mqttOnDisconnect(espMqttClientTypes::OnDisconnectCallback callback)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->onDisconnect(callback);
|
||||
}
|
||||
else
|
||||
{
|
||||
_mqttClient->onDisconnect(callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint16_t WifiDevice::mqttSubscribe(const char *topic, uint8_t qos)
|
||||
{
|
||||
if(_useEncryption)
|
||||
{
|
||||
return _mqttClientSecure->subscribe(topic, qos);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _mqttClient->subscribe(topic, qos);
|
||||
}
|
||||
}
|
||||
|
||||
void WifiDevice::disableMqtt()
|
||||
{
|
||||
if (_useEncryption)
|
||||
{
|
||||
_mqttClientSecure->disconnect();
|
||||
} else
|
||||
{
|
||||
_mqttClient->disconnect();
|
||||
}
|
||||
|
||||
_mqttEnabled = false;
|
||||
}
|
||||
|
||||
MqttClient *WifiDevice::getMqttClient() const
|
||||
{
|
||||
if (_useEncryption)
|
||||
{
|
||||
return _mqttClientSecure;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _mqttClient;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user