Added some ifdef for debugging purposes

This commit is contained in:
hsaturn
2022-01-05 01:56:45 +01:00
parent f1d3a15498
commit a5b8afc0bd
3 changed files with 20 additions and 4 deletions

View File

@@ -1,6 +1,10 @@
#include "TinyMqtt.h" #include "TinyMqtt.h"
#include <sstream> #include <sstream>
#ifdef EPOXY_DUINO
std::map<MqttMessage::Type, int> MqttClient::counters;
#endif
MqttBroker::MqttBroker(uint16_t port) MqttBroker::MqttBroker(uint16_t port)
{ {
server = new TcpServer(port); server = new TcpServer(port);
@@ -30,7 +34,11 @@ MqttClient::MqttClient(MqttBroker* parent, TcpClient* new_client)
#else #else
client = new WiFiClient(*new_client); client = new WiFiClient(*new_client);
#endif #endif
#ifdef EPOXY_DUINO
alive = millis()+500000;
#else
alive = millis()+5000; // TODO MAGIC client expires after 5s if no CONNECT msg alive = millis()+5000; // TODO MAGIC client expires after 5s if no CONNECT msg
#endif
} }
MqttClient::MqttClient(MqttBroker* parent, const std::string& id) MqttClient::MqttClient(MqttBroker* parent, const std::string& id)
@@ -242,7 +250,11 @@ void MqttClient::clientAlive(uint32_t more_seconds)
{ {
if (keep_alive) if (keep_alive)
{ {
#ifdef EPOXY_DUINO
alive=millis()+500000;
#else
alive=millis()+1000*(keep_alive+more_seconds); alive=millis()+1000*(keep_alive+more_seconds);
#endif
} }
else else
alive=0; alive=0;
@@ -387,11 +399,8 @@ MqttError MqttClient::sendTopic(const Topic& topic, MqttMessage::Type type, uint
return msg.sendTo(this); return msg.sendTo(this);
} }
long MqttClient::counter=0;
void MqttClient::processMessage(MqttMessage* mesg) void MqttClient::processMessage(MqttMessage* mesg)
{ {
counter++;
#ifdef TINY_MQTT_DEBUG #ifdef TINY_MQTT_DEBUG
if (mesg->type() != MqttMessage::Type::PingReq && mesg->type() != MqttMessage::Type::PingResp) if (mesg->type() != MqttMessage::Type::PingReq && mesg->type() != MqttMessage::Type::PingResp)
{ {
@@ -410,6 +419,10 @@ if (mesg->type() != MqttMessage::Type::PingReq && mesg->type() != MqttMessage::T
bool bclose=true; bool bclose=true;
switch(mesg->type() & 0XF0) switch(mesg->type() & 0XF0)
#ifdef EPOXY_DUINO
counters[mesg->type()]++;
#endif
{ {
case MqttMessage::Type::Connect: case MqttMessage::Type::Connect:
if (mqtt_connected) if (mqtt_connected)

View File

@@ -223,7 +223,9 @@ class MqttClient
#endif #endif
} }
static long counter; // Number of processed messages #ifdef EPOXY_DUINO
static std::map<MqttMessage::Type, int> counters; // Number of processed messages
#endif
private: private:

View File

@@ -4,3 +4,4 @@ git clone https://github.com/bxparks/AUnit.git
git clone https://github.com/bxparks/EpoxyDuino.git git clone https://github.com/bxparks/EpoxyDuino.git
cd TinyMqtt/tests cd TinyMqtt/tests
make make
make runtests