Merge pull request #365 from czaraugust/master
Adding some speed improvments
This commit is contained in:
commit
299c8293cb
4
.gitignore
vendored
4
.gitignore
vendored
@ -1 +1,5 @@
|
|||||||
tests/bin
|
tests/bin
|
||||||
|
.pioenvs
|
||||||
|
.piolibdeps
|
||||||
|
.clang_complete
|
||||||
|
.gcc-flags.json
|
||||||
|
@ -1,26 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
Basic ESP8266 MQTT example
|
Basic ESP8266 MQTT example
|
||||||
|
|
||||||
This sketch demonstrates the capabilities of the pubsub library in combination
|
This sketch demonstrates the capabilities of the pubsub library in combination
|
||||||
with the ESP8266 board/library.
|
with the ESP8266 board/library.
|
||||||
|
|
||||||
It connects to an MQTT server then:
|
It connects to an MQTT server then:
|
||||||
- publishes "hello world" to the topic "outTopic" every two seconds
|
- publishes "hello world" to the topic "outTopic" every two seconds
|
||||||
- subscribes to the topic "inTopic", printing out any messages
|
- subscribes to the topic "inTopic", printing out any messages
|
||||||
it receives. NB - it assumes the received payloads are strings not binary
|
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,
|
- If the first character of the topic "inTopic" is an 1, switch ON the ESP Led,
|
||||||
else switch it off
|
else switch it off
|
||||||
|
|
||||||
It will reconnect to the server if the connection is lost using a blocking
|
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
|
reconnect function. See the 'mqtt_reconnect_nonblocking' example for how to
|
||||||
achieve the same result without blocking the main loop.
|
achieve the same result without blocking the main loop.
|
||||||
|
|
||||||
To install the ESP8266 board, (using Arduino 1.6.4+):
|
To install the ESP8266 board, (using Arduino 1.6.4+):
|
||||||
- Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs":
|
- Add the following 3rd party board manager under "File -> Preferences -> Additional Boards Manager URLs":
|
||||||
http://arduino.esp8266.com/stable/package_esp8266com_index.json
|
http://arduino.esp8266.com/stable/package_esp8266com_index.json
|
||||||
- Open the "Tools -> Board -> Board Manager" and click install for the ESP8266"
|
- Open the "Tools -> Board -> Board Manager" and click install for the ESP8266"
|
||||||
- Select your ESP8266 in "Tools -> Board"
|
- Select your ESP8266 in "Tools -> Board"
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
|
||||||
PubSubClient.cpp - A simple client for MQTT.
|
PubSubClient.cpp - A simple client for MQTT.
|
||||||
Nick O'Leary
|
Nick O'Leary
|
||||||
http://knolleary.net
|
http://knolleary.net
|
||||||
@ -269,7 +270,7 @@ uint16_t PubSubClient::readPacket(uint8_t* lengthLength) {
|
|||||||
if(!readByte(&digit)) return 0;
|
if(!readByte(&digit)) return 0;
|
||||||
buffer[len++] = digit;
|
buffer[len++] = digit;
|
||||||
length += (digit & 127) * multiplier;
|
length += (digit & 127) * multiplier;
|
||||||
multiplier *= 128;
|
multiplier <<=7; //multiplier *= 128
|
||||||
} while ((digit & 128) != 0);
|
} while ((digit & 128) != 0);
|
||||||
*lengthLength = len-1;
|
*lengthLength = len-1;
|
||||||
|
|
||||||
@ -432,8 +433,8 @@ boolean PubSubClient::publish_P(const char* topic, const uint8_t* payload, unsig
|
|||||||
buffer[pos++] = header;
|
buffer[pos++] = header;
|
||||||
len = plength + 2 + tlen;
|
len = plength + 2 + tlen;
|
||||||
do {
|
do {
|
||||||
digit = len % 128;
|
digit = len & 127; //digit = len %128
|
||||||
len = len / 128;
|
len >>= 7; //len = len / 128
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
digit |= 0x80;
|
digit |= 0x80;
|
||||||
}
|
}
|
||||||
@ -492,8 +493,9 @@ size_t PubSubClient::buildHeader(uint8_t header, uint8_t* buf, uint16_t length)
|
|||||||
uint8_t pos = 0;
|
uint8_t pos = 0;
|
||||||
uint16_t len = length;
|
uint16_t len = length;
|
||||||
do {
|
do {
|
||||||
digit = len % 128;
|
|
||||||
len = len / 128;
|
digit = len & 127; //digit = len %128
|
||||||
|
len >>= 7; //len = len / 128
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
digit |= 0x80;
|
digit |= 0x80;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user