diff --git a/paho_mqtt_embedded_c/MQTTClient/src/MQTTClient.h b/paho_mqtt_embedded_c/MQTTClient/src/MQTTClient.h index 6afd927..5309f19 100644 --- a/paho_mqtt_embedded_c/MQTTClient/src/MQTTClient.h +++ b/paho_mqtt_embedded_c/MQTTClient/src/MQTTClient.h @@ -114,7 +114,6 @@ class Client { public: - typedef void (*messageHandler)(MessageData&); /** Construct the client @@ -234,10 +233,9 @@ class Client { return isconnected; } - -private: - void closeSession(); + +private: void cleanSession(); int cycle(Timer& timer); int waitfor(int packet_type, Timer& timer); @@ -256,7 +254,9 @@ class Client unsigned char sendbuf[MAX_MQTT_PACKET_SIZE]; unsigned char readbuf[MAX_MQTT_PACKET_SIZE]; - Timer last_sent, last_received; + Timer last_sent; + Timer last_received; + Timer ping_sent; unsigned int keepAliveInterval; bool ping_outstanding; bool cleansession; @@ -318,6 +318,9 @@ void MQTT::Client::cleanSession() template void MQTT::Client::closeSession() { + last_sent.stop(); + last_received.stop(); + ping_sent.stop(); ping_outstanding = false; isconnected = false; if (cleansession) @@ -700,7 +703,6 @@ template int MQTT::Client::keepalive() { int rc = SUCCESS; - static Timer ping_sent; if (keepAliveInterval == 0) goto exit; @@ -1066,6 +1068,9 @@ int MQTT::Client::disconnect() if (len > 0) rc = sendPacket(len, timer); // send the disconnect packet closeSession(); + last_sent.stop(); + last_received.stop(); + ping_sent.stop(); return rc; } diff --git a/paho_mqtt_embedded_c/MQTTClient/src/mbed/MQTTmbed.h b/paho_mqtt_embedded_c/MQTTClient/src/mbed/MQTTmbed.h index 46f00e6..82c9492 100644 --- a/paho_mqtt_embedded_c/MQTTClient/src/mbed/MQTTmbed.h +++ b/paho_mqtt_embedded_c/MQTTClient/src/mbed/MQTTmbed.h @@ -36,7 +36,7 @@ class Countdown bool expired() { - return t.read_ms() >= interval_end_ms; + return (unsigned long)t.read_ms() >= interval_end_ms; } void countdown_ms(unsigned long ms) @@ -57,6 +57,12 @@ class Countdown return interval_end_ms - t.read_ms(); } + void stop() + { + t.stop(); + t.reset(); + } + private: Timer t; unsigned long interval_end_ms; diff --git a/src/MQTTClientMbedOs.cpp b/src/MQTTClientMbedOs.cpp index 611e696..561d865 100644 --- a/src/MQTTClientMbedOs.cpp +++ b/src/MQTTClientMbedOs.cpp @@ -214,3 +214,8 @@ void MQTTClient::init(Socket *sock) client = NULL; clientSN = NULL; } + +void MQTTClient::mqttClientCloseSession() +{ + client->closeSession(); +} diff --git a/src/MQTTClientMbedOs.h b/src/MQTTClientMbedOs.h index a3459e6..81e16ea 100644 --- a/src/MQTTClientMbedOs.h +++ b/src/MQTTClientMbedOs.h @@ -22,7 +22,7 @@ #include #include #include -#include "unity/unity.h" +// #include "unity/unity.h" #include "FP.h" #include @@ -234,6 +234,8 @@ class MQTTClient { */ nsapi_error_t setMessageHandler(const char *topicFilter, messageHandler mh); + void mqttClientCloseSession(); + private: /** * @brief Helper function to initialize member variables.