From 3115cbb0cfb5bb71fdfcc4eded3e3822ddd809a9 Mon Sep 17 00:00:00 2001 From: Pablo2048 Date: Tue, 14 May 2024 13:22:00 +0200 Subject: [PATCH] Verze 2.0.0 odsud https://github.com/esphome/ESPAsyncTCP/releases/tag/v2.0.0 --- README.md | 15 ++++++++-- library.json => library.json_ | 8 +++--- library.properties | 9 ------ src/DebugPrintMacros.h | 1 - src/ESPAsyncTCP.cpp | 52 ++++++++++++++--------------------- src/ESPAsyncTCP.h | 2 -- 6 files changed, 37 insertions(+), 50 deletions(-) rename library.json => library.json_ (69%) delete mode 100644 library.properties diff --git a/README.md b/README.md index 8c7bae7..aac448a 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ -# ESPAsyncTCP - -Lokálně udržovaná verze ESPAsyncTCP knihovny, používaná ve všech projektech s ESP8266, postavena na https://github.com/OttoWinter/ESPAsyncTCP +# ESPAsyncTCP A fork of the [AsyncTCP](https://github.com/me-no-dev/AsyncTCP) library by [@me-no-dev](https://github.com/me-no-dev) for [ESPHome](https://esphome.io). ### Async TCP Library for ESP8266 Arduino +For ESP32 look [HERE](https://github.com/me-no-dev/AsyncTCP) + +[![Join the chat at https://gitter.im/me-no-dev/ESPAsyncWebServer](https://badges.gitter.im/me-no-dev/ESPAsyncWebServer.svg)](https://gitter.im/me-no-dev/ESPAsyncWebServer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) + This is a fully asynchronous TCP library, aimed at enabling trouble-free, multi-connection network environment for Espressif's ESP8266 MCUs. This library is the base for [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) @@ -22,3 +24,10 @@ This class is really similar to the ```AsyncPrinter```, but it differs in the fa ## SyncClient It is exactly what it sounds like. This is a standard, blocking TCP Client, similar to the one included in ```ESP8266WiFi``` + +## Libraries and projects that use AsyncTCP +- [ESP Async Web Server](https://github.com/me-no-dev/ESPAsyncWebServer) +- [Async MQTT client](https://github.com/marvinroger/async-mqtt-client) +- [arduinoWebSockets](https://github.com/Links2004/arduinoWebSockets) +- [ESP8266 Smart Home](https://github.com/baruch/esp8266_smart_home) +- [KBox Firmware](https://github.com/sarfata/kbox-firmware) diff --git a/library.json b/library.json_ similarity index 69% rename from library.json rename to library.json_ index bf2163d..0538519 100644 --- a/library.json +++ b/library.json_ @@ -1,18 +1,18 @@ { - "name":"ESPAsyncTCP", + "name":"ESPAsyncTCP-esphome", "description":"Asynchronous TCP Library for ESP8266", "keywords":"async,tcp", "authors": { "name": "Hristo Gochkov", - "maintainer": false + "maintainer": true }, "repository": { "type": "git", - "url": "https://git.xpablo.cz/xPablo.cz/ESPAsyncTCP.git" + "url": "https://github.com/esphome/ESPAsyncTCP.git" }, - "version": "1.2.3", + "version": "2.0.0", "license": "LGPL-3.0", "frameworks": "arduino", "platforms": "espressif8266", diff --git a/library.properties b/library.properties deleted file mode 100644 index 45a586f..0000000 --- a/library.properties +++ /dev/null @@ -1,9 +0,0 @@ -name=ESPAsyncTCP -version=1.2.3 -author=Me-No-Dev -maintainer=xPablo -sentence=Async TCP Library for ESP8266 and ESP31B -paragraph=Async TCP Library for ESP8266 and ESP31B -category=Other -url=https://git.xpablo.cz/xPablo.cz/ESPAsyncTCP.git -architectures=* diff --git a/src/DebugPrintMacros.h b/src/DebugPrintMacros.h index 43d8e15..30ed706 100644 --- a/src/DebugPrintMacros.h +++ b/src/DebugPrintMacros.h @@ -1,7 +1,6 @@ #ifndef _DEBUG_PRINT_MACROS_H #define _DEBUG_PRINT_MACROS_H // Some customizable print macros to suite the debug needs de jour. -#include // Debug macros // #include diff --git a/src/ESPAsyncTCP.cpp b/src/ESPAsyncTCP.cpp index ce24d50..fe08b93 100644 --- a/src/ESPAsyncTCP.cpp +++ b/src/ESPAsyncTCP.cpp @@ -244,8 +244,8 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){ #endif if (_pcb) //already connected return false; - ip_addr_t addr; - addr.addr = ip; + IPAddress addr; + addr = ip; #if LWIP_VERSION_MAJOR == 1 netif* interface = ip_route(&addr); if (!interface){ //no route to host @@ -264,10 +264,7 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){ #endif tcp_arg(pcb, this); tcp_err(pcb, &_s_error); - size_t err = tcp_connect(pcb, &addr, port,(tcp_connected_fn)&_s_connected); - if (err != ERR_OK) { - tcp_close(pcb); - } + size_t err = tcp_connect(pcb, addr, port,(tcp_connected_fn)&_s_connected); return (ERR_OK == err); } @@ -276,13 +273,13 @@ bool AsyncClient::connect(const char* host, uint16_t port, bool secure){ #else bool AsyncClient::connect(const char* host, uint16_t port){ #endif - ip_addr_t addr; - err_t err = dns_gethostbyname(host, &addr, (dns_found_callback)&_s_dns_found, this); + IPAddress addr; + err_t err = dns_gethostbyname(host, addr, (dns_found_callback)&_s_dns_found, this); if(err == ERR_OK) { #if ASYNC_TCP_SSL_ENABLED - return connect(IPAddress(addr.addr), port, secure); + return connect(addr, port, secure); #else - return connect(IPAddress(addr.addr), port); + return connect(addr, port); #endif } else if(err == ERR_INPROGRESS) { #if ASYNC_TCP_SSL_ENABLED @@ -331,7 +328,7 @@ AsyncClient& AsyncClient::operator=(const AsyncClient& other){ } bool AsyncClient::operator==(const AsyncClient &other) { - return (_pcb != NULL && other._pcb != NULL && (_pcb->remote_ip.addr == other._pcb->remote_ip.addr) && (_pcb->remote_port == other._pcb->remote_port)); + return (_pcb != NULL && other._pcb != NULL && (IPAddress(_pcb->remote_ip) == IPAddress(other._pcb->remote_ip)) && (_pcb->remote_port == other._pcb->remote_port)); } void AsyncClient::abort(){ @@ -708,9 +705,9 @@ void AsyncClient::_dns_found(const ip_addr *ipaddr){ #endif if(ipaddr){ #if ASYNC_TCP_SSL_ENABLED - connect(IPAddress(ipaddr->addr), _connect_port, _pcb_secure); + connect(ipaddr, _connect_port, _pcb_secure); #else - connect(IPAddress(ipaddr->addr), _connect_port); + connect(ipaddr, _connect_port); #endif } else { if(_error_cb) @@ -846,23 +843,12 @@ uint16_t AsyncClient::getMss(){ return 0; } -uint32_t AsyncClient::getRemoteAddress() { - if(!_pcb) - return 0; - return _pcb->remote_ip.addr; -} - uint16_t AsyncClient::getRemotePort() { if(!_pcb) return 0; return _pcb->remote_port; } -uint32_t AsyncClient::getLocalAddress() { - if(!_pcb) - return 0; - return _pcb->local_ip.addr; -} uint16_t AsyncClient::getLocalPort() { if(!_pcb) @@ -871,7 +857,9 @@ uint16_t AsyncClient::getLocalPort() { } IPAddress AsyncClient::remoteIP() { - return IPAddress(getRemoteAddress()); + if(!_pcb) + return IPAddress(0); + return _pcb->remote_ip; } uint16_t AsyncClient::remotePort() { @@ -879,7 +867,9 @@ uint16_t AsyncClient::remotePort() { } IPAddress AsyncClient::localIP() { - return IPAddress(getLocalAddress()); + if(!_pcb) + return IPAddress(0); + return _pcb->local_ip; } uint16_t AsyncClient::localPort() { @@ -1088,7 +1078,7 @@ AsyncServer::AsyncServer(IPAddress addr, uint16_t port) AsyncServer::AsyncServer(uint16_t port) : _port(port) - , _addr((uint32_t) IPADDR_ANY) + , _addr(IP_ANY_TYPE) , _noDelay(false) , _pcb(0) , _connect_cb(0) @@ -1127,15 +1117,15 @@ void AsyncServer::begin(){ return; int8_t err; - tcp_pcb* pcb = tcp_new(); + tcp_pcb* pcb = tcp_new_ip_type(IPADDR_TYPE_ANY); if (!pcb){ return; } tcp_setprio(pcb, TCP_PRIO_MIN); - ip_addr_t local_addr; - local_addr.addr = (uint32_t) _addr; - err = tcp_bind(pcb, &local_addr, _port); + IPAddress local_addr; + local_addr = _addr; + err = tcp_bind(pcb, local_addr, _port); // Failures are ERR_ISCONN or ERR_USE if (err != ERR_OK) { tcp_close(pcb); diff --git a/src/ESPAsyncTCP.h b/src/ESPAsyncTCP.h index 2fa344c..e0541ab 100644 --- a/src/ESPAsyncTCP.h +++ b/src/ESPAsyncTCP.h @@ -237,9 +237,7 @@ class AsyncClient { void setAckTimeout(uint32_t timeout);//no ACK timeout for the last sent packet in milliseconds void setNoDelay(bool nodelay); bool getNoDelay(); - uint32_t getRemoteAddress(); uint16_t getRemotePort(); - uint32_t getLocalAddress(); uint16_t getLocalPort(); IPAddress remoteIP();