d
Revision 60:f1a42823e381, committed 2022-03-20
- Comitter:
- JavierGC
- Date:
- Sun Mar 20 19:25:46 2022 +0000
- Parent:
- 59:9cff7b6bbd01
- Commit message:
- Rev1.0
Changed in this revision
MQTTClient.h | Show annotated file Show diff for this revision Revisions of this file |
MQTTSocket.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 9cff7b6bbd01 -r f1a42823e381 MQTTClient.h --- a/MQTTClient.h Thu Nov 02 12:12:41 2017 +0000 +++ b/MQTTClient.h Sun Mar 20 19:25:46 2022 +0000 @@ -108,7 +108,7 @@ * @param Network a network class which supports send, receive * @param Timer a timer class with the methods: */ -template<class Network, class Timer, int MAX_MQTT_PACKET_SIZE = 100, int MAX_MESSAGE_HANDLERS = 5> +template<class Network, class Timer, int MAX_MQTT_PACKET_SIZE = 100, int MAX_MESSAGE_HANDLERS = 11> class Client { @@ -428,10 +428,14 @@ goto exit; } rc = ipstack.read(&c, 1, timeout); + //printf("decode: %d\r\n",rc); if (rc != 1) goto exit; *value += (c & 127) * multiplier; multiplier *= 128; + //printf("c: %d\r\n",c); + //printf("value: %d\r\n",value); + //printf("multiplier: %d\r\n",multiplier); } while ((c & 128) != 0); exit: return len; @@ -454,6 +458,8 @@ /* 1. read the header byte. This has the packet type in it */ rc = ipstack.read(readbuf, 1, timer.left_ms()); + //printf("read: %d\r\n",rc); + //printf("%c\r\n",readbuf[0]); if (rc != 1) goto exit; @@ -564,7 +570,14 @@ timer.countdown_ms(timeout_ms); while (!timer.expired()) { - if (cycle(timer) < 0) + //printf("while...\r\n"); + int ans=cycle(timer); + if (ans == -3004) + { + rc = -3004; + break; + } + else if (ans < 0) { rc = FAILURE; break; @@ -582,15 +595,22 @@ int len = 0, rc = SUCCESS; + int packet_type = readPacket(timer); // read the socket, see what work is due + //printf("packet_type: %d\r\n",packet_type); switch (packet_type) { default: // no more data to read, unrecoverable. Or read packet fails due to unexpected network error rc = packet_type; + //printf("default\r\n"); goto exit; case 0: // timed out reading packet + //printf("timeout\r\n"); + break; + case -3001: // timed out reading packet + //printf("timeout\r\n"); break; case CONNACK: case PUBACK:
diff -r 9cff7b6bbd01 -r f1a42823e381 MQTTSocket.h --- a/MQTTSocket.h Thu Nov 02 12:12:41 2017 +0000 +++ b/MQTTSocket.h Sun Mar 20 19:25:46 2022 +0000 @@ -22,7 +22,8 @@ open = true; mysock.set_blocking(true); mysock.set_timeout((unsigned int)timeout); - rc = mysock.connect(hostname, port); + SocketAddress socketAddr(hostname,port); + rc = mysock.connect(socketAddr); mysock.set_blocking(false); // blocking timeouts seem not to work return rc; } @@ -39,7 +40,7 @@ if (first) first = false; else - wait_ms(timeout < 100 ? timeout : 100); + wait_us((timeout*1000) < 100 ? (timeout*1000) : 100); int rc; if (read) rc = mysock.recv((char*)buffer, len); @@ -68,6 +69,16 @@ { return common(buffer, len, timeout, true); } + + + /*int read(unsigned char* buffer, int len, int timeout) + { + mysock.set_timeout(timeout); + int rc = mysock.recv((char*)buffer, len); + mysock.set_timeout(0); + return rc; + } +*/ int write(unsigned char* buffer, int len, int timeout) {