This commit is contained in:
Pavel Brychta 2024-05-14 13:22:00 +02:00
parent a2ab207446
commit 3115cbb0cf
6 changed files with 37 additions and 50 deletions

View File

@ -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)

View File

@ -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",

View File

@ -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=*

View File

@ -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 <Arduino.h>
// Debug macros
// #include <pgmspace.h>

View File

@ -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);

View File

@ -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();