Better debugging code
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
// vim: ts=2 sw=2 expandtab smartindent
|
// vim: ts=2 sw=2 expandtab smartindent
|
||||||
#define TINY_MQTT_DEBUG
|
|
||||||
#include <TinyConsole.h>
|
#include <TinyConsole.h>
|
||||||
#include <TinyMqtt.h> // https://github.com/hsaturn/TinyMqtt
|
#include <TinyMqtt.h> // https://github.com/hsaturn/TinyMqtt
|
||||||
#include <TinyStreaming.h>
|
#include <TinyStreaming.h>
|
||||||
@@ -410,7 +409,11 @@ void eval(std::string& cmd)
|
|||||||
{}
|
{}
|
||||||
else if (compare(s, "debug"))
|
else if (compare(s, "debug"))
|
||||||
{
|
{
|
||||||
|
#if TINY_MQTT_DEBUG
|
||||||
TinyMqtt::debug = getint(cmd);
|
TinyMqtt::debug = getint(cmd);
|
||||||
|
#else
|
||||||
|
Console << red << "TinyMqtt not compiled in debug" << endl;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (compare(s, "list"))
|
else if (compare(s, "list"))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
#include "TinyMqtt.h"
|
#include "TinyMqtt.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
static auto cyan = TinyConsole::cyan;
|
static auto cyan = TinyConsole::cyan;
|
||||||
static auto white = TinyConsole::white;
|
static auto white = TinyConsole::white;
|
||||||
static auto red = TinyConsole::red;
|
static auto red = TinyConsole::red;
|
||||||
@@ -221,7 +221,7 @@ MqttError MqttBroker::publish(const MqttClient* source, const Topic& topic, Mqtt
|
|||||||
for(auto client: clients)
|
for(auto client: clients)
|
||||||
{
|
{
|
||||||
i++;
|
i++;
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
Console << __LINE__ << " broker:" << (broker && broker->connected() ? "linked" : "alone") <<
|
Console << __LINE__ << " broker:" << (broker && broker->connected() ? "linked" : "alone") <<
|
||||||
" srce=" << (source->isLocal() ? "loc" : "rem") << " clt#" << i << ", local=" << client->isLocal() << ", con=" << client->connected() << endl;
|
" srce=" << (source->isLocal() ? "loc" : "rem") << " clt#" << i << ", local=" << client->isLocal() << ", con=" << client->connected() << endl;
|
||||||
#endif
|
#endif
|
||||||
@@ -242,7 +242,7 @@ MqttError MqttBroker::publish(const MqttClient* source, const Topic& topic, Mqtt
|
|||||||
{
|
{
|
||||||
doit = true;
|
doit = true;
|
||||||
}
|
}
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
Console << ", doit=" << doit << ' ';
|
Console << ", doit=" << doit << ' ';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -426,7 +426,7 @@ MqttError MqttClient::sendTopic(const Topic& topic, MqttMessage::Type type, uint
|
|||||||
|
|
||||||
void MqttClient::processMessage(MqttMessage* mesg)
|
void MqttClient::processMessage(MqttMessage* mesg)
|
||||||
{
|
{
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
mesg->hexdump("Incoming");
|
mesg->hexdump("Incoming");
|
||||||
#endif
|
#endif
|
||||||
auto header = mesg->getVHeader();
|
auto header = mesg->getVHeader();
|
||||||
@@ -487,7 +487,7 @@ void MqttClient::processMessage(MqttMessage* mesg)
|
|||||||
payload += len;
|
payload += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
Console << yellow << "Client " << clientId << " connected : keep alive=" << keep_alive << '.' << white << endl;
|
Console << yellow << "Client " << clientId << " connected : keep alive=" << keep_alive << '.' << white << endl;
|
||||||
#endif
|
#endif
|
||||||
bclose = false;
|
bclose = false;
|
||||||
@@ -585,7 +585,7 @@ void MqttClient::processMessage(MqttMessage* mesg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MqttMessage::Type::Publish:
|
case MqttMessage::Type::Publish:
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
Console << "publish " << mqtt_connected << '/' << (long) client << endl;
|
Console << "publish " << mqtt_connected << '/' << (long) client << endl;
|
||||||
#endif
|
#endif
|
||||||
if (mqtt_connected or client == nullptr)
|
if (mqtt_connected or client == nullptr)
|
||||||
@@ -595,7 +595,7 @@ void MqttClient::processMessage(MqttMessage* mesg)
|
|||||||
mesg->getString(payload, len);
|
mesg->getString(payload, len);
|
||||||
Topic published(payload, len);
|
Topic published(payload, len);
|
||||||
payload += len;
|
payload += len;
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
Console << "Received Publish (" << published.str().c_str() << ") size=" << (int)len << endl;
|
Console << "Received Publish (" << published.str().c_str() << ") size=" << (int)len << endl;
|
||||||
#endif
|
#endif
|
||||||
// << '(' << std::string(payload, len).c_str() << ')' << " msglen=" << mesg->length() << endl;
|
// << '(' << std::string(payload, len).c_str() << ')' << " msglen=" << mesg->length() << endl;
|
||||||
@@ -606,7 +606,7 @@ void MqttClient::processMessage(MqttMessage* mesg)
|
|||||||
|
|
||||||
if (local_broker==nullptr or client==nullptr) // internal MqttClient receives publish
|
if (local_broker==nullptr or client==nullptr) // internal MqttClient receives publish
|
||||||
{
|
{
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
if (TinyMqtt::debug >= 2)
|
if (TinyMqtt::debug >= 2)
|
||||||
{
|
{
|
||||||
Console << (isSubscribedTo(published) ? "not" : "") << " subscribed.\n";
|
Console << (isSubscribedTo(published) ? "not" : "") << " subscribed.\n";
|
||||||
@@ -641,7 +641,7 @@ void MqttClient::processMessage(MqttMessage* mesg)
|
|||||||
};
|
};
|
||||||
if (bclose)
|
if (bclose)
|
||||||
{
|
{
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
Console << red << "*************** Error msg 0x" << _HEX(mesg->type());
|
Console << red << "*************** Error msg 0x" << _HEX(mesg->type());
|
||||||
mesg->hexdump("-------ERROR ------");
|
mesg->hexdump("-------ERROR ------");
|
||||||
dump();
|
dump();
|
||||||
@@ -750,7 +750,7 @@ MqttError MqttClient::publishIfSubscribed(const Topic& topic, MqttMessage& msg)
|
|||||||
{
|
{
|
||||||
processMessage(&msg);
|
processMessage(&msg);
|
||||||
|
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
Console << "Should call the callback ?\n";
|
Console << "Should call the callback ?\n";
|
||||||
#endif
|
#endif
|
||||||
// callback(this, topic, nullptr, 0); // TODO Payload
|
// callback(this, topic, nullptr, 0); // TODO Payload
|
||||||
@@ -819,7 +819,7 @@ void MqttMessage::incoming(char in_byte)
|
|||||||
break;
|
break;
|
||||||
case Complete:
|
case Complete:
|
||||||
default:
|
default:
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
Console << red << "Spurious " << _HEX(in_byte) << white << endl;
|
Console << red << "Spurious " << _HEX(in_byte) << white << endl;
|
||||||
hexdump("spurious");
|
hexdump("spurious");
|
||||||
#endif
|
#endif
|
||||||
@@ -888,7 +888,7 @@ MqttError MqttMessage::sendTo(MqttClient* client)
|
|||||||
void MqttMessage::hexdump(const char* prefix) const
|
void MqttMessage::hexdump(const char* prefix) const
|
||||||
{
|
{
|
||||||
(void)prefix;
|
(void)prefix;
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
if (TinyMqtt::debug<2) return;
|
if (TinyMqtt::debug<2) return;
|
||||||
static std::map<Type, std::string> tts={
|
static std::map<Type, std::string> tts={
|
||||||
{ Connect, "Connect" },
|
{ Connect, "Connect" },
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// vim: ts=2 sw=2 expandtab
|
// vim: ts=2 sw=2 expandtab
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#define TINY_MQTT_DEBUG 0
|
||||||
|
|
||||||
// TODO Should add a AUnit with both TINY_MQTT_ASYNC and not TINY_MQTT_ASYNC
|
// TODO Should add a AUnit with both TINY_MQTT_ASYNC and not TINY_MQTT_ASYNC
|
||||||
// #define TINY_MQTT_ASYNC // Uncomment this to use ESPAsyncTCP instead of normal cnx
|
// #define TINY_MQTT_ASYNC // Uncomment this to use ESPAsyncTCP instead of normal cnx
|
||||||
@@ -34,7 +35,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "StringIndexer.h"
|
#include "StringIndexer.h"
|
||||||
|
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
#include <TinyStreaming.h>
|
#include <TinyStreaming.h>
|
||||||
#include <TinyConsole.h> // https://github.com/hsaturn/TinyConsole
|
#include <TinyConsole.h> // https://github.com/hsaturn/TinyConsole
|
||||||
struct TinyMqtt
|
struct TinyMqtt
|
||||||
@@ -202,7 +203,7 @@ class MqttClient
|
|||||||
void setCallback(CallBack fun)
|
void setCallback(CallBack fun)
|
||||||
{
|
{
|
||||||
callback=fun;
|
callback=fun;
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
Console << TinyConsole::magenta << "Callback set to " << (long)fun << TinyConsole::white << endl;
|
Console << TinyConsole::magenta << "Callback set to " << (long)fun << TinyConsole::white << endl;
|
||||||
if (callback) callback(this, "test/topic", "value", 5);
|
if (callback) callback(this, "test/topic", "value", 5);
|
||||||
#endif
|
#endif
|
||||||
@@ -226,7 +227,7 @@ class MqttClient
|
|||||||
void dump(std::string indent="")
|
void dump(std::string indent="")
|
||||||
{
|
{
|
||||||
(void)indent;
|
(void)indent;
|
||||||
#ifdef TINY_MQTT_DEBUG
|
#if TINY_MQTT_DEBUG
|
||||||
uint32_t ms=millis();
|
uint32_t ms=millis();
|
||||||
Console << indent << "+-- " << '\'' << clientId.c_str() << "' " << (connected() ? " ON " : " OFF");
|
Console << indent << "+-- " << '\'' << clientId.c_str() << "' " << (connected() ? " ON " : " OFF");
|
||||||
Console << ", alive=" << alive << '/' << ms << ", ka=" << keep_alive << ' ';
|
Console << ", alive=" << alive << '/' << ms << ", ka=" << keep_alive << ' ';
|
||||||
|
|||||||
Reference in New Issue
Block a user