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

Increase and stabilize tcp speed #25

Merged
merged 4 commits into from
Dec 13, 2024
Merged
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
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,28 @@ Just pre-pend make with tb, for instance
`tb make`

`tb make clean`


### Debugging

Conntect an Olimex Programmer (Arm-usb-Tiny-h) to the esp debug port on the deck. Make sure its powered.

To start an openocd server
```
openocd -f interface/ftdi/olimex-arm-usb-tiny-h.cfg -f board/esp-wroom-32.cfg -c 'adapter_khz 20000'
```

Then add a debug config in your launch.json (or create one)

{
"name": "Attach to ESP32",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/aideck_esp.elf",
"cwd": "${workspaceFolder}",
"miDebuggerPath": "your_espressif_path/.espressif/tools/xtensa-esp-elf-gdb/11.2_20220823/xtensa-esp-elf-gdb/bin/xtensa-esp32-elf-gdb",
"miDebuggerServerAddress": "localhost:3333",
"externalConsole": false,
"stopAtEntry": false
}

29 changes: 16 additions & 13 deletions main/wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ static xQueueHandle wifiTxQueue;
static const char *TAG = "WIFI";

/* Socket for receiving WiFi connections */
static int sock = -1;
static int serverSock = -1;
/* Accepted WiFi connection */
static int conn = -1;
static int clientConnection = -1;

enum {
WIFI_CTRL_SET_SSID = 0x10,
Expand Down Expand Up @@ -257,19 +257,19 @@ void wifi_bind_socket() {
addr_family = AF_INET;
ip_protocol = IPPROTO_IP;
inet_ntoa_r(destAddr.sin_addr, addr_str, sizeof(addr_str) - 1);
sock = socket(addr_family, SOCK_STREAM, ip_protocol);
if (sock < 0) {
serverSock = socket(addr_family, SOCK_STREAM, ip_protocol);
if (serverSock < 0) {
ESP_LOGE(TAG, "Unable to create socket: errno %d", errno);
}
ESP_LOGD(TAG, "Socket created");

int err = bind(sock, (struct sockaddr *)&destAddr, sizeof(destAddr));
int err = bind(serverSock, (struct sockaddr *)&destAddr, sizeof(destAddr));
if (err != 0) {
ESP_LOGE(TAG, "Socket unable to bind: errno %d", errno);
}
ESP_LOGD(TAG, "Socket binded");

err = listen(sock, 1);
err = listen(serverSock, 1);
if (err != 0) {
ESP_LOGE(TAG, "Error occured during listen: errno %d", errno);
}
Expand All @@ -280,8 +280,8 @@ void wifi_wait_for_socket_connected() {
ESP_LOGI(TAG, "Waiting for connection");
struct sockaddr sourceAddr;
uint addrLen = sizeof(sourceAddr);
conn = accept(sock, (struct sockaddr *)&sourceAddr, &addrLen);
if (conn < 0) {
clientConnection = accept(serverSock, (struct sockaddr *)&sourceAddr, &addrLen);
if (clientConnection < 0) {
ESP_LOGE(TAG, "Unable to accept connection: errno %d", errno);
}
ESP_LOGI(TAG, "Connection accepted");
Expand Down Expand Up @@ -344,12 +344,13 @@ static void wifi_task(void *pvParameters) {
}

void wifi_send_packet(const char * buffer, size_t size) {
if (conn != -1) {
if (clientConnection != -1) {
ESP_LOGD(TAG, "Sending WiFi packet of size %u", size);
int err = send(conn, buffer, size, 0);
int err = send(clientConnection, buffer, size, 0);
if (err < 0) {
ESP_LOGE(TAG, "Error occurred during sending: errno %d", errno);
conn = -1;
clientConnection = -1;
close(clientConnection);
xEventGroupSetBits(s_wifi_event_group, WIFI_SOCKET_DISCONNECTED);
}
}
Expand Down Expand Up @@ -379,19 +380,21 @@ static void wifi_receiving_task(void *pvParameters) {

xEventGroupSetBits(startUpEventGroup, START_UP_RX_TASK);
while (1) {
len = recv(conn, &rxp_wifi, 2, 0);
len = recv(clientConnection, &rxp_wifi, 2, 0);
if (len > 0) {
ESP_LOGD(TAG, "Wire data length %i", rxp_wifi.payloadLength);
int totalRxLen = 0;
do {
len = recv(conn, &rxp_wifi.payload[totalRxLen], rxp_wifi.payloadLength - totalRxLen, 0);
len = recv(clientConnection, &rxp_wifi.payload[totalRxLen], rxp_wifi.payloadLength - totalRxLen, 0);
ESP_LOGD(TAG, "Read %i bytes", len);
totalRxLen += len;
} while (totalRxLen < rxp_wifi.payloadLength);
ESP_LOG_BUFFER_HEX_LEVEL(TAG, &rxp_wifi, 10, ESP_LOG_DEBUG);
xQueueSend(wifiRxQueue, &rxp_wifi, portMAX_DELAY);
} else if (len == 0) {
//vTaskDelay(10);
close(clientConnection); //Reading 0 bytes most often means the client has disconnected
clientConnection = -1;
xEventGroupSetBits(s_wifi_event_group, WIFI_SOCKET_DISCONNECTED);
//printf("No data!\n");
} else {
Expand Down
10 changes: 5 additions & 5 deletions sdkconfig
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=32
# CONFIG_ESP32_WIFI_STATIC_TX_BUFFER is not set
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER=y
CONFIG_ESP32_WIFI_TX_BUFFER_TYPE=1
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=32
CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=64
# CONFIG_ESP32_WIFI_CSI_ENABLED is not set
CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED=y
CONFIG_ESP32_WIFI_TX_BA_WIN=6
Expand Down Expand Up @@ -709,7 +709,7 @@ CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
CONFIG_LWIP_DNS_SUPPORT_MDNS_QUERIES=y
# CONFIG_LWIP_L2_TO_L3_COPY is not set
# CONFIG_LWIP_IRAM_OPTIMIZATION is not set
CONFIG_LWIP_IRAM_OPTIMIZATION=y
CONFIG_LWIP_TIMERS_ONDEMAND=y
CONFIG_LWIP_MAX_SOCKETS=10
# CONFIG_LWIP_USE_ONLY_LWIP_SELECT is not set
Expand Down Expand Up @@ -749,15 +749,15 @@ CONFIG_LWIP_LOOPBACK_MAX_PBUFS=8
#
# TCP
#
CONFIG_LWIP_MAX_ACTIVE_TCP=16
CONFIG_LWIP_MAX_LISTENING_TCP=16
CONFIG_LWIP_MAX_ACTIVE_TCP=5
CONFIG_LWIP_MAX_LISTENING_TCP=5
CONFIG_LWIP_TCP_HIGH_SPEED_RETRANSMISSION=y
CONFIG_LWIP_TCP_MAXRTX=12
CONFIG_LWIP_TCP_SYNMAXRTX=12
CONFIG_LWIP_TCP_MSS=1440
CONFIG_LWIP_TCP_TMR_INTERVAL=250
CONFIG_LWIP_TCP_MSL=60000
CONFIG_LWIP_TCP_SND_BUF_DEFAULT=5744
CONFIG_LWIP_TCP_SND_BUF_DEFAULT=64000
CONFIG_LWIP_TCP_WND_DEFAULT=5744
CONFIG_LWIP_TCP_RECVMBOX_SIZE=6
CONFIG_LWIP_TCP_QUEUE_OOSEQ=y
Expand Down
Loading