From 54043f5469a307157d990b64454f5e8b30365a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Augusto?= Date: Tue, 14 Nov 2017 22:34:33 -0300 Subject: [PATCH 1/3] Start --- nada.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 nada.txt diff --git a/nada.txt b/nada.txt new file mode 100644 index 0000000..1fa1684 --- /dev/null +++ b/nada.txt @@ -0,0 +1 @@ +nada From 6bc3b76a9b3a8a79e3dfc1af78ccacf29d549fc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Augusto?= Date: Thu, 7 Dec 2017 12:20:23 -0300 Subject: [PATCH 2/3] Adding improvments --- .gitignore | 4 ++++ examples/mqtt_esp8266/mqtt_esp8266.ino | 5 ----- src/PubSubClient.cpp | 18 +++++++++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 1c3ba18..a42cc40 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ tests/bin +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json diff --git a/examples/mqtt_esp8266/mqtt_esp8266.ino b/examples/mqtt_esp8266/mqtt_esp8266.ino index 34333c9..ef4ab28 100644 --- a/examples/mqtt_esp8266/mqtt_esp8266.ino +++ b/examples/mqtt_esp8266/mqtt_esp8266.ino @@ -1,26 +1,21 @@ /* Basic ESP8266 MQTT example - This sketch demonstrates the capabilities of the pubsub library in combination with the ESP8266 board/library. - It connects to an MQTT server then: - publishes "hello world" to the topic "outTopic" every two seconds - subscribes to the topic "inTopic", printing out any messages it receives. NB - it assumes the received payloads are strings not binary - If the first character of the topic "inTopic" is an 1, switch ON the ESP Led, else switch it off - It will reconnect to the server if the connection is lost using a blocking reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to achieve the same result without blocking the main loop. - To install the ESP8266 board, (using Arduino 1.6.4+): - Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs": http://arduino.esp8266.com/stable/package_esp8266com_index.json - Open the "Tools -> Board -> Board Manager" and click install for the ESP8266" - Select your ESP8266 in "Tools -> Board" - */ #include diff --git a/src/PubSubClient.cpp b/src/PubSubClient.cpp index 5932bdb..1e12375 100755 --- a/src/PubSubClient.cpp +++ b/src/PubSubClient.cpp @@ -1,4 +1,5 @@ /* + PubSubClient.cpp - A simple client for MQTT. Nick O'Leary http://knolleary.net @@ -243,7 +244,8 @@ uint16_t PubSubClient::readPacket(uint8_t* lengthLength) { if(!readByte(&digit)) return 0; buffer[len++] = digit; length += (digit & 127) * multiplier; - multiplier *= 128; + //multiplier *= 128; replace by multiplier <<=7; + multiplier <<=7; } while ((digit & 128) != 0); *lengthLength = len-1; @@ -399,8 +401,11 @@ boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsig buffer[pos++] = header; len = plength + 2 + tlen; do { - digit = len % 128; - len = len / 128; + //digit = len %128; replace by digit = len & 127; + digit = len & 127; + + //len = len / 128; replace by len >>= 7; + len >>= 7; if (len > 0) { digit |= 0x80; } @@ -429,8 +434,11 @@ boolean PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length) { uint16_t rc; uint16_t len = length; do { - digit = len % 128; - len = len / 128; + //digit = len %128; replace by digit = len & 127; + digit = len & 127; + + //len = len / 128; replace by len >>= 7; + len >>= 7; if (len > 0) { digit |= 0x80; } From 3b0775a91d2168000f370d89628ecb818de4a7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Augusto?= Date: Thu, 7 Dec 2017 15:31:24 -0300 Subject: [PATCH 3/3] Excluding nada.txt which was empty and improving indentation --- nada.txt | 1 - src/PubSubClient.cpp | 16 +++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) delete mode 100644 nada.txt diff --git a/nada.txt b/nada.txt deleted file mode 100644 index 1fa1684..0000000 --- a/nada.txt +++ /dev/null @@ -1 +0,0 @@ -nada diff --git a/src/PubSubClient.cpp b/src/PubSubClient.cpp index 1e12375..7686c8b 100755 --- a/src/PubSubClient.cpp +++ b/src/PubSubClient.cpp @@ -244,8 +244,7 @@ uint16_t PubSubClient::readPacket(uint8_t* lengthLength) { if(!readByte(&digit)) return 0; buffer[len++] = digit; length += (digit & 127) * multiplier; - //multiplier *= 128; replace by multiplier <<=7; - multiplier <<=7; + multiplier <<=7; //multiplier *= 128 } while ((digit & 128) != 0); *lengthLength = len-1; @@ -401,11 +400,8 @@ boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsig buffer[pos++] = header; len = plength + 2 + tlen; do { - //digit = len %128; replace by digit = len & 127; - digit = len & 127; - - //len = len / 128; replace by len >>= 7; - len >>= 7; + digit = len & 127; //digit = len %128 + len >>= 7; //len = len / 128 if (len > 0) { digit |= 0x80; } @@ -434,11 +430,9 @@ boolean PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length) { uint16_t rc; uint16_t len = length; do { - //digit = len %128; replace by digit = len & 127; - digit = len & 127; - //len = len / 128; replace by len >>= 7; - len >>= 7; + digit = len & 127; //digit = len %128 + len >>= 7; //len = len / 128 if (len > 0) { digit |= 0x80; }