refactor NetworkDevice interface to work with new esp mqtt lib
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Print.h>
|
||||
#include "MqttClient.h"
|
||||
#include "MqttClientSetup.h"
|
||||
#include "../../../networkDevices/NetworkDevice.h"
|
||||
|
||||
#define MQTT_MAX_PACKET_SIZE 1024
|
||||
|
||||
@@ -30,16 +29,16 @@ private:
|
||||
uint8_t* buffer;
|
||||
uint8_t* bufferEnd;
|
||||
uint16_t bufferCnt = 0, bufferSize = 0;
|
||||
MqttClientSetup* client;
|
||||
NetworkDevice* client;
|
||||
MqttLoggerMode mode;
|
||||
void sendBuffer();
|
||||
|
||||
public:
|
||||
MqttLogger(MqttLoggerMode mode=MqttLoggerMode::MqttAndSerialFallback);
|
||||
MqttLogger(MqttClientSetup& client, const char* topic, MqttLoggerMode mode=MqttLoggerMode::MqttAndSerialFallback);
|
||||
MqttLogger(NetworkDevice* client, const char* topic, MqttLoggerMode mode=MqttLoggerMode::MqttAndSerialFallback);
|
||||
~MqttLogger();
|
||||
|
||||
void setClient(MqttClientSetup& client);
|
||||
void setClient(NetworkDevice* client);
|
||||
void setTopic(const char* topic);
|
||||
void setMode(MqttLoggerMode mode);
|
||||
void setRetained(boolean retained);
|
||||
|
||||
Reference in New Issue
Block a user