Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples for the AsyncTCP #165

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# AsyncTCP
# AsyncTCP
[![Build Status](https://travis-ci.org/me-no-dev/AsyncTCP.svg?branch=master)](https://travis-ci.org/me-no-dev/AsyncTCP) ![](https://github.com/me-no-dev/AsyncTCP/workflows/Async%20TCP%20CI/badge.svg) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/2f7e4d1df8b446d192cbfec6dc174d2d)](https://www.codacy.com/manual/me-no-dev/AsyncTCP?utm_source=github.com&utm_medium=referral&utm_content=me-no-dev/AsyncTCP&utm_campaign=Badge_Grade)

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 ESP32 Arduino

[![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)
Expand Down
8 changes: 4 additions & 4 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name":"AsyncTCP",
"name":"AsyncTCP-esphome",
"description":"Asynchronous TCP Library for ESP32",
"keywords":"async,tcp",
"authors":
Expand All @@ -10,13 +10,13 @@
"repository":
{
"type": "git",
"url": "https://github.com/me-no-dev/AsyncTCP.git"
"url": "https://github.com/OttoWinter/AsyncTCP.git"
},
"version": "1.1.1",
"version": "1.2.1",
"license": "LGPL-3.0",
"frameworks": "arduino",
"platforms": "espressif32",
"build": {
"libCompatMode": 2
}
}
}
9 changes: 0 additions & 9 deletions library.properties

This file was deleted.

43 changes: 32 additions & 11 deletions src/AsyncTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,32 @@ static void _stop_async_task(){
}
}
*/

static bool customTaskCreateUniversal(
TaskFunction_t pxTaskCode,
const char * const pcName,
const uint32_t usStackDepth,
void * const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t * const pxCreatedTask,
const BaseType_t xCoreID) {
#ifndef CONFIG_FREERTOS_UNICORE
if(xCoreID >= 0 && xCoreID < 2) {
return xTaskCreatePinnedToCore(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask, xCoreID);
} else {
#endif
return xTaskCreate(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask);
#ifndef CONFIG_FREERTOS_UNICORE
}
#endif
}

static bool _start_async_task(){
if(!_init_async_event_queue()){
return false;
}
if(!_async_service_task_handle){
xTaskCreateUniversal(_async_service_task, "async_tcp", 8192 * 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);
customTaskCreateUniversal(_async_service_task, "async_tcp", 8192 * 2, NULL, 3, &_async_service_task_handle, CONFIG_ASYNC_TCP_RUNNING_CORE);
if(!_async_service_task_handle){
return false;
}
Expand Down Expand Up @@ -555,7 +575,7 @@ AsyncClient::AsyncClient(tcp_pcb* pcb)
, _pb_cb_arg(0)
, _timeout_cb(0)
, _timeout_cb_arg(0)
, _pcb_busy(false)
, _pcb_busy(0)
, _pcb_sent_at(0)
, _ack_pcb(true)
, _rx_last_packet(0)
Expand Down Expand Up @@ -763,13 +783,14 @@ size_t AsyncClient::add(const char* data, size_t size, uint8_t apiflags) {
}

bool AsyncClient::send(){
int8_t err = ERR_OK;
err = _tcp_output(_pcb, _closed_slot);
if(err == ERR_OK){
_pcb_busy = true;
_pcb_sent_at = millis();
auto pcb_sent_at_backup = _pcb_sent_at;
_pcb_sent_at = millis();
_pcb_busy++;
if (_tcp_output(_pcb, _closed_slot) == ERR_OK) {
return true;
}
_pcb_sent_at = pcb_sent_at_backup;
_pcb_busy--;
return false;
}

Expand Down Expand Up @@ -849,7 +870,7 @@ int8_t AsyncClient::_connected(void* pcb, int8_t err){
_pcb = reinterpret_cast<tcp_pcb*>(pcb);
if(_pcb){
_rx_last_packet = millis();
_pcb_busy = false;
_pcb_busy = 0;
// tcp_recv(_pcb, &_tcp_recv);
// tcp_sent(_pcb, &_tcp_sent);
// tcp_poll(_pcb, &_tcp_poll, 1);
Expand Down Expand Up @@ -912,7 +933,7 @@ int8_t AsyncClient::_fin(tcp_pcb* pcb, int8_t err) {
int8_t AsyncClient::_sent(tcp_pcb* pcb, uint16_t len) {
_rx_last_packet = millis();
//log_i("%u", len);
_pcb_busy = false;
_pcb_busy--;
if(_sent_cb) {
_sent_cb(_sent_cb_arg, this, len, (millis() - _pcb_sent_at));
}
Expand Down Expand Up @@ -957,8 +978,8 @@ int8_t AsyncClient::_poll(tcp_pcb* pcb){
uint32_t now = millis();

// ACK Timeout
if(_pcb_busy && _ack_timeout && (now - _pcb_sent_at) >= _ack_timeout){
_pcb_busy = false;
if(_pcb_busy > 0 && _ack_timeout && (now - _pcb_sent_at) >= _ack_timeout){
_pcb_busy = 0;
log_w("ack timeout %d", pcb->state);
if(_timeout_cb)
_timeout_cb(_timeout_cb_arg, this, (now - _pcb_sent_at));
Expand Down
2 changes: 1 addition & 1 deletion src/AsyncTCP.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class AsyncClient {
AcConnectHandler _poll_cb;
void* _poll_cb_arg;

bool _pcb_busy;
uint32_t _pcb_busy;
uint32_t _pcb_sent_at;
bool _ack_pcb;
uint32_t _rx_ack_len;
Expand Down