{"action":"created","issue":{"url":"https://api.github.com/repos/knolleary/pubsubclient/issues/62","labels_url":"https://api.github.com/repos/knolleary/pubsubclient/issues/62/labels{/name}","comments_url":"https://api.github.com/repos/knolleary/pubsubclient/issues/62/comments","events_url":"https://api.github.com/repos/knolleary/pubsubclient/issues/62/events","html_url":"https://github.com/knolleary/pubsubclient/issues/62","id":73679024,"number":62,"title":"Large payloads with Arduino Wifi Shield does not work","user":{"login":"wollud1969","id":12278169,"avatar_url":"https://avatars.githubusercontent.com/u/12278169?v=3","gravatar_id":"","url":"https://api.github.com/users/wollud1969","html_url":"https://github.com/wollud1969","followers_url":"https://api.github.com/users/wollud1969/followers","following_url":"https://api.github.com/users/wollud1969/following{/other_user}","gists_url":"https://api.github.com/users/wollud1969/gists{/gist_id}","starred_url":"https://api.github.com/users/wollud1969/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wollud1969/subscriptions","organizations_url":"https://api.github.com/users/wollud1969/orgs","repos_url":"https://api.github.com/users/wollud1969/repos","events_url":"https://api.github.com/users/wollud1969/events{/privacy}","received_events_url":"https://api.github.com/users/wollud1969/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-05-06T17:04:59Z","updated_at":"2015-09-07T20:31:41Z","closed_at":"2015-09-07T20:31:41Z","body":"I ran into the problem that messages I published via PubSubClient using an Arduino Mega and an Arduino Wifi Shield which are large than about 80 octets did not appear at the broker. I found by googling that it is not possible to send more than 90 octets using the Wifi Shield and the related library at once: http://mssystems.emscom.net/helpdesk/knowledgebase.php?article=51\r\nAnd that exactly what I experienced too: I increased the buffer size one by one and at 90 octets it stopped and the WiFi library lost the connection.\r\n\r\nFurthermore I found that the WiFi library and the shield handles a `stop()` on a fresh client socket somewhat strange: The socket can not be open or will be closed immediately after opening. Since at least in my case I always give a fresh `WiFiClient` into the `PubSubClient` I removed the `connected()` call from the top of the `connect` method in PubSubClient.cpp. \r\n\r\nSince PubSubClient works as it is with the Ethernet Shield I suppose a fix in the WiFi library would be a better idea but I put a workaround into PubSubClient.cpp. Here is my diff against release 1.9.1. Maybe - as long as the WiFi library is not fixed - this fix/workaround should depend on the actual type of Client but this distinction of cases is not included in the patch. Will free to use it if you like.\r\n\r\n\r\n```\r\nwn@baikonur:~/Documents/workspace/WiModbusGateway/MQTT$ diff PubSubClient.cpp ~/Downloads/pubsubclient-1.9.1/PubSubClient/PubSubClient.cpp \r\n42,43c42\r\n< //   if (!connected()) {\r\n<    if (true) {\r\n---\r\n>    if (!connected()) {\r\n217d215\r\n<       // Serial.print(\"pub len: \"); Serial.println(length-5);\r\n219,220d216\r\n<    } else {\r\n<      // Serial.println(\"connection lost\");\r\n290,308c286\r\n< \r\n< //   Serial.print(\"write len: \"); Serial.println(length+1+llen);\r\n< //   size_t olen = length + 1 + llen;\r\n< //   rc = _client->write(buf+(4-llen),length+1+llen);\r\n< \r\n<    const size_t SEND_AT_ONCE = 64;\r\n<    size_t remains = length + 1 + llen;\r\n<    // Serial.print(\"write len: \"); Serial.println(remains);\r\n<    const uint8_t *writebuf = buf + (4 - llen);\r\n<    bool result = true;\r\n<    while ((remains > 0) && result) {\r\n<      size_t actuallySendChars = (remains > SEND_AT_ONCE) ? SEND_AT_ONCE : remains;\r\n<      // Serial.print(\"tbs: \"); Serial.println(actuallySendChars);\r\n<      size_t sentChars = _client->write(writebuf, actuallySendChars);\r\n<      result = sentChars == actuallySendChars;\r\n<      remains -= sentChars;\r\n<      writebuf += sentChars;\r\n<    }\r\n< \r\n---\r\n>    rc = _client->write(buf+(4-llen),length+1+llen);\r\n311,312c289\r\n< //   return (rc == 1+llen+length);\r\n<    return result;\r\n---\r\n>    return (rc == 1+llen+length);\r\n357,362c334\r\n<    //Serial.print(\"rc: \"); Serial.println(rc);\r\n<    if (!rc) {\r\n<      //Serial.println(\"would stop\");\r\n<      _client->stop();\r\n<      // while (true);\r\n<    }\r\n---\r\n>    if (!rc) _client->stop();\r\nwn@baikonur:~/Documents/workspace/WiModbusGateway/MQTT$ \r\n```"},"comment":{"url":"https://api.github.com/repos/knolleary/pubsubclient/issues/comments/138373029","html_url":"https://github.com/knolleary/pubsubclient/issues/62#issuecomment-138373029","issue_url":"https://api.github.com/repos/knolleary/pubsubclient/issues/62","id":138373029,"user":{"login":"knolleary","id":51083,"avatar_url":"https://avatars.githubusercontent.com/u/51083?v=3","gravatar_id":"","url":"https://api.github.com/users/knolleary","html_url":"https://github.com/knolleary","followers_url":"https://api.github.com/users/knolleary/followers","following_url":"https://api.github.com/users/knolleary/following{/other_user}","gists_url":"https://api.github.com/users/knolleary/gists{/gist_id}","starred_url":"https://api.github.com/users/knolleary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/knolleary/subscriptions","organizations_url":"https://api.github.com/users/knolleary/orgs","repos_url":"https://api.github.com/users/knolleary/repos","events_url":"https://api.github.com/users/knolleary/events{/privacy}","received_events_url":"https://api.github.com/users/knolleary/received_events","type":"User","site_admin":false},"created_at":"2015-09-07T20:31:41Z","updated_at":"2015-09-07T20:31:41Z","body":"Version 2.1 released - all should be working now"}}