Add MAX_TRANSFER_SIZE def to chunk messages if needed
This commit is contained in:
parent
545d0045f9
commit
2b582f6899
@ -421,10 +421,25 @@ boolean PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length) {
|
|||||||
for (int i=0;i<llen;i++) {
|
for (int i=0;i<llen;i++) {
|
||||||
buf[5-llen+i] = lenBuf[i];
|
buf[5-llen+i] = lenBuf[i];
|
||||||
}
|
}
|
||||||
rc = _client->write(buf+(4-llen),length+1+llen);
|
|
||||||
|
|
||||||
|
#ifdef MQTT_MAX_TRANSFER_SIZE
|
||||||
|
uint8_t* writeBuf = buf+(4-llen);
|
||||||
|
uint8_t bytesRemaining = length+1+llen;
|
||||||
|
uint8_t bytesToWrite;
|
||||||
|
boolean result = true;
|
||||||
|
while((bytesRemaining > 0) && result) {
|
||||||
|
bytesToWrite = (bytesRemaining > MQTT_MAX_TRANSFER_SIZE)?MQTT_MAX_TRANSFER_SIZE:bytesRemaining;
|
||||||
|
rc = _client->write(writeBuf,bytesToWrite);
|
||||||
|
result = (rc == bytesToWrite);
|
||||||
|
bytesRemaining -= rc;
|
||||||
|
writeBuf += rc;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
#else
|
||||||
|
rc = _client->write(buf+(4-llen),length+1+llen);
|
||||||
lastOutActivity = millis();
|
lastOutActivity = millis();
|
||||||
return (rc == 1+llen+length);
|
return (rc == 1+llen+length);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean PubSubClient::subscribe(const char* topic) {
|
boolean PubSubClient::subscribe(const char* topic) {
|
||||||
@ -506,10 +521,11 @@ boolean PubSubClient::connected() {
|
|||||||
if (!rc) {
|
if (!rc) {
|
||||||
if (this->_state == MQTT_CONNECTED) {
|
if (this->_state == MQTT_CONNECTED) {
|
||||||
this->_state = MQTT_CONNECTION_LOST;
|
this->_state = MQTT_CONNECTION_LOST;
|
||||||
}
|
_client->flush();
|
||||||
_client->stop();
|
_client->stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,13 +19,17 @@
|
|||||||
//#define MQTT_VERSION MQTT_VERSION_3_1
|
//#define MQTT_VERSION MQTT_VERSION_3_1
|
||||||
#define MQTT_VERSION MQTT_VERSION_3_1_1
|
#define MQTT_VERSION MQTT_VERSION_3_1_1
|
||||||
|
|
||||||
|
|
||||||
// MQTT_MAX_PACKET_SIZE : Maximum packet size
|
// MQTT_MAX_PACKET_SIZE : Maximum packet size
|
||||||
#define MQTT_MAX_PACKET_SIZE 128
|
#define MQTT_MAX_PACKET_SIZE 128
|
||||||
|
|
||||||
// MQTT_KEEPALIVE : keepAlive interval in Seconds
|
// MQTT_KEEPALIVE : keepAlive interval in Seconds
|
||||||
#define MQTT_KEEPALIVE 15
|
#define MQTT_KEEPALIVE 15
|
||||||
|
|
||||||
|
// MQTT_MAX_TRANSFER_SIZE : limit how much data is passed to the network client
|
||||||
|
// in each write call. Needed for the Arduino Wifi Shield. Leave undefined to
|
||||||
|
// pass the entire MQTT packet in each write call.
|
||||||
|
//#define MQTT_MAX_TRANSFER_SIZE 80
|
||||||
|
|
||||||
// Possible values for client.state()
|
// Possible values for client.state()
|
||||||
#define MQTT_CONNECTION_TIMEOUT -4
|
#define MQTT_CONNECTION_TIMEOUT -4
|
||||||
#define MQTT_CONNECTION_LOST -3
|
#define MQTT_CONNECTION_LOST -3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user