refactor NetworkDevice interface to work with new esp mqtt lib

This commit is contained in:
technyon
2023-01-28 17:17:46 +01:00
parent a6010a7f49
commit 5853b0dc0e
24 changed files with 493 additions and 287 deletions

View File

@@ -7,7 +7,7 @@ MqttLogger::MqttLogger(MqttLoggerMode mode)
this->setBufferSize(MQTT_MAX_PACKET_SIZE);
}
MqttLogger::MqttLogger(MqttClientSetup& client, const char* topic, MqttLoggerMode mode)
MqttLogger::MqttLogger(NetworkDevice* client, const char* topic, MqttLoggerMode mode)
{
this->setClient(client);
this->setTopic(topic);
@@ -19,9 +19,9 @@ MqttLogger::~MqttLogger()
{
}
void MqttLogger::setClient(MqttClientSetup& client)
void MqttLogger::setClient(NetworkDevice* client)
{
this->client = &client;
this->client = client;
}
void MqttLogger::setTopic(const char* topic)
@@ -74,9 +74,9 @@ void MqttLogger::sendBuffer()
if (this->bufferCnt > 0)
{
bool doSerial = this->mode==MqttLoggerMode::SerialOnly || this->mode==MqttLoggerMode::MqttAndSerial;
if (this->mode!=MqttLoggerMode::SerialOnly && this->client != NULL && this->client->connected())
if (this->mode!=MqttLoggerMode::SerialOnly && this->client != NULL && this->client->mqttConnected())
{
this->client->publish(topic, 0, true, (uint8_t*)this->buffer, this->bufferCnt);
this->client->mqttPublish(topic, 0, true, (uint8_t*)this->buffer, this->bufferCnt);
} else if (this->mode == MqttLoggerMode::MqttAndSerialFallback)
{
doSerial = true;