From fefef0d855a7270e0966d8eaa5259f112f5345c5 Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Fri, 23 Nov 2018 12:22:20 +0200 Subject: [PATCH] Truncates TCP stream and NACKs UDP datagram when sending too much data ESP8266 maximum packet size when sending is 2048 bytes. --- components/wifi/esp8266-driver/ESP8266/ESP8266.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp b/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp index 61105a351d..cb96df56ce 100644 --- a/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp +++ b/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp @@ -549,7 +549,14 @@ bool ESP8266::dns_lookup(const char *name, char *ip) nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount) { // +CIPSEND supports up to 2048 bytes at a time - amount = amount > 2048 ? 2048 : amount; + // Data stream can be truncated + if (amount > 2048 && _sock_i[id].proto == NSAPI_TCP) { + amount = 2048; + // Datagram must stay intact + } else if (amount > 2048 && _sock_i[id].proto == NSAPI_UDP) { + tr_debug("UDP datagram maximum size is 2048"); + return NSAPI_ERROR_PARAMETER; + } //May take a second try if device is busy for (unsigned i = 0; i < 2; i++) {