diff --git a/src/TinyMqtt.cpp b/src/TinyMqtt.cpp index d6e95cf..1d567b1 100644 --- a/src/TinyMqtt.cpp +++ b/src/TinyMqtt.cpp @@ -1,6 +1,10 @@ #include "TinyMqtt.h" #include +#ifdef EPOXY_DUINO + std::map MqttClient::counters; +#endif + MqttBroker::MqttBroker(uint16_t port) { server = new TcpServer(port); @@ -30,7 +34,11 @@ MqttClient::MqttClient(MqttBroker* parent, TcpClient* new_client) #else client = new WiFiClient(*new_client); #endif +#ifdef EPOXY_DUINO + alive = millis()+500000; +#else alive = millis()+5000; // TODO MAGIC client expires after 5s if no CONNECT msg +#endif } MqttClient::MqttClient(MqttBroker* parent, const std::string& id) @@ -242,7 +250,11 @@ void MqttClient::clientAlive(uint32_t more_seconds) { if (keep_alive) { +#ifdef EPOXY_DUINO + alive=millis()+500000; +#else alive=millis()+1000*(keep_alive+more_seconds); +#endif } else alive=0; @@ -387,11 +399,8 @@ MqttError MqttClient::sendTopic(const Topic& topic, MqttMessage::Type type, uint return msg.sendTo(this); } -long MqttClient::counter=0; - void MqttClient::processMessage(MqttMessage* mesg) { - counter++; #ifdef TINY_MQTT_DEBUG 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; switch(mesg->type() & 0XF0) +#ifdef EPOXY_DUINO + counters[mesg->type()]++; +#endif + { case MqttMessage::Type::Connect: if (mqtt_connected) diff --git a/src/TinyMqtt.h b/src/TinyMqtt.h index 8a17500..78e34d4 100644 --- a/src/TinyMqtt.h +++ b/src/TinyMqtt.h @@ -223,7 +223,9 @@ class MqttClient #endif } - static long counter; // Number of processed messages +#ifdef EPOXY_DUINO + static std::map counters; // Number of processed messages +#endif private: diff --git a/tests/howto b/tests/howto index cc4dda2..e629f0f 100644 --- a/tests/howto +++ b/tests/howto @@ -4,3 +4,4 @@ git clone https://github.com/bxparks/AUnit.git git clone https://github.com/bxparks/EpoxyDuino.git cd TinyMqtt/tests make +make runtests