tracking down and fixing large payload issue
This commit is contained in:
@ -39,7 +39,8 @@ boolean PubSubClient::connect(char *id, char* willTopic, uint8_t willQos, uint8_
|
||||
}
|
||||
|
||||
boolean PubSubClient::connect(char *id, char *user, char *pass, char* willTopic, uint8_t willQos, uint8_t willRetain, char* willMessage) {
|
||||
if (!connected()) {
|
||||
// if (!connected()) {
|
||||
if (true) {
|
||||
int result = 0;
|
||||
|
||||
if (domain != NULL) {
|
||||
@ -213,7 +214,10 @@ boolean PubSubClient::publish(char* topic, uint8_t* payload, unsigned int plengt
|
||||
if (retained) {
|
||||
header |= 1;
|
||||
}
|
||||
// Serial.print("pub len: "); Serial.println(length-5);
|
||||
return write(header,buffer,length-5);
|
||||
} else {
|
||||
// Serial.println("connection lost");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -283,10 +287,29 @@ boolean PubSubClient::write(uint8_t header, uint8_t* buf, uint16_t length) {
|
||||
for (int i=0;i<llen;i++) {
|
||||
buf[5-llen+i] = lenBuf[i];
|
||||
}
|
||||
rc = _client->write(buf+(4-llen),length+1+llen);
|
||||
|
||||
// Serial.print("write len: "); Serial.println(length+1+llen);
|
||||
// size_t olen = length + 1 + llen;
|
||||
// rc = _client->write(buf+(4-llen),length+1+llen);
|
||||
|
||||
const size_t SEND_AT_ONCE = 64;
|
||||
size_t remains = length + 1 + llen;
|
||||
// Serial.print("write len: "); Serial.println(remains);
|
||||
const uint8_t *writebuf = buf + (4 - llen);
|
||||
bool result = true;
|
||||
while ((remains > 0) && result) {
|
||||
size_t actuallySendChars = (remains > SEND_AT_ONCE) ? SEND_AT_ONCE : remains;
|
||||
// Serial.print("tbs: "); Serial.println(actuallySendChars);
|
||||
size_t sentChars = _client->write(writebuf, actuallySendChars);
|
||||
result = sentChars == actuallySendChars;
|
||||
remains -= sentChars;
|
||||
writebuf += sentChars;
|
||||
}
|
||||
|
||||
|
||||
lastOutActivity = millis();
|
||||
return (rc == 1+llen+length);
|
||||
// return (rc == 1+llen+length);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -331,7 +354,12 @@ uint16_t PubSubClient::writeString(char* string, uint8_t* buf, uint16_t pos) {
|
||||
|
||||
boolean PubSubClient::connected() {
|
||||
int rc = (int)_client->connected();
|
||||
if (!rc) _client->stop();
|
||||
//Serial.print("rc: "); Serial.println(rc);
|
||||
if (!rc) {
|
||||
//Serial.println("would stop");
|
||||
_client->stop();
|
||||
// while (true);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user