added duplicate console to mqtt
This commit is contained in:
+19
-2
@@ -20,6 +20,11 @@ char DebugMqtt::topic[MQTT_BUFFER_SIZE];
|
||||
|
||||
DebugMqtt::DebugMqtt(const char* name) {
|
||||
this->name = name;
|
||||
this->buf = new char[this->bufSitze];
|
||||
}
|
||||
|
||||
DebugMqtt::~DebugMqtt() {
|
||||
delete this->buf;
|
||||
}
|
||||
|
||||
void DebugMqtt::sendMsg(Loglevel loglevel, String topic, String msg) {
|
||||
@@ -32,7 +37,9 @@ void DebugMqtt::sendMsg(Loglevel loglevel, String msg) {
|
||||
}
|
||||
|
||||
void DebugMqtt::sendData(Loglevel loglevel, String topic, String data) {
|
||||
if (!DebugMqtt::isInit) {return;}
|
||||
if (!DebugMqtt::isInit) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (loglevel <= DebugMqtt::loglevel && loglevel > Loglevel::none) {
|
||||
snprintf (DebugMqtt::topic, MQTT_BUFFER_SIZE, "%s%s", DebugMqtt::enum_to_string(loglevel).c_str(), topic.c_str());
|
||||
@@ -52,9 +59,19 @@ void DebugMqtt::writeToInflux(String measurement_name, String field_set, float m
|
||||
this->sendData(Loglevel::influx, DebugMqtt::msg);
|
||||
}
|
||||
|
||||
void DebugMqtt::addCharacter(char c) {
|
||||
this->buf[this->bufPos] = c;
|
||||
this->bufPos++;
|
||||
if (c == '\n' || this->bufPos >= this->bufSitze - 1) {
|
||||
this->buf[this->bufPos - 1] = '\0';
|
||||
this->sendMsg(Loglevel::info, buf);
|
||||
this->bufPos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void DebugMqtt::init(PubSubClient *client, Loglevel max_loglevel) {
|
||||
DebugMqtt::client = client;
|
||||
DebugMqtt::loglevel = loglevel;
|
||||
DebugMqtt::loglevel = max_loglevel;
|
||||
DebugMqtt::isInit = true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user