documentation checked and edit
for all files in lib folder
This commit is contained in:
+48
-35
@@ -5,101 +5,115 @@
|
||||
* @see debugMqtt.h
|
||||
* @version 0.1
|
||||
* @date 2021-12-13
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (c) 2021
|
||||
*
|
||||
*
|
||||
*/
|
||||
#include "debugMqtt.h"
|
||||
|
||||
PubSubClient* DebugMqtt::client;
|
||||
PubSubClient *DebugMqtt::client;
|
||||
Loglevel DebugMqtt::loglevel;
|
||||
bool DebugMqtt::isInit = false;
|
||||
char DebugMqtt::msg[MQTT_BUFFER_SIZE];
|
||||
char DebugMqtt::topic[MQTT_BUFFER_SIZE];
|
||||
|
||||
|
||||
DebugMqtt::DebugMqtt(const char* name, uint8_t bufSize)
|
||||
: name {name}
|
||||
DebugMqtt::DebugMqtt(const char *name, uint8_t bufSize)
|
||||
: name{name}
|
||||
{
|
||||
if (bufSize != 0) {
|
||||
if (bufSize != 0)
|
||||
{
|
||||
this->bufSize = bufSize;
|
||||
}
|
||||
this->buf = new char[this->bufSize];
|
||||
}
|
||||
|
||||
DebugMqtt::~DebugMqtt() {
|
||||
DebugMqtt::~DebugMqtt()
|
||||
{
|
||||
delete this->buf;
|
||||
}
|
||||
|
||||
void DebugMqtt::sendMsg(Loglevel loglevel, String topic, String msg) {
|
||||
snprintf (static_cast<char*>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char*>("%s: %s"),this->name ,msg.c_str());
|
||||
this->sendData(loglevel, topic, static_cast<const char*>(DebugMqtt::msg));
|
||||
void DebugMqtt::sendMsg(Loglevel loglevel, String topic, String msg)
|
||||
{
|
||||
snprintf(static_cast<char *>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char *>("%s: %s"), this->name, msg.c_str());
|
||||
this->sendData(loglevel, topic, static_cast<const char *>(DebugMqtt::msg));
|
||||
}
|
||||
|
||||
void DebugMqtt::sendMsg(Loglevel loglevel, String msg) {
|
||||
void DebugMqtt::sendMsg(Loglevel loglevel, String msg)
|
||||
{
|
||||
this->sendMsg(loglevel, "", msg);
|
||||
}
|
||||
|
||||
void DebugMqtt::sendData(Loglevel loglevel, String topic, String data) {
|
||||
if (!DebugMqtt::isInit) {
|
||||
void DebugMqtt::sendData(Loglevel loglevel, String topic, String data)
|
||||
{
|
||||
if (!DebugMqtt::isInit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (loglevel <= DebugMqtt::loglevel && loglevel > Loglevel::none) {
|
||||
snprintf (static_cast<char*>(DebugMqtt::topic), MQTT_BUFFER_SIZE, static_cast<const char*>("%s%s"), DebugMqtt::enum_to_string(loglevel).c_str(), topic.c_str());
|
||||
snprintf (static_cast<char*>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char*>("%s"), data.c_str());
|
||||
client->publish(DebugMqtt::topic, static_cast<const char*>(DebugMqtt::msg));
|
||||
if (loglevel <= DebugMqtt::loglevel && loglevel > Loglevel::none)
|
||||
{
|
||||
snprintf(static_cast<char *>(DebugMqtt::topic), MQTT_BUFFER_SIZE, static_cast<const char *>("%s%s"), DebugMqtt::enum_to_string(loglevel).c_str(), topic.c_str());
|
||||
snprintf(static_cast<char *>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char *>("%s"), data.c_str());
|
||||
client->publish(DebugMqtt::topic, static_cast<const char *>(DebugMqtt::msg));
|
||||
}
|
||||
}
|
||||
|
||||
void DebugMqtt::sendData(Loglevel loglevel, String data){
|
||||
void DebugMqtt::sendData(Loglevel loglevel, String data)
|
||||
{
|
||||
DebugMqtt::sendData(loglevel, "", data);
|
||||
}
|
||||
|
||||
void DebugMqtt::writeToInflux(String measurement_name, String field_set, float measurement, uint64_t nanos) {
|
||||
void DebugMqtt::writeToInflux(String measurement_name, String field_set, float measurement, uint64_t nanos)
|
||||
{
|
||||
// Example String: "weather temperature=82 1465839830100400200";
|
||||
|
||||
snprintf(static_cast<char*>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char*>("%s %s=%f %llu"), measurement_name.c_str(), field_set.c_str(), measurement, nanos);
|
||||
this->sendData(Loglevel::influx, static_cast<const char*>(DebugMqtt::msg));
|
||||
snprintf(static_cast<char *>(DebugMqtt::msg), MQTT_BUFFER_SIZE, static_cast<const char *>("%s %s=%f %llu"), measurement_name.c_str(), field_set.c_str(), measurement, nanos);
|
||||
this->sendData(Loglevel::influx, static_cast<const char *>(DebugMqtt::msg));
|
||||
}
|
||||
|
||||
void DebugMqtt::addCharacter(char character) {
|
||||
void DebugMqtt::addCharacter(char character)
|
||||
{
|
||||
this->buf[this->bufPos] = character;
|
||||
this->bufPos++;
|
||||
if (character == '\n' || this->bufPos >= this->bufSize - 1) {
|
||||
if (character == '\n' || this->bufPos >= this->bufSize - 1)
|
||||
{
|
||||
this->buf[this->bufPos - 1] = '\0';
|
||||
this->sendMsg(Loglevel::info, buf);
|
||||
this->bufPos = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void DebugMqtt::init(PubSubClient *client, Loglevel max_loglevel) {
|
||||
void DebugMqtt::init(PubSubClient *client, Loglevel max_loglevel)
|
||||
{
|
||||
DebugMqtt::client = client;
|
||||
DebugMqtt::loglevel = max_loglevel;
|
||||
DebugMqtt::isInit = true;
|
||||
}
|
||||
|
||||
void DebugMqtt::changeLoglevel(Loglevel loglevel) {
|
||||
void DebugMqtt::changeLoglevel(Loglevel loglevel)
|
||||
{
|
||||
DebugMqtt::loglevel = loglevel;
|
||||
}
|
||||
|
||||
String DebugMqtt::enum_to_string(Loglevel loglevel) {
|
||||
String DebugMqtt::enum_to_string(Loglevel loglevel)
|
||||
{
|
||||
String topic = "";
|
||||
topic += MQTT_DEBUG_TOPIC;
|
||||
switch(loglevel){
|
||||
case Loglevel::error :
|
||||
switch (loglevel)
|
||||
{
|
||||
case Loglevel::error:
|
||||
topic += "/Error";
|
||||
break;
|
||||
case Loglevel::warn :
|
||||
case Loglevel::warn:
|
||||
topic += "/Warn";
|
||||
break;
|
||||
case Loglevel::info :
|
||||
case Loglevel::info:
|
||||
topic += "/Info";
|
||||
break;
|
||||
case Loglevel::debug :
|
||||
case Loglevel::debug:
|
||||
topic += "/Debug";
|
||||
break;
|
||||
case Loglevel::influx :
|
||||
case Loglevel::influx:
|
||||
topic += "/Influx";
|
||||
break;
|
||||
default:
|
||||
@@ -107,5 +121,4 @@ String DebugMqtt::enum_to_string(Loglevel loglevel) {
|
||||
break;
|
||||
}
|
||||
return topic;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user