From f54b25073c08c865469c6bc618753f1a9ae17caa Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Mon, 19 Nov 2018 13:15:09 +0200 Subject: [PATCH 1/5] Drops std:: because string.h is included --- components/wifi/esp8266-driver/ESP8266Interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/wifi/esp8266-driver/ESP8266Interface.cpp b/components/wifi/esp8266-driver/ESP8266Interface.cpp index ed02a17699..b19a5c04a6 100644 --- a/components/wifi/esp8266-driver/ESP8266Interface.cpp +++ b/components/wifi/esp8266-driver/ESP8266Interface.cpp @@ -241,7 +241,7 @@ const char *ESP8266Interface::get_ip_address() } const char *ip_buff = _esp.ip_addr(); - if (!ip_buff || std::strcmp(ip_buff, "0.0.0.0") == 0) { + if (!ip_buff || strcmp(ip_buff, "0.0.0.0") == 0) { return NULL; } From 1f4a1af6edf5978fe952f5d39daa93ab8914cd3e Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Mon, 19 Nov 2018 13:16:56 +0200 Subject: [PATCH 2/5] Truncates data to be send to modem to 2048 bytes --- components/wifi/esp8266-driver/ESP8266/ESP8266.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp b/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp index f147e65e22..f5960c548c 100644 --- a/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp +++ b/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp @@ -550,6 +550,9 @@ 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; + //May take a second try if device is busy for (unsigned i = 0; i < 2; i++) { _smutex.lock(); From 95511bc7ebd8a82a82cd15fe3a6a4e8f4479a39e Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Mon, 19 Nov 2018 13:19:05 +0200 Subject: [PATCH 3/5] Dropping duplicate "using namespace mbed;" --- components/wifi/esp8266-driver/ESP8266/ESP8266.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp b/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp index f5960c548c..9061bf4c91 100644 --- a/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp +++ b/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp @@ -27,8 +27,6 @@ #define TRACE_GROUP "ESPA" // ESP8266 AT layer -using namespace mbed; - #define ESP8266_DEFAULT_BAUD_RATE 115200 #define ESP8266_ALL_SOCKET_IDS -1 From c0f9e65af60eee0e1df2a38e556e5984c32a7815 Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Mon, 19 Nov 2018 13:54:48 +0200 Subject: [PATCH 4/5] Fixes return value check when calling ATCmdParser::read() --- components/wifi/esp8266-driver/ESP8266/ESP8266.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp b/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp index 9061bf4c91..61105a351d 100644 --- a/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp +++ b/components/wifi/esp8266-driver/ESP8266/ESP8266.cpp @@ -955,7 +955,7 @@ void ESP8266::_oob_tcp_data_hdlr() return; } - if (!_parser.read(_sock_i[_sock_active_id].tcp_data, len)) { + if (_parser.read(_sock_i[_sock_active_id].tcp_data, len) == -1) { return; } From fefef0d855a7270e0966d8eaa5259f112f5345c5 Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Fri, 23 Nov 2018 12:22:20 +0200 Subject: [PATCH 5/5] 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++) {