test
Fork of MQTT by
Revision 56:30f7b745eaaa, committed 2017-11-27
- Comitter:
- DuyLionTran
- Date:
- Mon Nov 27 11:06:38 2017 +0000
- Parent:
- 52:3f9919941b86
- Child:
- 61:36e76acf2166
- Commit message:
- new version
Changed in this revision
MQTTClient.h | Show annotated file Show diff for this revision Revisions of this file |
MQTTmbed.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MQTTClient.h Mon Sep 25 11:12:23 2017 +0000 +++ b/MQTTClient.h Mon Nov 27 11:06:38 2017 +0000 @@ -336,7 +336,10 @@ { rc = ipstack.write(&sendbuf[sent], length - sent, timer.left_ms()); if (rc < 0) // there was an error writing the data + { + printf("sendPacket fail %d\n", rc); break; + } sent += rc; } if (sent == length) @@ -504,7 +507,7 @@ int MQTT::Client<Network, Timer, a, b>::yield(unsigned long timeout_ms) { int rc = SUCCESS; - Timer timer = Timer(); + Timer timer; timer.countdown_ms(timeout_ms); while (!timer.expired()) @@ -530,7 +533,6 @@ int len = 0, rc = SUCCESS; - switch (packet_type) { case FAILURE: @@ -609,6 +611,7 @@ exit: if (rc == SUCCESS) rc = packet_type; + return rc; } @@ -645,9 +648,8 @@ int MQTT::Client<Network, Timer, a, b>::waitfor(int packet_type, Timer& timer) { int rc = FAILURE; - do - { + { if (timer.expired()) break; // we timed out } @@ -709,8 +711,9 @@ #endif exit: - if (rc == SUCCESS) + if (rc == SUCCESS) { isconnected = true; + } return rc; } @@ -732,13 +735,21 @@ MQTTString topic = {(char*)topicFilter, {0, 0}}; if (!isconnected) + { + printf("Not connected\r\n"); goto exit; + } - len = MQTTSerialize_subscribe(sendbuf, MAX_MQTT_PACKET_SIZE, 0, packetid.getNext(), 1, &topic, (int*)&qos); + len = MQTTSerialize_subscribe(sendbuf, MAX_MQTT_PACKET_SIZE, 0, packetid.getNext(), 1, &topic, (int)qos); if (len <= 0) + { goto exit; + } + if ((rc = sendPacket(len, timer)) != SUCCESS) // send the subscribe packet + { goto exit; // there was a problem + } if (waitfor(SUBACK, timer) == SUBACK) // wait for suback { @@ -761,7 +772,9 @@ } } else + { rc = FAILURE; + } exit: if (rc != SUCCESS) @@ -778,8 +791,10 @@ MQTTString topic = {(char*)topicFilter, {0, 0}}; int len = 0; - if (!isconnected) - goto exit; + if (!isconnected) { + + goto exit; + } if ((len = MQTTSerialize_unsubscribe(sendbuf, MAX_MQTT_PACKET_SIZE, 0, packetid.getNext(), 1, &topic)) <= 0) goto exit; @@ -870,16 +885,15 @@ MQTTString topicString = MQTTString_initializer; int len = 0; - if (!isconnected) + if (!isconnected) { goto exit; - + } topicString.cstring = (char*)topicName; #if MQTTCLIENT_QOS1 || MQTTCLIENT_QOS2 if (qos == QOS1 || qos == QOS2) id = packetid.getNext(); #endif - len = MQTTSerialize_publish(sendbuf, MAX_MQTT_PACKET_SIZE, 0, qos, retained, id, topicString, (unsigned char*)payload, payloadlen); if (len <= 0)
--- a/MQTTmbed.h Mon Sep 25 11:12:23 2017 +0000 +++ b/MQTTmbed.h Mon Nov 27 11:06:38 2017 +0000 @@ -6,13 +6,14 @@ class Countdown { public: - Countdown() : t() + Countdown() { - + t = Timer(); } - Countdown(int ms) : t() + Countdown(int ms) { + t = Timer(); countdown_ms(ms); }