How to increase WiFi speed ?

Vineethad
Posts: 55
Joined: Wed Jul 19, 2023 7:45 am

How to increase WiFi speed ?

Postby Vineethad » Thu May 23, 2024 11:31 am

Hello Everyone,

I am working on Esp32c6 module and the tool is Espressif ide(V 5.1.2).
In my application ESP32C6 configured as a SPI slave and stm32 configured as a SPI master.

My application is to receive the data from master(stm32) through spi protocol and send the received data to Wi-Fi through an UDP protocol. So I have created the two tasks one for spi and another for wifi. The speed of wifi is getting around 3Mbps but my application is to reach 50Mbps.
Please give me the suggestions for how to increase the speed of wifi?.


The code is attached below,
************************************************************************************************************
void app_main(void)
{
esp_rom_gpio_pad_select_gpio(GPIO_HS); //Select Gpio
gpio_set_direction(GPIO_HS, GPIO_MODE_OUTPUT); //Set as o/p
xSemaphore = xSemaphoreCreateBinary();

printf("****Wifi initialization*** \r\n");
wifi_init_softap(); // Wifi init

// xTaskCreate(Udp_task,"Wifi_task", 1024*10, NULL, 0, NULL); // Udp task
xTaskCreate(Wifi_task,"Wifi_task", 1024*10, NULL, 1, NULL); //Wifi Task
xTaskCreate(Spi_task,"spi_task", 1024*50, NULL, 0, &task_handle); // SPI Task


}

*************************************************************************************************************

************************************Wifi Task*************************************************************

#include <stdio.h>
#include "Wifi_Task.h"
#include "unistd.h"
#include "esp_log.h"
#include "lwip/udp.h"
#include "lwip/opt.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "esp_err.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "nvs_flash.h"
#include <netdb.h>
#include "stdio.h"
#include "rom/ets_sys.h"

#include "esp_log.h"
#include "driver/spi_slave.h"
#include "driver/gpio.h"
#include "Wifi_Task.h"


struct udp_pcb *pcb1;
struct pbuf *p1;
ip_addr_t *addr1;
u16_t port1;
char* RxPayloadData;
uint8_t RxFlag;
u32_t s_addr;
ip_addr_t dest_addr1;
struct pbuf *response_pbuf;
char rx_buffer[128];
int i;


extern TaskHandle_t task_handle;
extern SemaphoreHandle_t xSemaphore ;
#define PORT 3333
#define SOM '#'

#define RCV_HOST SPI2_HOST

// UDP receive callback function
void udp_receive_handler(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{

if (p != NULL)
{
// Process the received UDP packet here
// p->payload points to the data buffer
// p->len indicates the length of the data
printf("Received UDP packet from %s:%d, length=%d\n", ip4addr_ntoa(addr), port, p->len);

// You can access the packet data like this:
RxPayloadData = (char *)p->payload;

// printf("RxPayloadData: ");
for (int i = 0; i < 10 && RxPayloadData != '\0'; i++)
{
printf("%c", RxPayloadData);
}
printf("\n");
if(RxPayloadData[0]==SOM)
{
printf("RxPayloadData...........:%s",RxPayloadData);
spi_slave_transaction_t t;
t.length=16000*8;
t.tx_buffer=RxPayloadData;
// t.rx_buffer=recvbuf;
printf("RxPayloadData:%s",RxPayloadData);
spi_slave_transmit(RCV_HOST, &t, portMAX_DELAY); //Spi Tx and Rx

}
else
{
printf("Didn't enter this condition \n");
}

printf("RxWISR:%s\n",(char *)RxPayloadData);

pcb1 = malloc(sizeof(struct udp_pcb)); //mem allocation for pcb1
p1 = malloc(sizeof(struct pbuf)); //memory allocation for p1
addr1 = malloc(sizeof(struct pbuf)); //memory allocation for addr1

memcpy((char*)pcb1,(char*)pcb,sizeof(struct udp_pcb));
memcpy((char*)p1,(char*)p,sizeof(struct pbuf));
port1 = port;
IP_ADDR4(&dest_addr1, 192, 168, 4, 5);
udp_sendto(pcb1, p1, &dest_addr1, port1);

}
}

void Wifi_task()
{

// wifi_init_softap(); //Accesspoint initialisation

struct udp_pcb *udp_pcb = udp_new(); //Create UDP

if (udp_pcb != NULL) {

err_t bind_err = udp_bind(udp_pcb, IP_ADDR_ANY, PORT); // Bind the UDP pcb to a specific port

if (bind_err == ERR_OK) {

printf("UDP server listening on port %d\n", PORT);
} else {
printf("UDP bind failed with error %d\n", bind_err);
}
} else {
printf("Failed to create UDP pcb\n");
}

udp_recv(udp_pcb, udp_receive_handler, NULL); //UDP receive handler



while(1)
{

if(RxFlag == 1)
{
RxFlag=0;
response_pbuf = pbuf_alloc(PBUF_TRANSPORT, 128, PBUF_RAM); //Allocate Buffer

memcpy(response_pbuf->payload, rx_buffer, sizeof(rx_buffer));

if (response_pbuf != NULL)
{

printf("rx_buffer:%s",rx_buffer);
gpio_set_level(GPIO_HS, 1); // Set high
udp_sendto(pcb1, response_pbuf, &dest_addr1, port1); //Send data to wifi
gpio_set_level(GPIO_HS, 0); // Set low
vTaskResume(task_handle);
pbuf_free(response_pbuf); //Clear the buffer

}

}

sleep(1);


}
}

*********************************************************************************************************************************
**********************************************Spi Task************************************************************************

#define RCV_HOST SPI2_HOST

extern char spi_recvbuf[1024];
//Called after a transaction is queued and ready for pickup by master. We use this to set the handshake line high.
void my_post_setup_cb(spi_slave_transaction_t *trans) {
gpio_set_level(GPIO_HANDSHAKE, 1);
}

//Called after transaction is sent/received. We use this to set the handshake line low.
void my_post_trans_cb(spi_slave_transaction_t *trans) {
gpio_set_level(GPIO_HANDSHAKE, 0);
}
int n=0;
esp_err_t ret;
extern TaskHandle_t task_handle;


void spi_init(){


//Configuration for the SPI bus
spi_bus_config_t buscfg={
.mosi_io_num=GPIO_MOSI,
.miso_io_num=GPIO_MISO,
.sclk_io_num=GPIO_SCLK,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz=16000,
};

//Configuration for the SPI slave interface
spi_slave_interface_config_t slvcfg={
.mode=0,
.spics_io_num=GPIO_CS,
.queue_size=3,
.flags=0,
.post_setup_cb=my_post_setup_cb,
.post_trans_cb=my_post_trans_cb
};

//Configuration for the handshake line
gpio_config_t io_conf={
.intr_type=GPIO_INTR_DISABLE,
.mode=GPIO_MODE_OUTPUT,
.pin_bit_mask=(1<<GPIO_HANDSHAKE)
};

//Configure handshake line as output
gpio_config(&io_conf);
//Enable pull-ups on SPI lines so we don't detect rogue pulses when no master is connected.
gpio_set_pull_mode(GPIO_MOSI, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(GPIO_SCLK, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(GPIO_CS, GPIO_PULLUP_ONLY);

//Initialize SPI slave interface
ret=spi_slave_initialize(RCV_HOST, &buscfg, &slvcfg, SPI_DMA_CH_AUTO);
assert(ret==ESP_OK);
}

void Spi_task()
{

printf("spi task...\r\n");

spi_init(); //Spi Initialization
WORD_ALIGNED_ATTR char sendbuf[128]="";
WORD_ALIGNED_ATTR char recvbuf[128]="";

spi_slave_transaction_t t;
// memset(&t, 0, sizeof(t));
// RxFlag = 1;
while(1)
{

memset(recvbuf, 0x00, 128);
sprintf(sendbuf, "This is the receiver, sending data for transmission number %04d.", n);

//Set up a transaction of 128 bytes to send/receive
t.length=128*8;
t.tx_buffer=sendbuf;
t.rx_buffer=recvbuf;

ret=spi_slave_transmit(RCV_HOST, &t, portMAX_DELAY); //Spi Tx and Rx
memcpy(rx_buffer,recvbuf,sizeof(recvbuf)); //Copy data from recvbuf to rx_buffer
RxFlag=1;
printf("rx_buffer received:%s\r\n",rx_buffer);
n++;

vTaskSuspend(task_handle);

}

}

****************************************************************************************************************

Thanks & Regards,
D. Vineetha.

liaifat85
Posts: 200
Joined: Wed Dec 06, 2023 2:46 pm

Re: How to increase WiFi speed ?

Postby liaifat85 » Thu May 23, 2024 4:29 pm

Correct me if I am wrong. Do you want to make a Wifi repeater?

Vineethad
Posts: 55
Joined: Wed Jul 19, 2023 7:45 am

Re: How to increase WiFi speed ?

Postby Vineethad » Fri May 24, 2024 7:20 am

No.
I am checking the speed by using gpio pin as high and low between udp_sento(); function as below
gpio_set_level(GPIO_HS, 1); // Set high
udp_sendto(pcb1, response_pbuf, &dest_addr1, port1); //Send data to wifi
gpio_set_level(GPIO_HS, 0); // Set low

calculating the time between gpio high and low to get the time taken to send data to wifi.


Thanks & Regards,
D. Vineetha.

Arrivagek
Posts: 2
Joined: Wed Jul 24, 2024 6:10 pm

Re: How to increase WiFi speed ?

Postby Arrivagek » Wed Jul 24, 2024 6:54 pm

Salut
essaie de regarder des trucs ici https://docs.espressif.com/projects/esp ... parameters

Arrivagek
Posts: 2
Joined: Wed Jul 24, 2024 6:10 pm

Re: How to increase WiFi speed ?

Postby Arrivagek » Wed Jul 24, 2024 6:57 pm

Ah j'ai oublié, sur la page en haut à gauche précise le model de la carte

eriksl
Posts: 116
Joined: Thu Dec 14, 2023 3:23 pm
Location: Netherlands

Re: How to increase WiFi speed ?

Postby eriksl » Sat Jul 27, 2024 7:26 am

Translation: see here for parameters, select your model in the top left hand corner.

This is a known problem (for me, at least). But to start, please drop the idea you can get anywhere 65Mbps throughput on 802.11n wlan anyway. Wlan has a very high overhead. If you where to obtain 10 Mbps it would already be very good.

Then with all the processing overhead on the chip itself (wlan, lwip, application) on a not so fast CPU, it gets way worse.

Having said that, on the ESP8266 I can obtain around 800 Mbytes/sec with CPU speed 160 MHz. That's 6,4 Mbits/sec so really not bad.

On the ESP32-S3 though, with a very simple benchmarking app, I can get no more than 250 kbyte/s (2 Mbps) at all possible CPU speeds (80/160/240 MHz) so I am convinced something is definitely wrong here.

Who is online

Users browsing this forum: No registered users and 87 guests