Skip to content

Commit

Permalink
Try fix #26 again
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Oct 13, 2024
1 parent c9044bf commit 30e0658
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 77 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ jobs:
arduino-cli --config-file ${{ matrix.config }} board listall
arduino-cli --config-file ${{ matrix.config }} core install esp32:esp32
- name: Compile Sketch
run: arduino-cli --config-file ${{ matrix.config }} --library ./src/ compile --fqbn esp32:esp32:esp32 ./examples/ClientServer/Client/Client.ino
run: arduino-cli --config-file ${{ matrix.config }} --library ./src/ compile --fqbn esp32:esp32:esp32 ./examples/Client/Client.ino
- name: Compile Sketch with IPv6
env:
LWIP_IPV6: true
run: arduino-cli --config-file ${{ matrix.config }} --library ./src/ compile --fqbn esp32:esp32:esp32 ./examples/ClientServer/Client/Client.ino
run: arduino-cli --config-file ${{ matrix.config }} --library ./src/ compile --fqbn esp32:esp32:esp32 ./examples/Client/Client.ino

platformio:
name: "pio:${{ matrix.env }}:${{ matrix.board }}"
Expand Down Expand Up @@ -96,4 +96,4 @@ jobs:
python -m pip install --upgrade pip
pip install --upgrade platformio
- run: PLATFORMIO_SRC_DIR=examples/ClientServer/Client PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
- run: PLATFORMIO_SRC_DIR=examples/Client PIO_BOARD=${{ matrix.board }} pio run -e ${{ matrix.env }}
56 changes: 56 additions & 0 deletions examples/Client/Client.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <Arduino.h>
#include <AsyncTCP.h>
#include <WiFi.h>

void makeRequest() {
AsyncClient* client = new AsyncClient;

client->onError([](void* arg, AsyncClient* client, int8_t error) {
Serial.printf("\n error occurred %s \n", client->errorToString(error));
client->close(true);
delete client;
});

client->onConnect([](void* arg, AsyncClient* client) {
Serial.printf("\n client has been connected\n");

client->onDisconnect([](void* arg, AsyncClient* client) {
Serial.printf("\n client has been disconnected\n");
client->close(true);
delete client;
});

client->onData([](void* arg, AsyncClient* client, void* data, size_t len) {
Serial.printf("\n data received from %s \n", client->remoteIP().toString().c_str());
Serial.write((uint8_t*)data, len);
});

client->write("GET / HTTP/1.1\r\nHost: www.google.com\r\nUser-Agent: ESP\r\nConnection: close\r\n\r\n");
});

if (client->connect("www.google.com", 80)) {
Serial.println("Connected to server");
} else {
Serial.println("Connection failed");
}
}

void setup() {
Serial.begin(115200);
while (!Serial)
continue;

WiFi.mode(WIFI_STA);
WiFi.begin("IoT");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected to WiFi");
Serial.println(WiFi.localIP());
}

void loop() {
makeRequest();
delay(10000);
}
42 changes: 0 additions & 42 deletions examples/ClientServer/Client/Client.ino

This file was deleted.

23 changes: 0 additions & 23 deletions examples/ClientServer/Client/config.h

This file was deleted.

10 changes: 5 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[platformio]
default_envs = arduino-2, arduino-3, arduino-310rc1
lib_dir = .
src_dir = examples/Client

[env]
framework = arduino
build_flags =
Expand All @@ -9,11 +14,6 @@ monitor_speed = 115200
monitor_filters = esp32_exception_decoder, log2file
board = esp32dev

[platformio]
default_envs = arduino-2, arduino-3, arduino-310rc1
lib_dir = .
src_dir = examples/ClientServer/Client

[env:arduino-2]
platform = espressif32@6.9.0

Expand Down
11 changes: 7 additions & 4 deletions src/AsyncTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,19 @@ static err_t _tcp_recved_api(struct tcpip_api_call_data *api_call_msg){
tcp_api_call_t * msg = (tcp_api_call_t *)api_call_msg;
msg->err = ERR_CONN;
// original code:
// causes the issue: assert failed: tcp_update_rcv_ann_wnd IDF/components/lwip/lwip/src/core/tcp.c:951 (new_rcv_ann_wnd <= 0xffff)
// if(msg->closed_slot == INVALID_CLOSED_SLOT || !_closed_slots[msg->closed_slot]) {

// attempted fix which was rolled back since non reproductible after middleware support in ESPAsyncWebServer:
// attempted fix 1, which was rolled back since non reproductible after middleware support in ESPAsyncWebServer but works in some cases:
// - https://github.com/tbnobody/OpenDTU/discussions/2326
// - https://github.com/mathieucarbou/AsyncTCP/pull/24
// if(msg->closed_slot != INVALID_CLOSED_SLOT && !_closed_slots[msg->closed_slot]) {
if(msg->closed_slot != INVALID_CLOSED_SLOT && !_closed_slots[msg->closed_slot]) {

// final fix based on:
// attempted fix 2,
// - OpenDTU testing: https://github.com/tbnobody/OpenDTU/discussions/2326
// - Original fix https://github.com/me-no-dev/AsyncTCP/pull/173/files#diff-5312944d5b5f39741f3827dd678a8e828e2624ceab236264c025ef2bdf400d6aR422-R428
if(msg->closed_slot != INVALID_CLOSED_SLOT) {
// Seems to have side effects: https://github.com/me-no-dev/ESPAsyncWebServer/issues/1437
// if(msg->closed_slot != INVALID_CLOSED_SLOT) {
msg->err = 0;
tcp_recved(msg->pcb, msg->received);
}
Expand Down

0 comments on commit 30e0658

Please sign in to comment.